![Page 1: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/1.jpg)
Introduction to Optimization1
Kristoffer H. [email protected]
Compiler ConstructionCSCI-GA.2130-001/Spring 2014
NYU Courant Institute
April 28, 2014
1ALSU §9.1K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 1 / 13
![Page 2: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/2.jpg)
Sixth compilation phase
source program
Lexical Analysis--
Syntax AnalysisTokens
--
Semantic AnalysisTree
--
Intermediate Representation GeneratorTree
--
SymbolTable
OptimizerIR--
Code GeneratorIR--
Machine-Dependent Code OptimizerAsm
--
target machine code��
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 2 / 13
![Page 3: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/3.jpg)
Sources of Redundancy
I Programmer “cut-n-paste”I Compiler templates.I Insufficient state transfer.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 3 / 13
![Page 4: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/4.jpg)
Sources of Redundancy
I Programmer “cut-n-paste”I Compiler templates.I Insufficient state transfer.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 3 / 13
![Page 5: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/5.jpg)
Sources of Redundancy
I Programmer “cut-n-paste”I Compiler templates.I Insufficient state transfer.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 3 / 13
![Page 6: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/6.jpg)
Example
void quicksort(int a[], int m, int n){int i, j, v, x; if (n <= m) return;
i = m-1; j = n; v = a[n];while (1) {do i = i+1; while (a[i] < v);do j = j-1; while (a[j] > v);if (i >= j) break;x = a[i]; a[i] = a[j]; a[j] = x;
}x = a[i]; a[i] = a[n]; a[n] = x;
quicksort(a,m,j); quicksort(a,i+1,n);}
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 4 / 13
![Page 7: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/7.jpg)
Basic Blocks
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = a[t6]t7 = 4*it8 = 4*jt9 = a[t8]a[t7] = t9t10 = 4*ja[t10] = xgoto B2
B5:ww
��t11 = 4*ix = a[t11]t13 = 4*nt14 = a[t13]a[t11] = t14t15 = 4*na[t15] = x
B6:%%
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 5 / 13
![Page 8: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/8.jpg)
(Local) Common Subexpression Elimination
t6 = 4*ix = a[t6]t7 = 4*it8 = 4*jt9 = a[t8]a[t7] = t9t10 = 4*ja[t10] = xgoto B2
B5:
⇒
t6 = 4*ix = a[t6]t8 = 4*jt9 = a[t8]a[t6] = t9a[t8] = xgoto B2
B5:
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 6 / 13
![Page 9: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/9.jpg)
(Local) Common Subexpression Elimination
t6 = 4*ix = a[t6]t7 = 4*it8 = 4*jt9 = a[t8]a[t7] = t9t10 = 4*ja[t10] = xgoto B2
B5:
⇒
t6 = 4*ix = a[t6]t8 = 4*jt9 = a[t8]a[t6] = t9a[t8] = xgoto B2
B5:
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 6 / 13
![Page 10: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/10.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = a[t6]t8 = 4*jt9 = a[t8]a[t6] = t9a[t8] = xgoto B2
B5:yy��
t11 = 4*ix = a[t11]t13 = 4*nt14 = a[t1]a[t11] = t14a[t13] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 11: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/11.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = a[t6]t8 = 4*jt9 = a[t8]a[t6] = t9a[t8] = xgoto B2
B5:yy��
t11 = 4*ix = a[t11]t13 = 4*nt14 = a[t1]a[t11] = t14a[t13] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 12: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/12.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = a[t2]t8 = 4*jt9 = a[t8]a[t2] = t9a[t8] = xgoto B2
B5:yy��
t11 = 4*ix = a[t11]t13 = 4*nt14 = a[t1]a[t11] = t14a[t13] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 13: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/13.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = t3t8 = 4*jt9 = a[t8]a[t2] = t9a[t8] = xgoto B2
B5:yy��
t11 = 4*ix = a[t11]t13 = 4*nt14 = a[t1]a[t11] = t14a[t13] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 14: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/14.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = t3t8 = 4*jt9 = a[t8]a[t2] = t9a[t8] = xgoto B2
B5:yy��
t11 = 4*ix = a[t11]t13 = 4*nt14 = a[t1]a[t11] = t14a[t13] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 15: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/15.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = t3
a[t2] = t5a[t4] = xgoto B2
B5:yy��
t11 = 4*ix = a[t11]t13 = 4*nt14 = a[t1]a[t11] = t14a[t13] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 16: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/16.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = t3
a[t2] = t5a[t4] = xgoto B2
B5:yy��
t11 = 4*ix = a[t11]t13 = 4*nt14 = a[t1]a[t11] = t14a[t13] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 17: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/17.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = t3
a[t2] = t5a[t4] = xgoto B2
B5:yy��
t11 = 4*ix = t3t13 = 4*nt14 = a[t1]a[t2] = t14a[t1] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 18: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/18.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = t3
a[t2] = t5a[t4] = xgoto B2
B5:yy��
t11 = 4*ix = t3t13 = 4*nt14 = a[t1]a[t2] = t14a[t1] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 19: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/19.jpg)
Global Common Subexpression Elimination
i = m-1j = nt1 = 4*nv = a[t1]
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
t6 = 4*ix = t3
a[t2] = t5a[t4] = xgoto B2
B5:yy��
t11 = 4*ix = t3t13 = 4*nt14 = a[t1]a[t2] = t14a[t1] = x
B6:##
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 7 / 13
![Page 20: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/20.jpg)
Copy Propagation
t = d + ea = d + e
B1: t = d + eb = d + e
B2:
c = d + eB3:$$ zz
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 8 / 13
![Page 21: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/21.jpg)
Copy Propagation
t = d + ea = t
B1: t = d + eb = t
B2:
c = tB3:$$ zz
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 8 / 13
![Page 22: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/22.jpg)
Code Motion
while (i <= limit -2) /*not changing limit*/
becomes
t = limit -2;while (i <= t) /*not changing limit or t*/
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 9 / 13
![Page 23: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/23.jpg)
Code Motion
while (i <= limit -2) /*not changing limit*/
becomes
t = limit -2;while (i <= t) /*not changing limit or t*/
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 9 / 13
![Page 24: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/24.jpg)
Induction Invariants and Reduction in Strength
i = m-1j = nt1 = 4*nv = a[t1]t2 = 4*it4 = 4*j
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
x = t3a[t2] = t5a[t4] = xgoto B2
B5:}}
��
x = t3t14 = a[t1]a[t2] = t14a[t1] = x
B6:!!
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 10 / 13
![Page 25: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/25.jpg)
Induction Invariants and Reduction in Strength
i = m-1j = nt1 = 4*nv = a[t1]t2 = 4*it4 = 4*j
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = 4*jt5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
x = t3a[t2] = t5a[t4] = xgoto B2
B5:}}
��
x = t3t14 = a[t1]a[t2] = t14a[t1] = x
B6:!!
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 10 / 13
![Page 26: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/26.jpg)
Induction Invariants and Reduction in Strength
i = m-1j = nt1 = 4*nv = a[t1]t2 = 4*it4 = 4*j
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = t4-4t5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
x = t3a[t2] = t5a[t4] = xgoto B2
B5:}}
��
x = t3t14 = a[t1]a[t2] = t14a[t1] = x
B6:!!
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 10 / 13
![Page 27: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/27.jpg)
Induction Invariants and Reduction in Strength
i = m-1j = nt1 = 4*nv = a[t1]t2 = 4*it4 = 4*j
B1:
i = i+1t2 = 4*it3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = t4-4t5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
x = t3a[t2] = t5a[t4] = xgoto B2
B5:}}
��
x = t3t14 = a[t1]a[t2] = t14a[t1] = x
B6:!!
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 10 / 13
![Page 28: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/28.jpg)
Induction Invariants and Reduction in Strength
i = m-1j = nt1 = 4*nv = a[t1]t2 = 4*it4 = 4*j
B1:
i = i+1t2 = t2+4t3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = t4-4t5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
x = t3a[t2] = t5a[t4] = xgoto B2
B5:}}
��
x = t3t14 = a[t1]a[t2] = t14a[t1] = x
B6:!!
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 10 / 13
![Page 29: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/29.jpg)
Induction Invariants and Reduction in Strength
i = m-1j = nt1 = 4*nv = a[t1]t2 = 4*it4 = 4*j
B1:
i = i+1t2 = t2+4t3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = t4-4t5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
x = t3a[t2] = t5a[t4] = xgoto B2
B5:}}
��
x = t3t14 = a[t1]a[t2] = t14a[t1] = x
B6:!!
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 10 / 13
![Page 30: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/30.jpg)
Induction Invariants and Reduction in Strength
i = m-1j = nt1 = 4*nv = a[t1]t2 = 4*it4 = 4*j
B1:
i = i+1t2 = t2+4t3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = t4-4t5 = a[t4]if t5>v goto B3
B3:�� ��
if i>=j goto B6B4:##
x = t3a[t2] = t5a[t4] = xgoto B2
B5:}}
��
x = t3t14 = a[t1]a[t2] = t14a[t1] = x
B6:!!
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 10 / 13
![Page 31: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/31.jpg)
Induction Invariants and Reduction in Strength
i = m-1j = nt1 = 4*nv = a[t1]t2 = 4*it4 = 4*j
B1:
i = i+1t2 = t2+4t3 = a[t2]if t3<v goto B2
B2:�� ��
j = j-1t4 = t4-4t5 = a[t4]if t5>v goto B3
B3:�� ��
if t2>=t4 goto B6B4:##
x = t3a[t2] = t5a[t4] = xgoto B2
B5:}}
��
x = t3t14 = a[t1]a[t2] = t14a[t1] = x
B6:!!
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 10 / 13
![Page 32: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/32.jpg)
i = m-1t1 = 4*nv = a[t1]t2 = 4*it4 = t1
B1:
t2 = t2+4t3 = a[t2]if t3<v goto B2
B2:�� ��
t4 = t4-4t5 = a[t4]if t5>v goto B3
B3:�� ��
if t2>=t4 goto B6B4:!!
a[t2] = t5a[t4] = t3goto B2
B5:~~
��
t14 = a[t1]a[t2] = t14a[t1] = t3
B6:
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 11 / 13
![Page 33: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/33.jpg)
Summary
Redundancy but preserve semantics!I Global Common Subexpressions.I Copy Propagation.I Dead-code Elimination.I Code Motion.I Induction Variables/Strength Reduction.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 12 / 13
![Page 34: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/34.jpg)
Summary
Redundancy but preserve semantics!I Global Common Subexpressions.I Copy Propagation.I Dead-code Elimination.I Code Motion.I Induction Variables/Strength Reduction.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 12 / 13
![Page 35: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/35.jpg)
Summary
Redundancy but preserve semantics!I Global Common Subexpressions.I Copy Propagation.I Dead-code Elimination.I Code Motion.I Induction Variables/Strength Reduction.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 12 / 13
![Page 36: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/36.jpg)
Summary
Redundancy but preserve semantics!I Global Common Subexpressions.I Copy Propagation.I Dead-code Elimination.I Code Motion.I Induction Variables/Strength Reduction.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 12 / 13
![Page 37: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/37.jpg)
Summary
Redundancy but preserve semantics!I Global Common Subexpressions.I Copy Propagation.I Dead-code Elimination.I Code Motion.I Induction Variables/Strength Reduction.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 12 / 13
![Page 38: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/38.jpg)
Summary
Redundancy but preserve semantics!I Global Common Subexpressions.I Copy Propagation.I Dead-code Elimination.I Code Motion.I Induction Variables/Strength Reduction.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 12 / 13
![Page 39: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/39.jpg)
Summary
Redundancy but preserve semantics!I Global Common Subexpressions.I Copy Propagation.I Dead-code Elimination.I Code Motion.I Induction Variables/Strength Reduction.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 12 / 13
![Page 40: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/40.jpg)
Questions?
I HACS will recover this week, and pr2 will be restarted.I Because of GSAS conflict we swap final and pr3:
I Final is May 12.I pr3 will be due week of May 19.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 13 / 13
![Page 41: New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H. Rose krisrose@cs.nyu.edu Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant](https://reader035.vdocument.in/reader035/viewer/2022081617/60532c07b37e4617e7382d4a/html5/thumbnails/41.jpg)
Questions?
I HACS will recover this week, and pr2 will be restarted.I Because of GSAS conflict we swap final and pr3:
I Final is May 12.I pr3 will be due week of May 19.
K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 13 / 13