DemandDriven Constant Propagation

Eric Stoltz Michael Wolfe and Michael P Gerlek

Department of Computer Science and Engineering

Oregon Graduate Institute of Science Technology

PO Box

Portland OR

ext

FAX

stoltzcseogiedu

Technical Rep ort

Abstract

Constant propagation is a wellknown static technique in whichvalues of vari

ables that are determined to b e constants can b e passed to expressions that use these

constants Co de size reduction b ounds propagation and deadco de elimination are some

of the optimizations which b enet from this analysis

In this pap er we present a new metho d for detecting constants based up on an opti

mistic demanddriven recursivesolver as opp osed to more traditional iterativesolvers The

problem with iterativesolvers is that they mayevaluate an expression many times while our

technique evaluates each expression only once To consider conditional co de we augment

the standard Static Single Assignment SSA form with merge op erators called functions

adapted from the interpretable Gated Single Assignment GSA mo del Wepresent pre

liminary exp erimental results whichshow the number of intrapro cedural constants found

in common highp erformance Fortran programs

This research supp orted by NSF grant CCR ARPA grant FC and grants from Intel

Corp oration and Matsushita Electric Industrial

Intro duction

Constant propagation is a static technique employed by the compiler to determine values which

do not change regardless of the program path taken In fact it is a generalization of constant

folding the deduction at compile time that the value of an expression is constant and is

frequently used as a preliminary to other optimizations The results can often b e propagated

to other expressions enabling further applications of the technique It is this recursive nature

of the dataow problem which suggests using a demanddriven metho d instead of the more

usual iterativetechniques

In the following example the compiler substitutes the value of in S for x whichisa

canonical instance of constant folding Since the value of x is now constant the compiler can

propagate this value into S which after applying constant folding once again results in the

determination that y is the constant It should b e noted that constant propagation for this

work was applied only to scalar integer values Propagation of realvalued expressions can b e

p erformed but sp ecial care is required since op erations on realvalued expressions are often

architecturally dep endent The metho d outlined in this work also allows for arbitrary symb olic

expression propagation

S x

S y x

Although in general constant propagation is an undecidable problem it is nonetheless ex

tremely useful and protable for a numb er of optimizations These include dead co de elimi

nation array and lo opb ound propagation and pro cedure integration and inlining which

we b elieve to b e a ma jor source of detectable constants Due to these b enets constant

propagation is an integral comp onent of mo dern optimizing commercial

The pap er is organized as follows In Section we examine the standard framework em

ployed to p erform constant propagation and relate it to previous metho ds and algorithms In

Section we dene the structure used for this work with particular attention given to the

necessary intermediate form based up on Static Single Assignment required to implementthe

algorithms we present The basic propagation metho d used in our restructuring parallelizing

compiler is also given in this section Section describ es the extension of the metho d to con

ditional co de and a discussion of variables within lo ops whichwehave found is closely tied to

recognition In Section we present the exp erimental results obtained thus

far and we close with future directions and conclusions in Section

Background and Other Work

Framework

Constant propagation op erates on a standard level lattice as shown in Figure Top

is the initial state for all symbols When comparing two lattice elementvalues the meet

op erator u is applied as given in Table These foundations are standard for many constant

propagation metho ds originally intro duced by Kildall Eachsymb ol has its lattice

value initialize d to which indicates that it has an as yet undetermined value After analysis

is complete all symb ols will have lattice value equal to it cannot b e determined to b e

constant a constantvalue or unexecutable co de We note that values can only move

down in the lattice due to the meet op erator By initializin g lattice values to an optimistic

ven approachistaken which assumes all symb ols can b e determined to b e constantuntil pro

otherwise

Previous metho ds p erform the analysis as an iterative dataow problem in which

iterations continue until a xed p oint is reached We will see in the next section that an

alternative demanddriven recursive algorithm oers advantages over the traditional approach

u any any

u any

constant if i j

i

constant u constant

i j

otherwise

Table Rules for meet u op erator

. . . C iC i + 1C i + 2 . . .

Figure Standard Constant Propagation Lattice

S z S z

S if P then S if z then

S y S y

S else S else

S y z S y

S endif S endif

a b

Figure Constant propagation with a simple and b conditional constants

Previous Metho ds

Classication

As explained byWegman and Zadeck constant propagation algorithms can b e classied

in twoways i using the entire graph or a sparse graph representation and ii detecting

simple or conditional constants This naturally creates four classes of algorithms It is clear

that propagating information ab out eachsymbol to every no de in a graph is inecient since

not all no des contain references or denitions of the symb ol under consideration Sparse repre

sentations on the other hand such as defuse or usedef chains Static Single Assignment

SSA Dep endence Flow Graphs DFG or Program Dep endence Graphs PDG

have all shown the virtue of op erating on a sparse graph for analysis

The distinction b etween simple all paths constants and conditional constants can b e seen

in Figure The simple value of y is determined to b e constant only if b oth branches whic h

merge at S are constant with identical value as is the case in a However if the predicate

whichcontrols branching can b e determined to b e constant then only one of the branches will

b e executed allowing not only y to b e recognized as constant in b but also identifying the

other path to b e dead co de

The distinction b etween the four typ es of algorithms is explained well byWegman and

Zadeck and the reader is referred to their pap er for more detail We will lo ok at the algo

rithm that they present since it incorp orates b oth sparse graph representation and conditional

co de The sparse graph employed is the SSA form describ ed in the next subsection

Graph Preliminaries

The algorithms to convert a program into SSA form are based up on the Control Flow Graph

CFG which isagraphG VEEntryExit where V is a set of no des representing basic

blo cks in the program E is a set of edges representing sequential control ow in the program

and Entry and Exit are no des representing the unique entry p ointinto the program and the

unique exit p oint from the program Switch no des have their outgoing edges determined bya

predicate After a program has b een converted into SSA form it has twokey prop erties

Every use of a variable in the program has exactly one reaching denition and

At conuence p oints in the CFG merge functions called functions are intro duced A

function for a variable merges the values of the variable from distinct incoming control

ow paths in which a denition o ccurs along at least one of these paths and has one

argument for eachcontrol ow predecessor The function is itself considered a new

denition of the variable

For details on SSA graph construction the reader is referred to the pap er by Cytron et al

to SSA form is shown in Figure A sample program converted in

A Closer Lo ok at One Algorithm

The algorithm used byWegman and Zadeck op erates on CFG edges SSA defuse edges are

added to the graph once the program has b een transformed into SSA form

Their algorithm works bykeeping twoworklists a FlowWorkList and an SSAWorkList Flow

edges are initially marked unexecutable Edges are examined from either worklist until empty

x x x

y y y

z z z

if P then if P then if P then

y y y y y y

 

endif endif endif

y y y y P true y false y

   

x y x y x y

   

z y z y z y

   

a b c

Figure Program in a normal form b SSA form and c GSA form

with those examined from the FlowWorkList b eing marked executable The destination no de

for these edges also have their functions evaluated by taking the meet of all the arguments

whose corresp onding CFG predecessors are marked executable Expressions are evaluated the

rst time a no de is the destination of a ow edge and also when the expression is the target

of an SSA edge and at least one incoming ow edge is executable More detail can b e found in

the original pap er

This algorithm nds all simple constants plus additional constants that can b e discovered

when the predicate controlling a switch no de is determined to b e constant The time complexity

is prop ortional to the size of the SSA graph and each SSA edge can b e pro cessed at most twice

Since functions are reevaluated each time an edge with that no de as a destination is

examined Wegman and Zadeck note that expressions which dep end on the value of a function

may b e reevaluated twice for each of its op erands For example in this program fragment

ifP

then

y



z



else

y



z



endif

y y y

  

z z z

  

x y z

  

if P is not constant the expression for x maybeevaluated many times If the ow edge from



is pro cessed rst then x equals and it may stay at if the SSA edges for y are examined



next Eventually x will evaluate to as the merge for z b ecomes nonconstant It is this



multiple expression evaluation whichwe seek to avoid

SSA using FUD Chains for Simple Constants

FUD Chains

tation In our restructuring compiler Nascent wealsoconvert the intermediate represen

into SSA form In order to achieve the singleassignment prop ertyeach new denition of a

variable receives a new name Practicallyhowever this is undesirable managing the symbol

table explosion alone precludes this option so the SSA prop erties are maintained by providing

links b etween each use and its one reaching denition Instead of providing defuse links as

is the common implementation weprovide usedef links giving rise to an SSA graph

comprising factored usedef chains FUD chains This approach yields several advantages

such as constant space p er no de and an ideal form with which to p erform demanddriven

analysis

Our analysis of programs b egins within a framework consisting of the CFG and an SSA data

ow graph Each basic blo ckcontains a list of intermediate co de tuples which themselves are

linked together as part of the dataow graph Tuples are of the form opleftrightssalinklattice

where op is the op eration co de and left and right are the two op erands b oth are not always

required eg a unary minus The ssalink is used for fetches and arguments of functions

as well as indexed stores which are not discussed further in this pap er The ssalink if appli

cable represents the one reaching denition for the variable in question at that p ointinthe

program The left rightandssalink elds are p ointers they are all essentially usedef links

Thus to p erform an op eration asso ciated with any tuple a request or demand is made for

the information at the target of these links Each tuple also has a lattice element assigned to

it lattice initialize d to

We rst showhow to implement simple constant propagation within our framework Our

algorithm eciently propagates simple constants in the SSA dataow graph by demanding the

lattice value from the unique denition p ointofeach use We visit all CFG no des examining

each of its tuples calling propagate recursively on anyunvisited left or right tuples Assign

t statements are evaluated calling propagate on all references with an ssalink When men

a function is encountered recursive calls to the arguments are made followed by taking

the meet of those arguments In the case of dataow cycles characterized by functions at

lo opheader no des is returned The algorithm is given in Figure

Several p oints are noted regarding this algorithm

This is not an iterative solver It is a recursive demanddriven technique which will

completely solve the graph in the absence of cycles The order in which basic blo cks are

visited is not imp ortant

This is an optimistic solver since all symb ols are initialized to We nd the same class

of simple constants as other nonconditional solvers such as Kildall and Reif and

t tuples

lattice t

unvisited t true

Visit al l basic blocks B in the program

Visit al l tuples t within B

if unvisited t then propagate t

propagate tuple t

unvisited t false

if ssa link t then

link t then propagate ssa link t if unvisited ssa

lattice t lattice t u lattice ssa link t

endif

if unvisited left t then propagate left t

if unvisited right t then propagate right t

case on type t

constant C lattice t C

arithmetic operation

if al l operands have constant lattice value

then lattice t arithmetic result of

lattice values of operands

else lattice t

endif

store lattice t lattice RHS

function

e t if loopheader then lattic

else lattice t u of arguments of t

endif

default lattice t

end case

end propagate

Figure Demanddriven propagation of simple constants

Lewis

When at a merge no de wetake the meet of the demanded classication of the

arguments By Table this will result in a constantiall arguments are constant

and identical

Each expression is evaluated once since the no de containing the expression will only b e

evaluated after all referenced denitions are classied

The asymptotic complexity is prop ortional to the size of the SSA dataow graph since

it requires each SSA edge to b e examined once

In the presence of dataow cycles due to lo ops in the CFG the solver will fail to classify

constantvalued tuples either as a function of the lo ops trip countoreven if it remains

constant throughout the lo op A more complex solver such as the one describ ed in the

next section is needed to account for cycles

Constants within Conditionals and Lo ops

Extending SSA to GSA

When demanding the classication of a variable at a merge no de we take the meet of the

demanded classication of its arguments as noted in the last section However if only one

of the branches will in fact b e taken wewould like to only propagate the value along that

path In previous metho ds as illustrated in Section the predicate at a branch or split

no de is rst evaluated and if found constant the executable edge is added to a worklist Thus

when the corresp onding merge no de is pro cessed expressions at that no de will b e evaluated in

terms of the incoming executable edges As wehave seen this may result in expressions b eing

evaluated more than once

In our metho d if a symb ol demands the value from a merge no de wewant to pro cess

the predicate that determines the path to follow Examine Figure b When attempting

to classify x the value is demanded from the usedef SSA link of y which p oints to the

 

function However a function is not interpretable Thus wehave no information ab out

whichpathmayormay not b e taken Since the predicate P in our example determines the

path taken if P is constant we can determine which argumentofthe function to evaluate

If P is not constant the b est we can do is to take the meet of the arguments

Augmentation of the function is needed to include this additional information We extend

the SSA form to a gated single assignment form GSA intro duced by Ballance et al which

allows us to evaluate conditionals based up on their predicates Figure shows a simple program

converted to GSA form Briey functions are reclassied into and functions Most

functions contained within lo opheader no des are renamed functions while most other

functions The function v P true v false v means functions are converted to

 

if P then vv else vv In this form the function represents an ifthenelse construct

 

but it is also extended to include more complex branch conditions suchascase statements

Several imp ortant notes are necessary

Weprovide the complete algorithm to convert functions to and functions in Ap

p endix A A similar metho d employed byHavlak aimed at valuenumb ering thins

the function to eliminate paths that cannot reach a merge p oint Essentiallyifallar

guments save one are then the entire argument structure is reduced to the one non

argument Thinning misses identifying constants in some situations such as shown in

Figure

It is convenient to insert no des into the CFG suc h that the header no de of a lo op has

A function cannot b e converted to a or function in the presence of irreducible lo ops

exactly two predecessors one from within the lo op and one from without A preheader

no de is inserted to accomplish this task and we also insert a postbody no de that is the

target for all lo op back edges

Multiple levels of conditionals result in nested functions Examine Figure whichisan

unstructured co de fragment although structured co de with nested ifthen constructs

also result in nested functions Figure b shows the program translated into GSA

form It is quite an interesting example for constant propagation since if we knowthe

value of predicate P wealways know what p ossible value of x can reach the merge at

However if we dont know P then the value of predicate Q b ecomes crucial

If Q is true only x can reach



If Q is false wehave no clear information on what value of x to propagate

If thinning were used the function at would reduce to x P tx f x

 

If P is not constant the meet of its arguments is However if Q is known to b e true

the constantvalue x will b e missed using thinning since the false side of predicate P is



prematurely reduced to x instead of



As describ ed by Ballance et al functions also contain a predicate it determines

whether another execution of the lo op will take place We dont require an executable

intermediate form and as we shall see other techniques eciently handle lo ops

Only reducible ow graphs can b e converted into GSA form An irreducible graph con

tains lo ops with multiple entries this leads to problems b oth in lo op detection we

classify lo ops according to the natural loop denition and working with control de

p endence in an irreducible graph the transitive control dep endence of a no de can skip

over the immediate dominator The App endix provides more detail

x x

if P goto if P goto

if Q goto if Q goto

else goto else goto

x x



y x x P tx f Qt f x

 

y x

 

continue continue

a b

Figure Conditional co de which results in nested functions

Conditional Constant Propagation

Once converted into GSA form we can improveuponthepropagate routine to take advantage

of predicates that can b e determined to b e constant When encountering a function we rst

attempt to evaluate the predicate If constant wefollow the indicated branch propagating

constantvalues as found If not constant wetake the meet of its arguments The revised

algorithm is given in Figure

Wemay encoun ter functions in a program with irreducible lo ops In this case

functions cannot b e converted to GSA form but we can still detect simple constants

Several comments need to b e made regarding this algorithm

Due to lackofspacewehave only dealt with integer constants not logical or enumerated

typ es

Wehave not covered arithmetic simplications including sp ecial cases such as zero times

anything including equals zero

Reaching a function returns This is due to the separate solver used for lo ops

discussed next

t tuples

lattice t

unvisited t true

Visit al l basic blocks B in the program

Visit al l tuples t within B

if unvisited t then propagate t

propagate tuple t

unvisited t false

link t then if ssa

if unvisited ssa link t then propagate ssa link t

lattice t lattice t u lattice ssa link t

endif

if unvisited left t then propagate left t

if unvisited right t then propagate right t

case on type t

constant C lattice t C

arithmetic operation

if al l operands have constant latticevalue

then lattice t arithmetic result of

lattice values of operands

else lattice t

endif

store lattice t lattice RHS

function lattice t u of arguments of t

function

if lattice predicate C then

lattice t lattice value of

argument corresponding to C

else lattice t u of al l arguments of t

endif

function lattice t

function lattice t lattice argument

default lattice t

end case

end propagate

Figure Demanddriven propagation with conditional constants

Lo ops

Cycles in the GSA dataow graph are the result of lo ops within the original program The

variables dened within these cycles are detected with induction variable analysis Induction

variables are traditionally detected as a precursor to and more recently

for dep endence analysis with regard to subscript expressions Wehave develop ed metho ds for

detecting and classifying induction variables including nonlinear induction variables

based on stronglyconnected regions in the SSA dataow graph These techniques

make use of an exit function the function which holds the exit value of a variable assigned

within the lo op The exit value may b e a function of the lo op trip count whichmay itself b e an

expression determined to b e constant or maybeinvariant with resp ect to the lo op An exit

expression is held bythe argument which if constant can b e used to propagate values outside

of the lo op Ballance et al intro duced functions in their GSA form We place functions in

postexit no des as part of our SSA translation phase For each edge exiting the lo op a p ostexit

no de is inserted outside the lo op b etween the source of the exit edge within the lo op b o dy

and the target outside the lo op

We are able to propagate constants through lo ops single and nested by taking advantage

of sp ecialized solvers which detect and classify a large assortment of linear and nonlinear

induction variables Interested readers may obtain a description of this work via anonymous

ftp to cseogiedu

Exp erimental Results

To gauge the eectiveness of our routines we measured the numb er of constants b oth simple

and conditional on Fortran scientic co des found in the PERFECT RICEPS and MENDEZ

b enchmark suites and several miscellaneous but imp ortant routines A constant is considered

propagated if there was a fetch of a constant Folded constants are counted separately

Results are shown in Table The vast ma jorityofconstants are simple constants

Most conditional constants were as a result of lo op analysis Although a few predicates control

ling switch no des are determined constant we b elieve these are mainly due to guards not until

interpro cedural analysis and inlining are implemented do we exp ect to see many conditional

constants propagated Results are also shown for the numb er of folded constants

With a total of lines of co de analyzed we found simple constants p er pro cedure

on average with one constantevery lines For conditional constants we found p er

pro cedure and one constantevery lines

To obtain valid comparisons with other algorithms notably Wegman and Zadecks weare

currently implementing a version of our compiler that transforms intermediate forms into a

version of SSA which supp orts their data structures We plan timing tests for several constant

propagation algorithms on the same test suite of Fortran programs as was used in this section

Future Work and Conclusions

We plan many extensions to this work One imp ortant topic is interpro cedural analysis and

pro cedure integration an area where we b elieve many constants will b e found Although some

work has already b een done in this area wewould like to apply our demanddriven

style to the problem

hnique but wehavenotyet develop ed Deadco de can currently b e identied with our tec

the algorithm fully It maywell b e that dead co de is b est identied using edges instead of

no des as p ointed out byWegman and Zadeck

Traditional SSA form has b een criticized for lacking a metho d to propagate constants de

termined by predicate analysis In the following fragment

routine lines procs FC SC CP NCP CC

PERFECT club

adm

arcd

bdna

dyfesm

o

mdg

mgd

ocean

qcd

spec

track

trfd

RICEPS

boast

ccm

linpackd

simple

sphot

wanal

MENDEZ

euler

mhdd

shear

vortex

MISC

comp

comps

eispack

livermore

vector

Total

Table Exp erimental runs to detect propagated constants FC folded constant SC simple

constant CP constant predicate NCP nonconstant predicate CC conditional constant

if x then



i x



else

j x



endif

it is desirable to b e able to assign i constantvalue A sophisticated compiler may analyze the

guard and determine that under the range of the true side of the conditional x will always



b e This notion of a derived assertion is not new but to our knowledge has not yet b een

integrated into the SSA form Using demanddriven SSA form derived assertions can easily b e

captured by inserting dummy assignments We prop ose a new SSA op erator the function

which serves as the new denition of its variable By examining the righthand side of the

predicate the ab ove fragment b ecomes

if x then



x



i x



else

j x



endif

Now constant propagation may easily b e p erformed via the argumentofthe function which

may b e constructed of actual op erations in the intermediate form

In addition to constant propagation the explicit representation of derived assertions may

b e advantageous if b ounds information can b e expressed In this fragment

if n then

for i n

endfor

endif

if the compiler cannot determine anyvalue for n then it cannot b e determined if the b o dy

of the lo op will ever b e executed within the range of the ifHowever analysis of the guard

condition assures the lo op will b e executed at least once If limit information can b e enco ded

in the argument of the function the lo op may b e transformed

if n then

n



for i n



endfor

endif

Now it is clear from the expression describing the trip count that the lo op will b e executed at

least once since the lower limit of n is known

Other planned pro jects include runtime analysis and value numb ering We are interested in

obtaining timing results that demonstrate howmuch execution time is saved for the increased

analysis done at compile time These are interesting tradeos and remain an op en question

Although not constant propagation per se the structure of GSA lends itself particularly well to

implementing value numb ering as has b een shown byHavlak Finallywewant to extend

our work into the area of noninteger and symb olic expression propagation

Wehave presented a new demanddriven metho d for p erforming conditional constant prop

agation whichworks on sparse dataow graphs nds the same class of constants as previous

algorithms but avoids evaluating expressions more than once Wehave detailed sp ecic algo

rithms to accomplish this task and have presented preliminary data on the numb er of constants

found in scientic Fortran co des and as noted in the last section we are building a comparative

e b elieve this is a promising approachwithmany opp ortunities for extensions exp eriment W

References

JeanPaul Tremblay and Paul G Sorenson The Theory and Practice of Compiler Writing

McGrawHill New York NY

Michael P Gerlek Eric Stoltz and Michael Wolfe Beyond induction variables Detecting

and classifying sequences using a demanddriven SSA form submittedforpublication

Septemb er

J Kam and J Ullman Monotone data ow analysis frameworks Acta Informatica

pages

Mark N Wegman and F Kenneth Zadeck Constant propagation with conditional

branches ACM Trans on Programming Languages and Systems July

Dan Grove and Linda Torczon Interpro cedural constant propagation A study of jump

function implementations In Proceedings of the ACM SIGPLAN ConferenceonProgram

ming Language Design and Implementation pages June

Steve S Muchnick Optimizing compilers for SPARC Sun Technology pages

Summer

D Blickstein PCraigCDavidson R Faiman K Glossop R Grove S Hobbs and

W Noyce The GEM system Digital Technical Journal

Sp ecial Issue

PLowneySAFreudenb erger T Karzes W Lichtenstein R Nix J ODonnell and

w trace scheduling compiler The Journal of Supercomputing J Ruttenb erg The Multio

David Callahan Keith D Co op er Ken Kennedy and Linda Torczon Interpro cedural

constant propagation In Proceedings of Sigplan Symposium on Compiler Construction

volume June

G A Kildall A unied approach to global In ConferenceRecord

of the First ACM Symposium on Principles of Programming Languages pages

Octob er

A V Aho R Sethi and J D Ullman Compilers Principles Techniques and Tools

AddisonWesley Reading MA

Ron Cytron Jeanne Ferrante Barry K Rosen Mark N Wegman and F Kenneth Zadeck

Eciently computing Static Single Assignment form and the control dep endence graph

ACM Trans on Programming Languages and Systems Octob er

Richard Johnson and Keshav Pingali Dep endencebased program analysis In Proceedings

of the ACM SIGPLAN ConferenceonProgramming Language Design and Implementation

pages June

Jeanne Ferrante Karl J Ottenstein and Jo e D Warren The program dep endence

graph and its use in optimization ACM Tr ans on Programming Languages and Systems

July

Michael Wolfe Michael P Gerlek and Eric Stoltz Nascent A NextGeneration High

Performance Compiler Oregon Graduate Institute of Science Technology unpublished

Eric Stoltz Michael P Gerlek and Michael Wolfe Extended SSA with factored usedef

chains to supp ort optimization and parallelism In ACM Conf Proceedings Hawaii

International Conference on System SciencesJanuary to appear

John H Reif and Harry R Lewis Symbolic evaluation and the global value graph In Con

ferenceRecord of the Fourth ACM Symposium on Principles of Programming Languages

pages January

Rob ert A Ballance Arthur B Maccab e and Karl J Ottenstein The program dep endence

web A representation supp orting control data and demanddriven interpretation of

imp erative languages In Proc ACM SIGPLAN Conf on Programming Language

Design and Implementation pages White Plains NY June

Paul Havlak Construction of thinned gated singleassignmentform In Sixth Annual

Workshop on Languages and Compilers for Paral lel Computing August

edings of the ACM SIGPLAN Confer Michael Wolfe Beyond induction variables In Proce

enceonProgramming Language Design and Implementation pages June

Mohammed R Haghighat and Constantine D Polychronop oulos Symb olic program analy

sis and optimization for parallelizin g compilers In Workshop on Languages and Compilers

for Paral lel Computing pages

R Eigenmann J Ho einger Z Li and D Padua Exp erience in the automatic paral

lelization of four PerfectBenchmark programs In U Banerjee D Gelernter A Nicolau

and D Padua editors Languages and Compilers for Paral lel Computing pages

SpingerVerlag LNCS no

Michael P Gerlek Detecting induction variables using SSA form Technical Rep ort

Oregon Graduate Institute of Science Technology

Mary Hall Managing Interprocedural Optimization PhD thesis Department of Computer

Science Rice University

R Metzger and S Stroud Interpro cedural constant propagation an empirical study

ACM Letters on Programming Languages and Systems June

App endix The Conversion Algorithm

The complete algorithm to translate a program from SSA form already augmented with

functions the lo opexit placeholders into GSA form is provided This algorithm essentially

renames lo opheader functions as functions while creating an interpretable function to

replace other functions We note that this translation is only p ossible with reducible ow

graphs In reducible graphs the initial switch no de to determine program ow aecting a merge

is always the immediate dominator

This algorithm relies heavily on the concept of control dependence Informally X is control

dep endent on Y if one path from Y must reach X while another path mayavoid X Cytron

et al showed that control dep endence is equivalent to dominance frontiers in the reverse

CFG We compute control dep endence only on the forward CFG eliminating back edges

Roughly half the functions can b e reduced This reduction can o ccur in twoways

The same predicate o ccurs more than once in a function In this case the value of the

rst o ccurrence of the predicate can prune the nested predicate The reduce function

accomplishes this task

If all arguments have the same value then the function can b e replaced by the value

of the arguments

As an example of reduce examine this co de fragment

x

if P goto

x

 a

y x

 

goto

x



if Q goto

x

 c

Before reduce the function at will b e

x Pt Qt x f f x

 a b 

And the function at will b e

x Pt Qt f x f

 c d a  a

After applying the rst reduction rule the function at b ecomes

c

x Pt Qt x f x f x

 c d  

Next the second reduction rule is applied yielding

x Pt x f x

 c 

Replacing Functions with  andFunctions

last  previous function pro cessed at this basic blo ck

current  function under consideration for this basic blo ck

lab els branchvalues which corresp ond to outedges from a basic blo ck

If there is only one successor the branchlabelistrue

link reaching denitions corresp onding to a fetch ssa

or an argumentfroma or function

last 

current 

while list of basic blo cks not empty do

B next blo ck in top ological order from the CFG

idom immediate dominator of B

for each function f in B do

if f  lo opheader then replace with

else

for each predecessor pred of B do

lab branch lab el of edge from pred to B

ssa link argument of f which corresp onds to pred

pro cess f pred lab ssa link

enddo

replace f with reduce current idom

endif

enddo

enddo

pro cess function f basic blo ck blabellabdef link

b  f if last

last b f

if b has more than successor

send current bbuild gammab

else

b  current

send link

endif

for each control predecessor cp of b do

if b  idom then

cp lab branch lab el from cp which executes b

pro cess f cp cp lab send

endif

enddo

endif

if current b  

for argument a of current b  lab el a lab

set ssa linka link

endfor

endif

end pro cess

build gamma basic blo ck bg

predicate switch function in bg

for each successor succ of bg do

e lab el from bg to succ

link Top add argument with lab el e and ssa

enddo

return

end build gamma

reduceobject r

if r is not a function return r

predicate switch op erator of function r

if predicate already on the stack

arg argument of r whose lab el matches the branchvalue of predicate

return reduce ssa link arg

endif

for all arguments a of r do

push onto stack predicate lab el of a

link a reducessa link a ssa

p op o stack predicate

enddo

if all arguments a of r haveidentical ssa link return ssa link a

else return r

end reduce