Peephole Optimization MCQs January 8, 2026December 14, 2024 by u930973931_answers 20 min Score: 0 Attempted: 0/20 Subscribe 1. What is the main purpose of peephole optimization? (A) To replace high-level code with machine code (B) To improve the readability of code (C) To reduce the number of instructions in the generated code by replacing small instruction sequences (D) To convert machine code into assembly code 2. Which of the following is an example of a peephole optimization? (A) Loop unrolling (B) Strength reduction (C) Register allocation (D) Removing redundant instructions like consecutive moves or loads 3. Peephole optimization generally operates on which of the following? (A) The entire program at once (B) The program’s logic and flow (C) A small window of instructions at a time (D) Only the most critical code sections 4. Which of the following is NOT typically targeted by peephole optimization? (A) Reducing the complexity of loops (B) Removing redundant load and store instructions (C) Replacing a sequence of instructions with more efficient ones (D) Simplifying consecutive arithmetic operations 5. In peephole optimization, which of the following changes might be made? (A) Removing loops with no body (B) Replacing A = B + 0 with A = B (C) Converting an if statement into a switch statement (D) Eliminating unreachable code 6. Which of the following is a key characteristic of peephole optimization? (A) It is a low-level optimization technique. (B) It focuses on optimizing large chunks of code. (C) It is applied after the entire program is compiled. (D) It does not affect the correctness of the program. 7. What is a possible effect of peephole optimization on the program’s performance? (A) It can reduce the size of the code and improve execution speed. (B) It can significantly increase the program’s runtime. (C) It has no effect on the performance. (D) It may make the program less readable but improve performance. 8. Which of the following operations is NOT typically considered in peephole optimization? (A) Removing unnecessary instructions (B) Replacing a sequence of instructions with a faster alternative (C) Reducing function calls (D) Simplifying constant expressions 9. Which of the following is an example of a simple peephole optimization? (A) Replacing A = A + 0 with A = A (B) Converting a while loop to a for loop (C) Rewriting a function for better performance (D) Changing an array to a linked list 10. In which stage of the compiler process is peephole optimization usually applied? (A) Code generation or after code generation (B) Syntax analysis (C) Intermediate code generation (D) Lexical analysis 11. Which of the following peephole optimizations would reduce the number of instructions in the sequence MOV A, B; MOV C, A;? (A) Replace MOV A, B with ADD C, B (B) Remove MOV A, B and leave MOV C, A (C) Replace MOV A, B; MOV C, A with MOV C, B (D) None of the above 12. Which of the following is a common peephole optimization? (A) Removing redundant NOP (no operation) instructions (B) Transforming loops into recursive functions (C) Changing if conditions into switch statements (D) Converting high-level code to assembly 13. Peephole optimization is primarily focused on: (A) Improving the high-level logic of the program (B) Reducing the overall complexity of the program (C) Optimizing memory usage (D) Optimizing individual instructions and instruction sequences 14. What type of instruction sequence does peephole optimization generally target? (A) Large loops with complex conditions (B) Entire program logic (C) High-level control flow statements (D) Sequences of instructions that can be replaced with more efficient alternatives 15. Which of the following is a common transformation applied during peephole optimization? (A) for (i = 0; i < 10; i++) {} → for (i = 0; i < 5; i++) {} (B) if (x == 1) { } else { } → if (x == 1) {} (C) A = B * 1 → A = B (D) A = B + C + D → A = (B + C) + D 16. Peephole optimization is considered a type of: (A) Machine-dependent optimization (B) Compiler frontend optimization (C) High-level optimization (D) Low-level optimization 17. In which situation would peephole optimization be most effective? (A) When there are large amounts of redundant code (B) When dealing with simple instruction sequences that can be improved (C) When improving loop structures (D) When refactoring the entire program’s logic 18. Which of the following is an example of a sequence that peephole optimization could simplify? (A) MOV A, B; ADD A, C; MOV D, A → ADD D, B, C (B) MOV A, B; ADD A, C → MOV A, B; ADD B, C (C) MOV A, B; MOV B, C → MOV A, C (D) MOV A, B; ADD A, C → MOV A, B; ADD C, D 19. What is one limitation of peephole optimization? (A) It can only be applied to certain types of programs (B) It does not always significantly reduce the size of the program (C) It is not effective for high-level programming languages (D) It works best for large code blocks and complex structures 20. Which of the following is NOT a benefit of peephole optimization? (A) Improved readability of the source code (B) Improvement in the execution speed of the program (C) Reduction of the code size (D) Removal of unnecessary instructions