+ All Categories
Home > Documents > New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H....

New Introduction to Optimization · 2017. 3. 18. · Introduction to Optimization1 Kristoffer H....

Date post: 16-Oct-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
41
Introduction to Optimization 1 Kristoffer H. Rose [email protected] Compiler Construction CSCI-GA.2130-001/Spring 2014 NYU Courant Institute April 28, 2014 1 ALSU §9.1 K.H.Rose CSCI-GA.2130-001/Spring 2014/Optimization April 28, 2014 1 / 13
Transcript
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

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

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

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

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

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

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

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

(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

(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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Questions?

[email protected]

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

Questions?

[email protected]

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


Recommended