0
0
Compiler Designknowledge~20 mins

Local optimization (peephole) in Compiler Design - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Peephole Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary goal of peephole optimization in compilers?

Peephole optimization is a technique used in compilers. What is its main purpose?

ATo optimize small sequences of instructions locally for better performance or size
BTo improve the overall program logic by changing algorithms
CTo translate high-level code directly into machine code
DTo perform syntax checking and error reporting
Attempts:
2 left
💡 Hint

Think about small code segments and local improvements.

📋 Factual
intermediate
2:00remaining
Which of the following is a common peephole optimization technique?

Identify the typical peephole optimization from the options below.

ALoop unrolling to reduce loop overhead
BInlining functions to avoid call overhead
CReplacing a sequence of instructions with a single equivalent instruction
DRegister allocation across the entire program
Attempts:
2 left
💡 Hint

Focus on small instruction sequences and their replacement.

🔍 Analysis
advanced
2:00remaining
What is the output of the peephole optimizer on this instruction sequence?

Given the following assembly instructions, what will a peephole optimizer most likely produce?

Compiler Design
MOV R1, R2
MOV R2, R1
ADD R1, #0
A
MOV R1, R2
MOV R2, R1
ADD R1, #0
BMOV R1, R2
C
NOP
NOP
NOP
D
MOV R1, R2
NOP
Attempts:
2 left
💡 Hint

Consider redundant moves and adding zero.

Reasoning
advanced
2:00remaining
Why might peephole optimization sometimes be limited in improving program performance?

Choose the best explanation for the limitations of peephole optimization.

AIt increases the size of the compiled code
BIt only works on high-level source code, not machine code
CIt requires manual intervention by the programmer
DIt focuses on small instruction windows and cannot optimize across larger code structures
Attempts:
2 left
💡 Hint

Think about the scope of peephole optimization.

Comparison
expert
2:00remaining
Compare peephole optimization with global optimization in compilers.

Which statement correctly contrasts peephole optimization with global optimization?

APeephole optimization analyzes entire programs, while global optimization only looks at small instruction sequences
BGlobal optimization can optimize across functions and modules, whereas peephole optimization only works on local instruction windows
CPeephole optimization requires source code changes, global optimization does not
DGlobal optimization is faster and simpler than peephole optimization
Attempts:
2 left
💡 Hint

Consider the scope and scale of each optimization type.