09 - More Optimizations Common Subexpression Elimination...

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

View Full Document Right Arrow Icon
More Optimizations Last Time Loop invariant code motion Loop induction variables Today Global Common Subexpression Elimination Value Numbering CS 380C Lecture 9 1 Optimization Common Subexpression Elimination (Example) Given A[i][j] = A[i][j] + 1, and assuming 1. row-major order 2. each array element is 4 bytes, and 3. R rows in the array will yield the following 3-address intermediate code: t0 = A t1 = R * 4 t2 = t1 * i t3 = t0 + t2 t4 = j * 4 t5 = t3 + t4 t6 = [t5] t7 = t6 + 1 t8 = A t9 = R * 4 t10 = t8 * i t11 = t8 + t10 t12 = j * 4 t13 = t11 + t12 [ t13 ] =t7 What are the common sub-expressions? CS 380C Lecture 9 2 Optimization
Background image of page 1

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

View Full DocumentRight Arrow Icon
Global Common Subexpression Elimination The Goal to fnd common subexpressions whose range spans basic blocks, and eliminate unnecessary re-evaluations Safety available expressions (AVAIL) proves that value is current transFormation gives value the right name ProFtability don’t add evaluations to any path add some copy instructions copy is as cheap as any operator may shrink, may stretch live ranges CS 380C Lecture 9 3 Optimization Available expressions ±or a block b AVAIL( b ) the set oF expressions available on entry to b . NKILL( b ) the set oF expressions not killed in b . DE±( b ) the set oF expressions defned in b and not subsequently killed in b . AVAIL ( b )= \ x pred ( b ) DE± ( x ) ( ( x ) NKILL ( x )) IN(b) = OUT(b) = CS 380C Lecture 9 4 Optimization
Background image of page 2
AVAIL What expressions are available at the end of this basic block? t0 = A t1 = R * 4 t2 = t1 * i t3 = t0 + t2 t4 = j * 4 t5 = t3 + t4 t6 = [t5] How do we compute AVAIL for a basic block? CS 380C Lecture 9 5 Optimization Returning to our example. How can we detect that t2 and r10 compute the same value? t0 = A t1 = R * 4 t2 = t1 * i t3 = t0 + t2 t4 = j * 4 t5 = t3 + t4 t6 = [t5] t7 = t6 + 1 t8 = A t9 = R * 4 t10 = t8 * i t11 = t8 + t10 t12 = j * 4 t13 = t11 + t12 [ t13 ] =t7 CS 380C Lecture 9 6 Optimization
Background image of page 3

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

View Full DocumentRight Arrow Icon
Value Numbering Value numbering computes available expressions (AVAIL or DEF) for a basic block. Input basic block of tuples ( statements ) symbol table Output improved basic block ( cse, constant folding ) table of available expressions table of constant values An expression is available at point p if it is de±ned along each path leading to p and none of its constituent values has been subsequently rede±ned.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2012 for the course CS 380 taught by Professor Shmat during the Fall '08 term at University of Texas.

Page1 / 11

09 - More Optimizations Common Subexpression Elimination...

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

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