Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Code Optimization: Low Level & Mixed Model, Common Subexpression Elimination, Copy Propaga, Slides of Computer Science

A series of lecture notes on code optimization, specifically focusing on low level and mixed model optimization, common subexpression elimination, copy propagation, dead code elimination, algebraic transformation, and loop optimizations. The notes cover various optimization techniques, their benefits, and examples of their implementation.

Typology: Slides

2012/2013

Uploaded on 03/28/2013

ekanath
ekanath 🇮🇳

3.8

(4)

80 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Objectives_template
file:///D|/...ary,%20Dr.%20Sanjeev%20K%20Aggrwal%20&%20Dr.%20Rajat%20Moona/Multi-core_Architecture/lecture%2024/24_1.htm[6/14/2012 12:07:21 PM]
Module 12: View
Lecture 24: Code Optimization
The Lecture Contains:
Code Optimization
Most Important Optimizations
Low Level Model of Optimization
Mixed Model of Optimization
Placement of Optimizations
Placement of Optimizations: Continued
Common Subexpression Elimination
Copy Propagation
Dead Code Elimination
Algebraic Transformation
Loop Optimizations
Loop-unrolling
Induction Variable Simplification
Loop Jamming
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Code Optimization: Low Level & Mixed Model, Common Subexpression Elimination, Copy Propaga and more Slides Computer Science in PDF only on Docsity!

Module 12: View

Lecture 24: Code Optimization

The Lecture Contains:

Code Optimization

Most Important Optimizations

Low Level Model of Optimization

Mixed Model of Optimization

Placement of Optimizations

Placement of Optimizations: Continued

Common Subexpression Elimination

Copy Propagation

Dead Code Elimination

Algebraic Transformation

Loop Optimizations

Loop-unrolling

Induction Variable Simplification

Loop Jamming

Module 12: View

Lecture 24: Code Optimization

Code Optimization

int a,b,c,d c = a+b d = c+

ldw a,r ldw b,r add r1,r2,r stw r3,c ldw c,r add r3,1,r stw r4,d

add r1,r2,r add r3,1,r

source code naive sparc code 10 cycles

optimized code 2 cycles

Most Important Optimizations

Loop Optimizations Moving loop invariant computations Simplifying or eliminating computations on induction variables Global register allocation Instruction scheduling Some optimizations may be relevant to a particular program and may vary according to the structure and details of the programs A highly recursive program may benefit from tail call optimization A program with few loops and large basic blocks may benefit from loop distribution In-lining may decrease call over heads; in-lining may increase the code size and may have negative effect on performance by increasing cache misses

Module 12: View

Lecture 24: Code Optimization

Mixed Model of Optimization

More easily to be adapted to new architectures May be more efficient at compile time Used in Sun Sparc, Digital Alpha, Intel, SGI MIPS More appropriate for same language and many architectures

Placement of Optimizations

Module 12: View

Lecture 24: Code Optimization

Placement of Optimizations: Cont’d

Code Optimization

Criteria for Code Improving Transformation

Preserve the meaning Must speed up the program Must be worth the effort The analysis must be fast

Local transformation : Within basic blocks Global transformation : Across basic blocks

Module 12: View

Lecture 24: Code Optimization

Copy Propagation

Use g for f after assignment f = g

Dead Code Elimination

Dead Operation : Unreachable by any path produces a value not used

If whose true and false arcs are same If whose B expr known at compile time loop not to be executed procedure not to be called

debug := false ... if (debug) { ... }

while( i <= limit - 2 ) { * statement not changing limit *
}

t := limit - 2 while( i <= t ) { statement }

Module 12: View

Lecture 24: Code Optimization

Renaming Temporary Variable Rename temporary variable t to u and replace all the occurrences of t by u. This transformation increases parallelism. Interchange Statements Two statements may be interchanged if value of the block is not affected.

t1 = b + c t2 = X + Y

t2 = X + Y t1 = b + c

Constant folding Evaluate constant expressions at compile time.

X = 3 + 5 Y = X * 2

X = 8

Y = 16

Algebraic Transformation

Eliminate addition/subtraction with 0 X = X ± 0 should be eliminated. Eliminate multiplication/division by 1 X = X * 1 or X = X/1 should be eliminated. Eliminate multiplication by 0 X = X * 0 should be replaced with X = 0

Strength reduction Costly operators should be replaced by cheaper operators

Replace T = X * * *2 by T = X * X Replace T = X * 4 by T = ls(X, 2) Replace 2 * X by X + X Replace X * 0.5 by X/ Replace X/2 by rs(X, 1)

Loop Optimizations

Code Motion: Expression not evaluated in the code must be moved out of loop

file:///D|/...ry,%20Dr.%20Sanjeev%20K%20Aggrwal%20&%20Dr.%20Rajat%20Moona/Multi-core_Architecture/lecture%2024/24_10.htm[6/14/2012 12:07:23 PM]

Module 12: View

Lecture 24: Code Optimization

Induction Variable Simplification

Loop Jamming

Two adjacent loops may me merged into a single loop

can be replaced by