Chapter 10 Exercises

1. Perform a strength reduction on:

  (a) A := 8 * I
  (b) A := I2

2. Assuming quadruple intermediate representation, write an algorithm to perform

3. What changes need to be made to perform constant folding if the intermediate representation is an abstract syntax tree?

4. What other optimizations might be included in a general constant folding test?

5. Why is the statement X := Y + Z in Example 7 not loop-inariant?

6. Eliminate variable i in Example 12 by replacing the FOR loop with a WHILE loop, making all the appropriate changes.

7. Name some other strength reductions.

8. Can the following loops be fused?

9. Write an algorithm to find and implement each of the following optimizations. Presume control flow analysis and data flow analysis have been performed and that there are procedures to call to find loop invariants and induction variables.

10. For the program in Section 9.4.

11. Following the outline in Section 9.4, create the basic blocks and the control flow graph, perform data flow analysis and optimize the following algorithm which performs an exchange sort:

12. Name other program invariances as discussed in Section 9.5.1

13. Using data flow analysis, show how a compiler might discover that a matrix is a diagonal matrix.

14. Create table entries for the following using the models in Section 9.5.6:

Send questions and comments to: Karen Lemone