{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ps6-sol

# ps6-sol - ECE 468 Problem Set 6 Solutions CFGs and loop...

This preview shows pages 1–3. Sign up to view the full content.

ECE 468 Problem Set 6 Solutions: CFGs and loop optimizations 1. Consider the following code: 1: a = 7; 2: b = 10; 3: c = 20; L1: 4: if (a <= c) goto L3; 5: d = 3*a; 6: if (d <= c) goto L2; 7: c = b + 11; 8: e = b + 10; L2: 9: a = a + 1; 10: goto L1; L3: 11: //a, b, c, d and e are all live after this (a) What are the basic blocks for this code? Answer: { 1, 2, 3 } , { 4 } , { 5, 6 } , { 7, 8 } , { 9, 10 } , { 11 } (b) Draw the block-level CFG for this code. Answer: 1: a = 7; 2: b = 10; 3: c = 20; L1: 4: if (a <= c) goto L3; 5: d = 3*a; 6: if (d <= c) goto L2; 7: c = b + 11; 8: e = b + 10; L2: 9: a = a + 1; 10: goto L1; L3: 11: 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
(c) What are the loop headers? Answer: Line 4, because it is the target of a back edge (d) What are the back edges (give the source and target lines of code) Answer: The back edge is line 10 to line 4 (e) What are the loop-invariant instructions in this code? Answer: b does not change in the loop, so lines 7 and 8 are loop invariant. (f) Which instructions can be moved out of the loop? Answer: Line 8 can be moved out of the loop, because e is not used any- where before the loop. We cannot move Line 7 outside the loop, because c is live before the loop. We use c in Lines 4 and 6. If we move Line 7 outside the
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}