Copy Propagation Copy statements or Copies U=v a dte b=dte t=dte t dte a =t b = t c =dte c =t (a) (b) CS308 Compiler Theory 11
Copy Propagation • Copy statements or Copies – u = v CS308 Compiler Theory 11
Dead-Code Elimination 。Live variable -A variable is live at a point in a program if its value can be used subsequently; -otherwise,it is dead at that point. ·Constant folding Deducing at compile time that the value of an expression is a constant and using the constant instead CS308 Compiler Theory 12
Dead-Code Elimination • Live variable – A variable is live at a point in a program if its value can be used subsequently; – otherwise, it is dead at that point. • Constant folding – Deducing at compile time that the value of an expression is a constant and using the constant instea d CS308 Compiler Theory 12
1"m-1 9、 j=n t1=4*n v=a[ti] 1=1+1 B2 t2■4*1 t3=a[t2] if t3<v goto B2 j=j-1 B3 t4=4*1 t5=a[t4] if t5>v goto B3 if i>= goto B6 Ba ×子 ×七子 B6一 a[t2】=t5 t14=a[t1] a[t4】=× a[t2]=t14 goto B2 a[t1]x CS308 Compiler Theory 13
CS308 Compiler Theory 13
Code Motion An important modification that decreases the amount of code in a loop Loop-invariant computation -An expression that yields the same result independent of the number of times a loop is executed o Code Motion takes loop-invariant computation before its loop while (i<=limit-2) t=limit-2 while (i<=t) CS308 Compiler Theory 14
Code Motion • An important modification that decreases the amount of code in a loop • Loop-invariant computation – An expression that yields the same result independent of the number of times a loop is executed • Code Motion takes loop-invariant computation before its loop while (i <= limit-2) t = limit t = limit -2 while (i <= t) CS308 Compiler Theory 14