SlideShare ist ein Scribd-Unternehmen logo
1 von 46
CODE OPTIMIZATION Presented By: Amita das Jayanti bhattacharya Jaistha Upadhyay
Design Of a Compiler Lexical Analysis Syntax Analysis Intermediate Code Generation Code Generation Code Optimization Table  Mgmt  Routine Error Handling Routine Source code Object code
What is optimization? ,[object Object]
 
Levels' of optimization ,[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
When to optimize ? ,[object Object],[object Object],[object Object]
Criteria For optimization ,[object Object],[object Object],[object Object],[object Object],[object Object]
Improvements can be made at various phases: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Types of Code optimization ,[object Object],[object Object],[object Object]
Common Sub expression elimination Common Sub expression elimination is a optimization that searches for instances of identical expressions (i.e they all evaluate the same value), and analyses whether it is worthwhile replacing with a single variable holding the computed value. a=b * c + g d=b * c * d temp=b * c a=temp + g d=temp * d
Dead Code elimination is a compiler optimization that removes code that does not affect a program. Removing such code has two benefits It shrinks program size, an important consideration in some contexts. It lets the running program avoid executing irrelevant operations, which reduces its running time. Dead Code elimination is of two types Unreachable Code Redundant statement Dead code Optimization:
Unreachable Code In Computer Programming, Unreachable Code or dead code is code that exists in the source code of a program but can never be executed. Program Code If (a>b) m=a elseif (a<b) m=b elseif (a==b) m=0 else m=-1 Optimized Code If (a>b) m=a elseif (a<b) m=b else m=0
Redundant Code Redundant Code is code that is executed but has no effect on the output from a program main(){  int a,b,c,r; a=5; b=6; c=a + b; r=2; r++; printf(“%d”,c); } Adding time & space complexity
Loop  optimization Loop  optimization plays an important role in improving the performance of the source code by reducing overheads associated with executing loops. ,[object Object],[object Object],[object Object]
Loop Invariant i = 1 s= 0 do{  s= s + i a =5 i = i + 1 {  while (i < =n) i = 1 s= 0 a =5 do{  s= s + i i = i + 1 {  while (i < =n) Bringing a=5 outside the do while loop, is called code motion.
Induction variables i = 1 s= 0 S1=0 S2=0 while (i < =n) {  s= s + a[ i ] t1 = i * 4  s= s + b[ t1 ] t2 = t1 +2 s2= s2 + c[ t2 ] i = i + 1 } i = 1 s= 0 S1=0 S2=0 t2=0 while (i < =n) {  s= s + a[ i ] t1 = t1+ 4  s= s + b[ t1 ] s2= s2 + c[t1 +2 ] i = i + 1 } t1,t2 are induction variables. i is inducing t1 and t1 is inducing t2 “ +” replaced “  *  ”, t1 was made independent of i
 
 
 
 
Common Sub-expression Removal ,[object Object]
 
 
 
 
 
 
Three Address Code of Quick Sort i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto (5) j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto (9) if i >= j goto (23) t 6  = 4 * i x = a[t 6 ]   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t 7  = 4 * I t 8  = 4 * j t 9  = a[t 8 ] a[t 7 ] = t 9 t 10  = 4 * j a[t 10 ] = x goto (5) t 11  = 4 * I x = a[t 11 ] t 12   = 4 * i t 13  = 4 * n t 14  = a[t 13 ] a[t 12 ] = t 14 t 15  = 4 * n a[t 15 ] = x 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Find The Basic Block i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto (5) j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto (9) if i >= j goto (23) t 6  = 4 * i x = a[t 6 ]   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t 7  = 4 * I t 8  = 4 * j t 9  = a[t 8 ] a[t 7 ] = t 9 t 10  = 4 * j a[t 10 ] = x goto (5) t 11  = 4 * i x = a[t 11 ] t 12   = 4 * i t 13  = 4 * n t 14  = a[t 13 ] a[t 12 ] = t 14 t 15  = 4 * n a[t 15 ] = x 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Flow Graph if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 t 6  = 4 * i x = a[t 6 ]   t 7  = 4 * i t 8  = 4 * j t 9  = a[t 8 ] a[t 7 ] = t 9 t 10  = 4 * j a[t 10 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 12   = 4 * i t 13  = 4 * n t 14  = a[t 13 ] a[t 12 ] = t 14 t 15  = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 t 6  = 4 * i x = a[t 6 ]   t 7  = 4 * i t 8  = 4 * j t 9  = a[t 8 ] a[t 7 ] = t 9 t 10  = 4 * j a[t 10 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 12   = 4 * i t 13  = 4 * n t 14  = a[t 13 ] a[t 12 ] = t 14 t 15  = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 t 6  = 4 * i x = a[t 6 ]   t 8  = 4 * j t 9  = a[t 8 ] a[ t 6 ] = t 9 t 10  = 4 * j a[t 10 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 12   = 4 * i t 13  = 4 * n t 14  = a[t 13 ] a[t 12 ] = t 14 t 15  = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 t 6  = 4 * i x = a[t 6 ]   t 8  = 4 * j t 9  = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11  = 4 *i x = a[t 11 ] t 12   = 4 * i t 13  = 4 * n t 14  = a[t 13 ] a[t 12 ] = t 14 t 15  = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 t 6  = 4 * i x = a[t 6 ]   t 8  = 4 * j t 9  = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 12   = 4 * i t 13  = 4 * n t 14  = a[t 13 ] a[t 12 ] = t 14 t 15  = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 t 6  = 4 * i x = a[t 6 ]   t 8  = 4 * j t 9  = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 13  = 4 * n t 14  = a[t 13 ] a[ t 11 ] = t 14 t 15  = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 t 6  = 4 * i x = a[t 6 ]   t 8  = 4 * j t 9  = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 13  = 4 * n t 14  = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 t 6  = 4 * i x = a[t 6 ]   t 8  = 4 * j t 9  = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 13  = 4 * n t 14  = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 x = a[ t 2 ]   t 8  = 4 * j t 9  = a[t 8 ] a[ t 2 ] = t 9 a[ t 8 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 13  = 4 * n t 14  = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 x = t 3  t 8  = 4 * j t 9  = a[t 8 ] a[ t 2 ] = t 9 a[ t 8 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 13  = 4 * n t 14  = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 x = t 3  a[ t 2 ] = t 5 a[ t 4 ] = x goto B 2 t 11  = 4 * i x = a[t 11 ] t 13  = 4 * n t 14  = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Common Subexpression Elimination if i >= j goto B 6 Similarly for B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 x = t 3  a[ t 2 ] = t 5 a[ t 4 ] = x goto B 2 x = t 3 t 14  = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Dead Code Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 x = t 3  a[ t 2 ] = t 5 a[ t 4 ] = x goto B 2 x = t 3 t 14  = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = x B 1 B 2 B 3 B 4 B 5 B 6
Dead Code Elimination if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 a[ t 2 ] = t 5 a[ t 4 ] = t 3 goto B 2 t 14  = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = t 3 B 1 B 2 B 3 B 4 B 5 B 6
Reduction in Strength if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] i = i  + 1 t 2  = 4 * i t 3  = a[t 2 ] if t 3  < v goto B 2 j = j – 1 t 4  = 4 *  j t 5  = a[t 4 ] if t 5  > v goto B 3 a[ t 2 ] = t 5 a[ t 4 ] = t 3 goto B 2 t 14  = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = t 3 B 1 B 2 B 3 B 4 B 5 B 6
Reduction in Strength if i >= j goto B 6 i = m - 1 j = n t 1  =4 *  n v = a[t 1 ] t 2  = 4 *  i t 4  = 4 * j t 2  = t 2  + 4 t 3  = a[t 2 ] if t 3  < v goto B 2 t 4  = t 4  - 4 t 5  = a[t 4 ] if t 5  > v goto B 3 a[ t 2 ] = t 5 a[ t 4 ] = t 3 goto B 2 t 14  = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = t 3 B 1 B 2 B 3 B 4 B 5 B 6

Weitere ähnliche Inhalte

Was ist angesagt?

3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足ssusere0a682
 
ข้อสอบ Pat 1 + เฉลย
ข้อสอบ Pat 1 +  เฉลยข้อสอบ Pat 1 +  เฉลย
ข้อสอบ Pat 1 + เฉลยAunJan
 
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-ssusere0a682
 
Niem khuccuoi kyam
Niem khuccuoi kyamNiem khuccuoi kyam
Niem khuccuoi kyam1bidvn1616
 
7 วิชา คณิต the brain
7 วิชา คณิต   the brain7 วิชา คณิต   the brain
7 วิชา คณิต the brainJamescoolboy
 
Sistemas de comunicacion 4ta edicion - bruce a. carlson solutions manual
Sistemas de comunicacion   4ta edicion - bruce a. carlson solutions manualSistemas de comunicacion   4ta edicion - bruce a. carlson solutions manual
Sistemas de comunicacion 4ta edicion - bruce a. carlson solutions manualluis hernando rodriguez montenegro
 
communication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manualcommunication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manualamirhosseinozgoli
 
Dominator tree
Dominator treeDominator tree
Dominator treesean chen
 

Was ist angesagt? (13)

3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
3人ゲームの混合戦略ナッシュ均衡を求める ゲーム理論 BASIC 演習1の補足
 
ข้อสอบ Pat 1 + เฉลย
ข้อสอบ Pat 1 +  เฉลยข้อสอบ Pat 1 +  เฉลย
ข้อสอบ Pat 1 + เฉลย
 
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
ゲーム理論BASIC 演習37 -3人ゲームの混合戦略ナッシュ均衡を求める-
 
Hw solution 5
Hw solution 5Hw solution 5
Hw solution 5
 
Key pat1 3-52 math
Key pat1 3-52 mathKey pat1 3-52 math
Key pat1 3-52 math
 
Niem khuccuoi kyam
Niem khuccuoi kyamNiem khuccuoi kyam
Niem khuccuoi kyam
 
matrices
matricesmatrices
matrices
 
Change of subject
Change of subjectChange of subject
Change of subject
 
7 วิชา คณิต the brain
7 วิชา คณิต   the brain7 วิชา คณิต   the brain
7 วิชา คณิต the brain
 
Sistemas de comunicacion 4ta edicion - bruce a. carlson solutions manual
Sistemas de comunicacion   4ta edicion - bruce a. carlson solutions manualSistemas de comunicacion   4ta edicion - bruce a. carlson solutions manual
Sistemas de comunicacion 4ta edicion - bruce a. carlson solutions manual
 
133467 p3a4
133467 p3a4133467 p3a4
133467 p3a4
 
communication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manualcommunication-systems-4th-edition-2002-carlson-solution-manual
communication-systems-4th-edition-2002-carlson-solution-manual
 
Dominator tree
Dominator treeDominator tree
Dominator tree
 

Ähnlich wie code optimization

code optimization
code optimization code optimization
code optimization Sanjeev Raaz
 
System dynamics 3rd edition palm solutions manual
System dynamics 3rd edition palm solutions manualSystem dynamics 3rd edition palm solutions manual
System dynamics 3rd edition palm solutions manualSextonMales
 
Solutions manual for business math 10th edition by cleaves
Solutions manual for business math 10th edition by cleavesSolutions manual for business math 10th edition by cleaves
Solutions manual for business math 10th edition by cleavesCooKi5472
 
ブロックチェーン: 「 書き換え不可能な記録」によって 社会はどう変化するか?
ブロックチェーン: 「書き換え不可能な記録」によって社会はどう変化するか? ブロックチェーン: 「書き換え不可能な記録」によって社会はどう変化するか?
ブロックチェーン: 「 書き換え不可能な記録」によって 社会はどう変化するか? Yoshiharu Ikutani
 
Metodologia de la programación - expresiones
Metodologia de la programación - expresionesMetodologia de la programación - expresiones
Metodologia de la programación - expresionesMar_Angeles
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation19magnet
 
Solución guía n°1 operaciones combinadas
Solución guía n°1 operaciones combinadasSolución guía n°1 operaciones combinadas
Solución guía n°1 operaciones combinadasFrancisco Gaete Garrido
 
kintone university 03-1. AD+カスタマイズ入門第6版 サンプル
kintone university 03-1. AD+カスタマイズ入門第6版 サンプルkintone university 03-1. AD+カスタマイズ入門第6版 サンプル
kintone university 03-1. AD+カスタマイズ入門第6版 サンプルYudai Shibuya
 
Boas mathematical methods in the physical sciences 3ed instructors solutions...
Boas  mathematical methods in the physical sciences 3ed instructors solutions...Boas  mathematical methods in the physical sciences 3ed instructors solutions...
Boas mathematical methods in the physical sciences 3ed instructors solutions...Praveen Prashant
 
Complete solutions-mathematical-methods-in-the-physical-sciences-3rd-edition
Complete solutions-mathematical-methods-in-the-physical-sciences-3rd-editionComplete solutions-mathematical-methods-in-the-physical-sciences-3rd-edition
Complete solutions-mathematical-methods-in-the-physical-sciences-3rd-editionAba Dula
 
AtCoder Regular Contest 038 解説
AtCoder Regular Contest 038 解説AtCoder Regular Contest 038 解説
AtCoder Regular Contest 038 解説AtCoder Inc.
 
Lecture 12 data structures and algorithms
Lecture 12 data structures and algorithmsLecture 12 data structures and algorithms
Lecture 12 data structures and algorithmsAakash deep Singhal
 
Matematicas iv.
Matematicas iv.Matematicas iv.
Matematicas iv.gabyjab
 
HCCMS 2nd 9 weeks review 2015
HCCMS 2nd 9 weeks review 2015HCCMS 2nd 9 weeks review 2015
HCCMS 2nd 9 weeks review 2015martinmommy2
 
ข้อสอบคณิตศาสตร์
ข้อสอบคณิตศาสตร์ข้อสอบคณิตศาสตร์
ข้อสอบคณิตศาสตร์Jamescoolboy
 

Ähnlich wie code optimization (20)

code optimization
code optimization code optimization
code optimization
 
System dynamics 3rd edition palm solutions manual
System dynamics 3rd edition palm solutions manualSystem dynamics 3rd edition palm solutions manual
System dynamics 3rd edition palm solutions manual
 
Solutions manual for business math 10th edition by cleaves
Solutions manual for business math 10th edition by cleavesSolutions manual for business math 10th edition by cleaves
Solutions manual for business math 10th edition by cleaves
 
ブロックチェーン: 「 書き換え不可能な記録」によって 社会はどう変化するか?
ブロックチェーン: 「書き換え不可能な記録」によって社会はどう変化するか? ブロックチェーン: 「書き換え不可能な記録」によって社会はどう変化するか?
ブロックチェーン: 「 書き換え不可能な記録」によって 社会はどう変化するか?
 
Lec38
Lec38Lec38
Lec38
 
Metodologia de la programación - expresiones
Metodologia de la programación - expresionesMetodologia de la programación - expresiones
Metodologia de la programación - expresiones
 
Slides13.pdf
Slides13.pdfSlides13.pdf
Slides13.pdf
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation
 
Solución guía n°1 operaciones combinadas
Solución guía n°1 operaciones combinadasSolución guía n°1 operaciones combinadas
Solución guía n°1 operaciones combinadas
 
kintone university 03-1. AD+カスタマイズ入門第6版 サンプル
kintone university 03-1. AD+カスタマイズ入門第6版 サンプルkintone university 03-1. AD+カスタマイズ入門第6版 サンプル
kintone university 03-1. AD+カスタマイズ入門第6版 サンプル
 
HIDRAULICA DE CANALES
HIDRAULICA DE CANALESHIDRAULICA DE CANALES
HIDRAULICA DE CANALES
 
Boas mathematical methods in the physical sciences 3ed instructors solutions...
Boas  mathematical methods in the physical sciences 3ed instructors solutions...Boas  mathematical methods in the physical sciences 3ed instructors solutions...
Boas mathematical methods in the physical sciences 3ed instructors solutions...
 
Complete solutions-mathematical-methods-in-the-physical-sciences-3rd-edition
Complete solutions-mathematical-methods-in-the-physical-sciences-3rd-editionComplete solutions-mathematical-methods-in-the-physical-sciences-3rd-edition
Complete solutions-mathematical-methods-in-the-physical-sciences-3rd-edition
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Math worksheet4
Math worksheet4Math worksheet4
Math worksheet4
 
AtCoder Regular Contest 038 解説
AtCoder Regular Contest 038 解説AtCoder Regular Contest 038 解説
AtCoder Regular Contest 038 解説
 
Lecture 12 data structures and algorithms
Lecture 12 data structures and algorithmsLecture 12 data structures and algorithms
Lecture 12 data structures and algorithms
 
Matematicas iv.
Matematicas iv.Matematicas iv.
Matematicas iv.
 
HCCMS 2nd 9 weeks review 2015
HCCMS 2nd 9 weeks review 2015HCCMS 2nd 9 weeks review 2015
HCCMS 2nd 9 weeks review 2015
 
ข้อสอบคณิตศาสตร์
ข้อสอบคณิตศาสตร์ข้อสอบคณิตศาสตร์
ข้อสอบคณิตศาสตร์
 

Kürzlich hochgeladen

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Kürzlich hochgeladen (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

code optimization

  • 1. CODE OPTIMIZATION Presented By: Amita das Jayanti bhattacharya Jaistha Upadhyay
  • 2. Design Of a Compiler Lexical Analysis Syntax Analysis Intermediate Code Generation Code Generation Code Optimization Table Mgmt Routine Error Handling Routine Source code Object code
  • 3.
  • 4.  
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Common Sub expression elimination Common Sub expression elimination is a optimization that searches for instances of identical expressions (i.e they all evaluate the same value), and analyses whether it is worthwhile replacing with a single variable holding the computed value. a=b * c + g d=b * c * d temp=b * c a=temp + g d=temp * d
  • 12. Dead Code elimination is a compiler optimization that removes code that does not affect a program. Removing such code has two benefits It shrinks program size, an important consideration in some contexts. It lets the running program avoid executing irrelevant operations, which reduces its running time. Dead Code elimination is of two types Unreachable Code Redundant statement Dead code Optimization:
  • 13. Unreachable Code In Computer Programming, Unreachable Code or dead code is code that exists in the source code of a program but can never be executed. Program Code If (a>b) m=a elseif (a<b) m=b elseif (a==b) m=0 else m=-1 Optimized Code If (a>b) m=a elseif (a<b) m=b else m=0
  • 14. Redundant Code Redundant Code is code that is executed but has no effect on the output from a program main(){ int a,b,c,r; a=5; b=6; c=a + b; r=2; r++; printf(“%d”,c); } Adding time & space complexity
  • 15.
  • 16. Loop Invariant i = 1 s= 0 do{ s= s + i a =5 i = i + 1 { while (i < =n) i = 1 s= 0 a =5 do{ s= s + i i = i + 1 { while (i < =n) Bringing a=5 outside the do while loop, is called code motion.
  • 17. Induction variables i = 1 s= 0 S1=0 S2=0 while (i < =n) { s= s + a[ i ] t1 = i * 4 s= s + b[ t1 ] t2 = t1 +2 s2= s2 + c[ t2 ] i = i + 1 } i = 1 s= 0 S1=0 S2=0 t2=0 while (i < =n) { s= s + a[ i ] t1 = t1+ 4 s= s + b[ t1 ] s2= s2 + c[t1 +2 ] i = i + 1 } t1,t2 are induction variables. i is inducing t1 and t1 is inducing t2 “ +” replaced “ * ”, t1 was made independent of i
  • 18.  
  • 19.  
  • 20.  
  • 21.  
  • 22.
  • 23.  
  • 24.  
  • 25.  
  • 26.  
  • 27.  
  • 28.  
  • 29. Three Address Code of Quick Sort i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto (5) j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto (9) if i >= j goto (23) t 6 = 4 * i x = a[t 6 ] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t 7 = 4 * I t 8 = 4 * j t 9 = a[t 8 ] a[t 7 ] = t 9 t 10 = 4 * j a[t 10 ] = x goto (5) t 11 = 4 * I x = a[t 11 ] t 12 = 4 * i t 13 = 4 * n t 14 = a[t 13 ] a[t 12 ] = t 14 t 15 = 4 * n a[t 15 ] = x 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  • 30. Find The Basic Block i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto (5) j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto (9) if i >= j goto (23) t 6 = 4 * i x = a[t 6 ] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t 7 = 4 * I t 8 = 4 * j t 9 = a[t 8 ] a[t 7 ] = t 9 t 10 = 4 * j a[t 10 ] = x goto (5) t 11 = 4 * i x = a[t 11 ] t 12 = 4 * i t 13 = 4 * n t 14 = a[t 13 ] a[t 12 ] = t 14 t 15 = 4 * n a[t 15 ] = x 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  • 31. Flow Graph if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 t 6 = 4 * i x = a[t 6 ] t 7 = 4 * i t 8 = 4 * j t 9 = a[t 8 ] a[t 7 ] = t 9 t 10 = 4 * j a[t 10 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 12 = 4 * i t 13 = 4 * n t 14 = a[t 13 ] a[t 12 ] = t 14 t 15 = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 32. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 t 6 = 4 * i x = a[t 6 ] t 7 = 4 * i t 8 = 4 * j t 9 = a[t 8 ] a[t 7 ] = t 9 t 10 = 4 * j a[t 10 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 12 = 4 * i t 13 = 4 * n t 14 = a[t 13 ] a[t 12 ] = t 14 t 15 = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 33. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 t 6 = 4 * i x = a[t 6 ] t 8 = 4 * j t 9 = a[t 8 ] a[ t 6 ] = t 9 t 10 = 4 * j a[t 10 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 12 = 4 * i t 13 = 4 * n t 14 = a[t 13 ] a[t 12 ] = t 14 t 15 = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 34. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 t 6 = 4 * i x = a[t 6 ] t 8 = 4 * j t 9 = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11 = 4 *i x = a[t 11 ] t 12 = 4 * i t 13 = 4 * n t 14 = a[t 13 ] a[t 12 ] = t 14 t 15 = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 35. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 t 6 = 4 * i x = a[t 6 ] t 8 = 4 * j t 9 = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 12 = 4 * i t 13 = 4 * n t 14 = a[t 13 ] a[t 12 ] = t 14 t 15 = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 36. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 t 6 = 4 * i x = a[t 6 ] t 8 = 4 * j t 9 = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 13 = 4 * n t 14 = a[t 13 ] a[ t 11 ] = t 14 t 15 = 4 * n a[t 15 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 37. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 t 6 = 4 * i x = a[t 6 ] t 8 = 4 * j t 9 = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 13 = 4 * n t 14 = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 38. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 t 6 = 4 * i x = a[t 6 ] t 8 = 4 * j t 9 = a[t 8 ] a[ t 6 ] = t 9 a[ t 8 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 13 = 4 * n t 14 = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 39. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 x = a[ t 2 ] t 8 = 4 * j t 9 = a[t 8 ] a[ t 2 ] = t 9 a[ t 8 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 13 = 4 * n t 14 = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 40. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 x = t 3 t 8 = 4 * j t 9 = a[t 8 ] a[ t 2 ] = t 9 a[ t 8 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 13 = 4 * n t 14 = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 41. Common Subexpression Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 x = t 3 a[ t 2 ] = t 5 a[ t 4 ] = x goto B 2 t 11 = 4 * i x = a[t 11 ] t 13 = 4 * n t 14 = a[t 13 ] a[ t 11 ] = t 14 a[ t 13 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 42. Common Subexpression Elimination if i >= j goto B 6 Similarly for B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 x = t 3 a[ t 2 ] = t 5 a[ t 4 ] = x goto B 2 x = t 3 t 14 = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 43. Dead Code Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 x = t 3 a[ t 2 ] = t 5 a[ t 4 ] = x goto B 2 x = t 3 t 14 = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = x B 1 B 2 B 3 B 4 B 5 B 6
  • 44. Dead Code Elimination if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 a[ t 2 ] = t 5 a[ t 4 ] = t 3 goto B 2 t 14 = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = t 3 B 1 B 2 B 3 B 4 B 5 B 6
  • 45. Reduction in Strength if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] i = i + 1 t 2 = 4 * i t 3 = a[t 2 ] if t 3 < v goto B 2 j = j – 1 t 4 = 4 * j t 5 = a[t 4 ] if t 5 > v goto B 3 a[ t 2 ] = t 5 a[ t 4 ] = t 3 goto B 2 t 14 = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = t 3 B 1 B 2 B 3 B 4 B 5 B 6
  • 46. Reduction in Strength if i >= j goto B 6 i = m - 1 j = n t 1 =4 * n v = a[t 1 ] t 2 = 4 * i t 4 = 4 * j t 2 = t 2 + 4 t 3 = a[t 2 ] if t 3 < v goto B 2 t 4 = t 4 - 4 t 5 = a[t 4 ] if t 5 > v goto B 3 a[ t 2 ] = t 5 a[ t 4 ] = t 3 goto B 2 t 14 = a[t 1 ] a[ t 2 ] = t 14 a[ t 1 ] = t 3 B 1 B 2 B 3 B 4 B 5 B 6