{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ps3-sol

# ps3-sol - ECE 468 573 Problem Set 3 Common sub-expression...

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

ECE 468 & 573 Problem Set 3: Common sub-expression elimination and register allocation For the following problems, consider the following piece of three-address code: 1. A = 7; 2. B = A + 2; 3. C = A + B; 4. D = C + B; 5. A = D + C; 6. B = D + C; 7. E = A + B; 8. F = D + C; 9. G = E + F; 1. Show the result of performing Common Subexpression Elimination (CSE) on the above code. Answer : 1. A = 7; 2. B = A + 2; 3. C = A + B; 4. D = C + B; 5. A = D + C; 6. B = A; 7. E = A + B; 8. F = A; 9. G = E + F; 2. Suppose E and C were aliased. How would that change the results of CSE? Answer: If E and C were aliased, then we would not be able to rewrite instruction 8; the assignment to E would change the value of C and so kill the expression ”D + C”. 3. If we were doing top-down register allocation, which variables would be put in regis- ters? Assume a machine with 3 registers. Answer Without consider keeping registers for spilling, A is used 5 times, B is used 5 times and C is used 5 times, so they would be in registers, while the other variables would not be. 1

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

View Full Document
4. For each instruction, show which variables are live immediately after the instruction . Answer: Instruction Live after 1 A 2 A, B 3 B, C 4 C, D 5 A, C, D 6 A, B, C, D 7 C, D, E 8 E, F 9 None 5. How many registers would be needed to perform register allocation with no spilling?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}