Unformatted text preview:

504CS 701 Fall 2007©SSA and Value NumberingWe already know how to do availableexpression analysis to determine if aprevious computation of anexpression can be reused.A limitation of this analysis is that itcan’t recognize that two expressionsthat aren’t syntactically identical mayactually still be equivalent.For example, givent1 = a + bc = at2 = c + bAvailable expression analysis won’trecognize thatt1 and t2 must beequivalent, since it doesn’t track thefact thata = c at t2.505CS 701 Fall 2007©Value NumberingAn early expression analysistechnique called value numberingworked only at the level of basicblocks. The analysis was in terms of“values” rather than variable ortemporary names.Each non-trivial (non-copy)computation is given a number, calledits value number.Two expressions, using the sameoperators and operands with the samevalue numbers, must be equivalent.506CS 701 Fall 2007©For example,t1 = a + bc = at2 = c + bis analyzed asv1 = av2 = bt1 = v1 + v2c = v1 t2 = v1 + v2Clearly t2 is equivalent to t1 (andhence need not be computed).507CS 701 Fall 2007©In contrast, givent1 = a + ba = 2t2 = a + bthe analysis createsv1 = av2 = bt1 = v1 + v2v3 = 2 t2 = v3 + v2Clearly t2 is not equivalent to t1(and hence will need to berecomputed).508CS 701 Fall 2007©Extending Value Numbering toEntire CFGsThe problem with a global version ofvalue numbering is how to reconcilevalues produced on different flowpaths. But this is exactly what SSA isdesigned to do!In particular, we know that anordinary assignmentx = ydoes not imply that all references to xcan be replaced by y after theassignment. That is, an assignment isnot an assertion of value equivalence.509CS 701 Fall 2007©But, in SSA formxi = yjdoes mean the two values are alwaysequivalent after the assignment. Ifyjreaches a use of xi, that use of xicanbe replaced withyj.Thus in SSA form, an assignment isan assertion of value equivalence.510CS 701 Fall 2007©We will assume that simple variableto variable copies are removed bysubstituting equivalent SSA names.This alone is enough to recognizesome simple value equivalences.As we saw,t1 = a1 + b1c1 = a1t2 = c1 + b1becomest1 = a1 + b1t2 = a1 + b1511CS 701 Fall 2007©Partitioning SSA VariablesInitially, all SSA variables will bepartitioned by the form of theexpression assigned to them.Expressions involving differentconstants or operators won’t (ingeneral) be equivalent, even if theiroperands happen to be equivalent.Thusv1 = 2 and w1 = a2 + 1are always considered inequivalent.But,v3 = a1 + b2 and w1 = d1 + e2may possibly be equivalent since bothinvolve the same operator.512CS 701 Fall 2007©Phi functions are potentiallyequivalent only if they are in thesame basic block.All variables are initially consideredequivalent (since they all initially areconsidered uninitialized until explicitinitialization).After SSA variables are grouped byassignment form, groups are split.If ai op by and ck op dlare in the same group (because theyboth have the same operator, op)and ai/≡ ck or bj/≡ dlthen we split the two expressionsapart into different groups.We continue splitting based onoperand inequivalence, until no moresplits are possible. Values stillgrouped are equivalent.513CS 701 Fall 2007©ExampleNow b4 isn’t equivalent to anything,so splita5 and b5. In G7 splitoperands b3, a5 and b5. We now haveif (...) { a1=0 if (...)b1=0 else {a2=x0b2=x0 } a3=φ(a1,a2) b3=φ(b1,b2) c2=*a3 d2=*b3 }else { b4=10 }a5=φ(a0,a3)b5=φ(b3,b4)c3=*a5d3=*b5e3=*a5Initial Groupings:G1=[a0,b0,c0,d0,e0,x0]G2=[a1=0, b1=0]G3=[a2=x0, b2=x0]G4=[b4=10]G5=[a3=φ(a1,a2),b3=φ(b1,b2)]G6=[a5=φ(a0,a3),b5=φ(b3,b4)]G7=[c2=*a3,d2=*b3,d3=*b5,c3=*a5,e3=*a5]514CS 701 Fall 2007©Variable e3 can use c3’s value and d2can use c2’s value.if (...) { a1=0 if (...)b1=0 else {a2=x0b2=x0 } a3=φ(a1,a2) b3=φ(b1,b2) c2=*a3 d2=*b3 }else { b4=10 }a5=φ(a0,a3)b5=φ(b3,b4)c3=*a5d3=*b5e3=*a5Final Groupings:G1=[a0,b0,c0,d0,e0,x0]G2=[a1=0, b1=0]G3=[a2=x0, b2=x0]G4=[b4=10]G5=[a3=φ(a1,a2),b3=φ(b1,b2)]G6a=[a5=φ(a0,a3)]G6b=[b5=φ(b3,b4)]G7a=[c2=*a3,d2=*b3]G7b=[d3=*b5]G7c=[c3=*a5,e3=*a5]515CS 701 Fall 2007©Limitations of Global ValueNumberingAs presented, our global valuenumbering technique doesn’trecognize (or handle) computationsof the same expression that producedifferent values along different paths.Thus invariablea3 isn’t equivalent to eithera1 or a2.a1=1t1=a1+b0a2=2t2=a2+b0a3=φ(a1,a2)t3=a3+b0516CS 701 Fall 2007©But,we can still remove a redundantcomputation ofa+b by moving thecomputation oft3 to each of itspredecessors:Now a redundant computation ofa+bis evident in each predecessor block.Note too that this has a nice registertargeting effect—e1, e2and e3can bereadily mapped to the same liverange.a1=1t1=a1+b0a2=2t2=a2+b0e3=φ(e1,e2)t3=e3e1=a1+b0e2=a2+b0517CS 701 Fall 2007©The notion of moving expressioncomputations above phi functionsalso meshes nicely with notion ofpartial redundancy elimination. Givenmovinga+b above the phi producesNowa+b is computed only once oneach path, an improvement.a1=1t1=a1+b0a2=2a3=φ(a1,a2)t3=a3+b0a1=1t1=a1+b0a2=2t2=a2+b0t3=φ(t1,t2)518CS 701 Fall 2007©Reading Assignment• Read "Global Optimization bySuppression of Partial Redundancies,”Morel and Renvoise.(Linked from the class Web page.)• Read “Profile Guided Code Positioning,”Pettis and Hansen.(Linked from the class Web page.)519CS 701 Fall 2007©Partial Redundancy AnalysisPartial Redundancy Analysis is aboolean-valued data flow analysisthat generalizes available expressionanalysis.Ordinary available expression analysistells us if an expression must alreadyhave been evaluated (and not killed)along all execution paths.Partial redundancy analysis, originallydeveloped by Morel & Renvoise,determines if an expression has beencomputed along some paths.Moreover, it tells us where to addnew computations of the expressionto change a partial redundancy into afull redundancy.520CS 701 Fall 2007©This technique never addscomputations to paths where thecomputation isn’t needed. It strives toavoid having any redundantcomputation on any path.In fact, this approach includesmovement of a loop invariantexpression into a preheader. This loopinvariant code movement is just aspecial case of partial redundancyelimination.521CS 701 Fall 2007©Basic Definition & NotationFor a Basic Block i and a particularexpression, e:Transpi is true if and only if e’soperands aren’t assigned to in i.Transpi≡¬ KilliCompi is true if and only


View Full Document

UW-Madison COMPSCI 701 - Lecture 24 Notes

Download Lecture 24 Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 24 Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 24 Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?