PEEPHOLE OPTIMIZATION
Redundant Loads And Stores:
If we see the instructions sequence
(1) MOV R0,a
(2) MOV a,R0
we can delete instructions (2) because whenever (2) is executed. (1) will ensure that the value of a is already in register R0.If (2) had a label we could not be sure that (1) was always executed immediately before (2) and so we could not remove (2).
Unreachable Code:
If ( debug ) { Print debugging information
}
In the intermediate representations the if-statement may be translated as:
debug =1 goto L2 goto L2
L1: print debugging information
L2:…………………………(a)
· As the argument of the first statement of (c) evaluates to a constant true, it can be replaced by goto L2. Then all the statement that print debugging aids are manifestly unreachable and can be eliminated one at a time.
Flows-Of-Control Optimizations:
goto L1 ….
L1: gotoL2 by the sequence goto L2 ….
L1: goto L2
if a < b goto L1 ….
L1: goto L2 can be replaced by Ifa < b goto L2 ….
L1: goto L2
L1: if a <b goto L2 L3:…………………………………..(1)
goto L3 …….
26 videos|66 docs|30 tests
|
1. What is peephole optimization in computer science engineering? |
2. How does peephole optimization work? |
3. What are the benefits of peephole optimization in computer science engineering? |
4. Can peephole optimization lead to incorrect program behavior? |
5. Are there any limitations or considerations to keep in mind when using peephole optimization? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|