SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Code generator
Code generatorCode generator
Code generatorTech_MX
 
Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksMohammad Vaseem Akaram
 
code optimization 1...code optimization-1221849738688969-9
code optimization 1...code optimization-1221849738688969-9code optimization 1...code optimization-1221849738688969-9
code optimization 1...code optimization-1221849738688969-9Sanjeev Raaz
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchHema Kashyap
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler designRajkumar R
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical AnalyzerArchana Gopinath
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler designAnul Chaudhary
 

What's hot (20)

Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Code generator
Code generatorCode generator
Code generator
 
Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocks
 
code optimization 1...code optimization-1221849738688969-9
code optimization 1...code optimization-1221849738688969-9code optimization 1...code optimization-1221849738688969-9
code optimization 1...code optimization-1221849738688969-9
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
 
Heap Management
Heap ManagementHeap Management
Heap Management
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 

Similar to 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
 
طراحی الگوریتم فصل 1
طراحی الگوریتم فصل 1طراحی الگوریتم فصل 1
طراحی الگوریتم فصل 1Saeed Sarshar
 
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
 

Similar to 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
 
ブロックチェーン: 「 書き換え不可能な記録」によって 社会はどう変化するか?
ブロックチェーン: 「書き換え不可能な記録」によって社会はどう変化するか? ブロックチェーン: 「書き換え不可能な記録」によって社会はどう変化するか?
ブロックチェーン: 「 書き換え不可能な記録」によって 社会はどう変化するか?
 
Integral calculus
Integral calculusIntegral calculus
Integral calculus
 
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
 
طراحی الگوریتم فصل 1
طراحی الگوریتم فصل 1طراحی الگوریتم فصل 1
طراحی الگوریتم فصل 1
 
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.
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........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