Early Optimizations Chapter 12 Constantexpression evaluation constant folding

  • Slides: 14
Download presentation
Early Optimizations (Chapter 12)

Early Optimizations (Chapter 12)

 • Constant-expression evaluation (constant folding), • scalar replacement of aggregates, • algebraic simplifications

• Constant-expression evaluation (constant folding), • scalar replacement of aggregates, • algebraic simplifications and reassociation, • value numbering, • copy propagation • sparse conditional constant propagation • First three are independent of Data flow analysis and last 3 are dependent of data flow analysis.

Constant-expression evaluation • It refers to the evaluation at compile time of expression whose,

Constant-expression evaluation • It refers to the evaluation at compile time of expression whose, operands are known to be constant. • The function returns true if its argument is a constant and false otherwise. • Ex Boolean values.

Scalar replacement of aggregates • Makes other optimizations applicable to components of aggregates, such

Scalar replacement of aggregates • Makes other optimizations applicable to components of aggregates, such as C structures. • Use in very less compiler

 • As in the example, first do scalar replacement on the snack record

• As in the example, first do scalar replacement on the snack record in main(), • Then the body of procedure color() into the call in main(), • Transform the resulting &snack->variety in the switch stmt into the equivalent snack. • Main() after constant propagation and deadcode elimination for the program.

Algebraic simplifications reassociation and • Use algebraic properties of operators to simplify expressions. •

Algebraic simplifications reassociation and • Use algebraic properties of operators to simplify expressions. • Ex.

Algebraic simplifications to floating point expressions

Algebraic simplifications to floating point expressions

Value numbering • It is one of several methods for determining that two computations

Value numbering • It is one of several methods for determining that two computations are equivalent and eliminating one of them.

Copy propagation • It is a transformation that, given an assignment x y for

Copy propagation • It is a transformation that, given an assignment x y for some variables x and y, replaces later uses of x with uses of y, as long as intervening instructions have not changed the value of either x or y

Ex: Copy propagation

Ex: Copy propagation

Ex.

Ex.

Sparse conditional constant propagation • It is a transformation that, given and assignment x

Sparse conditional constant propagation • It is a transformation that, given and assignment x c for a variable x and a constant c, replaces later uses of x with uses of c as long as intervening assignments have not changed the value of x.

Ex b 3 in block B 1 assigns the constant value 3 to b

Ex b 3 in block B 1 assigns the constant value 3 to b and no other assignment in the flow graph assigns to b Ex b 3 in block B 1 assigns the constant value 3 to b and no other assignment in the flowgraph assigns to b