0% found this document useful (0 votes)
5 views5 pages

Optimization Dataflow Detailed

The document outlines various optimization techniques that enhance program performance while preserving its semantics, including local optimizations like constant folding and loop optimizations such as loop unrolling. It also discusses partial redundancy elimination, constant propagation, and the basics of data-flow analysis, emphasizing their roles in improving efficiency. Additionally, it introduces concepts related to loops in flow graphs and their significance in optimization strategies.

Uploaded by

rem895964
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Optimization Dataflow Detailed

The document outlines various optimization techniques that enhance program performance while preserving its semantics, including local optimizations like constant folding and loop optimizations such as loop unrolling. It also discusses partial redundancy elimination, constant propagation, and the basics of data-flow analysis, emphasizing their roles in improving efficiency. Additionally, it introduces concepts related to loops in flow graphs and their significance in optimization strategies.

Uploaded by

rem895964
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Principal Sources of Optimization / Function-Preserving Transformations

These optimizations preserve the semantics of the program but improve performance.

Local Optimizations:

a) Constant Folding:

- Evaluate constant expressions at compile time.

- Example: x = 2 + 3 x = 5

b) Strength Reduction:

- Replace expensive operations with cheaper ones.

- Example: x = y * 2 x = y + y

c) Algebraic Simplifications:

- Simplify algebraic expressions.

- Example: x = x + 0 x

d) Common Subexpression Elimination:

- Avoid recomputing expressions.

- Example:

t1 = a + b

t2 = a + b eliminate and reuse t1

e) Copy Propagation:

- Replace variables that are copies of others.

- Example:

x=y
z=x z=y

Loop Optimizations:

a) Loop Invariant Code Motion:

- Move code outside the loop if it doesnt change.

- Example:

for (i = 0; i < n; i++) {

x = a + b; // Move out of loop

b) Loop Unrolling:

- Reduce overhead by repeating loop body.

- Example:

for (i = 0; i < 4; i++) unrolled version executes body 4 times

c) Induction Variable Elimination:

- Replace induction variables with simpler expressions.

2. Partial Redundancy Elimination (PRE)

PRE eliminates expressions that are redundant on some but not all paths.

Example:

if (cond)

t1 = a + b;

...

t2 = a + b;
PRE inserts the computation before the conditional to make it fully redundant:

t0 = a + b;

if (cond)

t1 = t0;

...

t2 = t0;

3. Constant Propagation

Replaces variables with known constant values at compile time.

Example:

x = 5;

y = x + 3; y = 5 + 3 y = 8

This improves performance and enables further optimizations.

4. Basics of Data-Flow Analysis

Data-flow analysis gathers information about the possible set of values calculated at various points.

Notations:

- IN[B]: Info coming into block B

- OUT[B]: Info leaving block B

- GEN[B]: Info generated by block B

- KILL[B]: Info killed by block B


Equations:

OUT[B] = GEN[B] (IN[B] - KILL[B])

IN[B] = OUT[P] for all predecessors P of B

5. Foundations of Data-Flow Analysis

- Based on Control Flow Graph (CFG)

- Each basic block contributes to overall data-flow information

- Uses fixed-point iteration to converge to correct result

Applications:

- Reaching definitions

- Live variable analysis

- Available expressions

- Very busy expressions

6. Loops in Flow Graphs

- Natural loop: Has a single entry point (header)

- Identified by back edges (edge from a node to its ancestor)

Algorithm to find natural loop:

- Given back edge A B, where B dominates A

- Loop = B nodes that can reach A without going through B

Loops are targets for:


- Invariant code motion

- Strength reduction

- Loop unrolling

You might also like