Optimisation Flashcards
Define the concept of variable lifetime
A variable is alive from the moment it is first defined to when that write is read from for the last time..
Describe Unconstrained Left Edge Algorithm
This is a method of mapping variables to registers.
Required as registers if ideal form of memory, however, likely more registers than variables.
What happens when a variable escapes?
Means value must be stored in memory as registers are full.
Steps for unconstrained left edge algorithm
- Mark all variable segments unmapped to registers.
- Select an empty register.
- Take the next unmapped segment whose left edge
is to the right of the left edge of the last segment
mapped on that register (sorry). - Map that segment to that register.
- If there are more variable segments and more
registers, go to 2.
Describe Tree height reduction
Reduce the “height” of an expression tree, so the
“parallel sections” can be put through separate
pipelines.
Example: x = a + b + c + d:
Describe constant folding
Rearrange expressions to minimise evaluation cost at
runtime. Effective when used with inline functions
with constants.
Describe Constant Propagation
Constant propagation is the process of substituting the values of known constants in expressions. Constant propagation eliminates cases in which values are copied from one location or variable to another, in order to simply assign their value to another variable.
Describe variable propagation
Can be used to completely eliminate a variable.
Describe Sub Expression Elimination
Eliminate repeated evaluation of expressions whose
value does not change. Often creates a temporary
variable (which often ends up stored in a register for
the duration of its use).
Describe Dead Code Elimination
Remove code that is unreachable/ not reached.
Describe Operator Strength Reduction
Replace operators with cheaper/faster operators that
produce identical results:
a = x * 3
Split the multiply. . .
a = x * 2 + x
Doubling is better as a shift. . .
a = ( x<<1) + x
A common case of this is b=x^2 ! b=x*x.
Describe algebraic identity recognition
- a + 0 = a
- a - 0 = a
- a X 1 =a
- a / 1 = a
- XOR(a; a) = 0
Replacement of algebra with result to avoid redundant calculation
Describe Pre-emptive Evaluation
Consider:
b o o l a , b ;
a = e x p e n s i v e o p e r a t i o n o n e ( ) ;
i f ( a ) e x p e n s i v e o p e r a t i o n two ( ) ;
We can start evaluating expensive_operation_two
at the same time as expensive_operation_one
(assuming no data ow issues). Simply throw away
the result if it’s not needed.
Describe Procedural Inlining
Replace a function call with its body. Given
int add ( int a, int b ){ return a + b ; }
…
int a , b , c ;
a = 2 ;
b = 4 ;
Then “c = add(a, b);” becomes “c = a + b;”.
Difficult to automate, but \activates” many data ow
transformations
Describe Conditional Expansion
Replaces control flow instructions with other
instructions:
boo l a;
if ( a ) {x = b + d ; }
else {y = p + q; }
becomes:
bool a ;
x = a ( b + d ) + a ` x ;
y = ay + a ` ( p + q ) ;
Requires intimate knowledge of the instruction set.