Answers to Self-Study Questions

Test Yourself #1

Question 1

Removing a redundant load: Checking for if(true) contributes to redundant load.

Jump to Jump Replacement: The return statement inside the if block contributes to a jump to jump replacement.

Question 2

Right after the line #if-then, there is a equence of instructions that is a no-op. This corresponds to if(true) in the code. Similarly, immediately after the line #if-then-else there is another check for if(true) which is a no-op.

_L2 has a jump to main_Exit immediately. Can be replaced with just main_Exit thus eliminating _L2.


Test Yourself #2

Some examples of loops for which the compiler can be sure that the loop will execute at least once:


Test Yourself #3

As illustrated immediately below this question, a Java compiler doesn't have to give up on this optimization. A for-loop that uses literals as the low and high bounds, use i++ (where i is the loop-index variable) as the increment, and doesn't assign to i inside the loop is a perfect candidate.


Test Yourself #4

Strength reduction can still be done if the loop-index variable is incremented by any constant amount. The only change is to change

to Note that the expression increment * k1 can be evaluated at compile time, so the increment of the temporary still only involves one addition (or subtraction), and no multiplications.