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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
(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?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/19/2012 for the course ECE 468 taught by Professor Test during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 4

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online