






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 10
This page cannot be seen from the preview
Don't miss anything!
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
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
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
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
Use g for f after assignment f = g
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 }
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
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)
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]
Two adjacent loops may me merged into a single loop
can be replaced by