Optimisation Flashcards

1
Q

Define the concept of variable lifetime

A

A variable is alive from the moment it is first defined to when that write is read from for the last time..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe Unconstrained Left Edge Algorithm

A

This is a method of mapping variables to registers.

Required as registers if ideal form of memory, however, likely more registers than variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens when a variable escapes?

A

Means value must be stored in memory as registers are full.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Steps for unconstrained left edge algorithm

A
  1. Mark all variable segments unmapped to registers.
  2. Select an empty register.
  3. 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).
  4. Map that segment to that register.
  5. If there are more variable segments and more
    registers, go to 2.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe Tree height reduction

A

Reduce the “height” of an expression tree, so the
“parallel sections” can be put through separate
pipelines.
Example: x = a + b + c + d:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe constant folding

A

Rearrange expressions to minimise evaluation cost at
runtime. Effective when used with inline functions
with constants.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe Constant Propagation

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe variable propagation

A

Can be used to completely eliminate a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe Sub Expression Elimination

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe Dead Code Elimination

A

Remove code that is unreachable/ not reached.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe Operator Strength Reduction

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe algebraic identity recognition

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe Pre-emptive Evaluation

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe Procedural Inlining

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe Conditional Expansion

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe Loop Unwinding

A

Expand iterative loops with a fixed number of
iterations (in whole or in part):
int i , x ; x = 0 ;
for ( i =1; i <4; i++) x = x + i ;
becomes:
int x = 0 ;
x = x + 1 ;
x = x + 2 ;
x = x + 3 ;

Works best if the loop contents are small.

17
Q

Describe Loop Fusion

A

Merges two or more loops into one (which may then
be unwound).
• Only one control variable, and one termination check.

  • For loops of different ranges, conditionals are used to “ignore” unwanted iterations.
  • A “remainder loop” may be created.
18
Q

Describe Loop Invariance

A

Move “unchanging” code from inside a loop to the
outside:

int a , i , x ; x = 0 ;
f o r ( i =1; i <4; i++)
{
a = 3 ;
x = x + a ;
}
becomes:
int i , x ; x = 0 ; a = 3 ;
for ( i = 1; I < 4; i++) x = x + a ;

19
Q

Describe Loop Switching

A

Moving of if statements outside of the loop

20
Q

What are we optimising for?

A
  • Memory footprint
  • Execution time