SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 
ข้อสอบคณิตศาสตร์
ข้อสอบคณิตศาสตร์ข้อสอบคณิตศาสตร์
ข้อสอบคณิตศาสตร์
 

Dernier

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
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
 
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
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
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
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 

Dernier (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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
 
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
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.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)
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
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...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.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