Cost-optimal code motion

We generalize Knoop et al.'s Lazy Code Motion (LCM) algorithm for partial redundancy elimination so that the generalized version also performs strength reduction. Although Knoop et al. have themselves extended LCM to strength reduction with their Lazy Strength Reduction algorithm, our approach differs substantially from theirs and results in a broader class of candidate expressions, stronger safety guarantees, and the elimination of the potential for performance loss instead of gain. Also, our general framework is not limited to traditional strength reduction, but rather can also handle a wide variety of optimizations in which data-flow information enables the replacement of a computation with a less expensive one. As a simple example, computations can be hoisted to points where they are constant foldable. Another example we sketch is the hoisting of polymorphic operations to points where type analysis provides leverage for optimization. Our general approach consists of placing computations so as to minimize their cost, rather than merely their number. So long as the cost differences between flowgraph nodes obey a certain natural constraint, a cost-optimal code motion transformation that does not unnecessarily prolong the lifetime of temporary varibles can be found using techniques completely analogous to LCM. Specifically, the cost differences can be discovered using a wide variety of forward data-flow analyses in a manner which we describe.

[1]  Oliver Rüthing,et al.  Optimal Code Motion in the Presence of Large Expressions , 1998, ICCL.

[2]  R. N. Horspool,et al.  Partial redundancy elimination driven by a cost-benefit analysis , 1997, Proceedings of the Eighth Israeli Conference on Computer Systems and Software Engineering.

[3]  Rajiv Gupta,et al.  Resource-sensitive profile-directed data flow analysis for code optimization , 1997, Proceedings of 30th Annual International Symposium on Microarchitecture.

[4]  Raymond Lo,et al.  Strength Reduction via SSAPRE , 1998, CC.

[5]  Dhananjay M. Dhamdhere,et al.  A composite hoisting-strength reduction transformation for global program optimization part ii , 1982 .

[6]  Sidney B. Gasser Program optimization , 1972 .

[7]  John Cocke,et al.  Register Allocation Via Coloring , 1981, Comput. Lang..

[8]  Sidney B. Gasser Program optimization , 1972, SICOSIM3.

[9]  Dhananjay M. Dhamdhere,et al.  Strength reduction of large expressions , 1995, J. Program. Lang..

[10]  Dm Dhamdhere,et al.  Algorithm for operator strength reduction , 1979 .

[11]  Bernhard Steffen,et al.  Efficient Code Motion and an Adaption to Strength Reduction , 1991, TAPSOFT, Vol.2.

[12]  Bernhard Steffen,et al.  Optimal code motion: theory and practice , 1994, TOPL.

[13]  Ken Kennedy,et al.  An algorithm for reduction of operator strength , 1977, Commun. ACM.

[14]  Dhananjay M. Dhamdhere A new algorithm for composite hoisting and strength reduction optimisation , 1989 .

[15]  J. Knoop,et al.  Lazy Strength Reduction , 1993 .

[16]  Gregory J. Chaitin,et al.  Register allocation and spilling via graph coloring , 2004, SIGP.

[17]  Gary A. Kildall,et al.  A unified approach to global program optimization , 1973, POPL.

[18]  John Cocke,et al.  A methodology for the real world , 1981 .

[19]  Rajiv Gupta,et al.  Path profile guided partial redundancy elimination using speculation , 1998, Proceedings of the 1998 International Conference on Computer Languages (Cat. No.98CB36225).

[20]  Raymond Lo,et al.  A new algorithm for partial redundancy elimination based on SSA form , 1997, PLDI '97.