### pptx

```Ross Tate
Michael Stepp
Sorin Lerner
University of California,
San Diego
Original
Optimized
for (i = 0; i < 50; i++)
for (j = 0; j < 50; j++)
img[i*50 + j] = f(i, j);
for (i = 0; i < 50; i++)
for (j = 0; j < 50; j++)
*(img++) = f(i, j);
 Easier
to
 Executes more
Train
Make
the
the
compiler
compiler
to
do
do
it!
it!
understand
efficiently
Many compilers do not
perform this optimization
Original
Optimized
for (i = 0; i < 50; i++)
for (j = 0; j < 50; j++)
img[i*50 + j] = f(i, j);
Generalized
Generalize
for (i = 0; i < w; i++)
for (j = 0; j < h; j++)
use(img[i*h + j])
h is loop-invariant
for (i = 0; i < 50; i++)
for (j = 0; j < 50; j++)
*(img++) = f(i, j);
for (i = 0; i < w; i++)
for (j = 0; j < h; j++)
use(*(img++))
use does not modify i, j, or img
Original
for (i = 0; i < 50; i++)
for (j = 0; j < 50; j++)
img[i*50 + j] = f(i, j);
Optimized
for (i = 0; i < 50; i++)
for (j = 0; j < 50; j++)
*(img++) = f(i, j);
Proof informs
which details in
the programs are
actually important
Translation
Validator
Proof
Generalizer
Programmers can teach the compiler
• with just one concrete example
• using a language they already know
8+8–8
Translation
Validator
8
8+8–8=8
∃e. Generalized
e – e = 0 ∃c,d. c
= 0⇒ d + c = d
Proof
∅
Uses fact i
Translation
Generalizer
Validator
i) c
e=
–e
i) e
c=
–e
0=0
0=0
∀x. x – x = 0
d x=
+=b
ey=
–e
b= d
d
a
c
∀x,y. x = 0 ⇒ ii)
y+
dd
+a
+
e c– e
d
b
Instantiation: d,e
Uses ↦
fact8i
∅
i) 8 – 8 = 0
8+8–8
i) 8 – 8 = 0
ii) 8 + 8 – 8 = 8
8
Most General Optimization
for this proof
d+e–e
Translation
Validator
Proof
Generalizer
d
8+8–8
8
 Formalized



Pushouts
Pullbacks
Pushout Completions
 Different


using category theory
Proof
Generalizer
categories for different logics
Different representations of programs
Domains besides program optimizations
Translation
Validator
 Need

Proof
Generalizer
a more expressive logic
Program Expression Graphs [POPL ‘09]
 Inter-Loop
Strength & Bound Reduction
 Loop Induction Strength & Bound Reduction
 Partial & Specialized Inlining
 Temporary Object Removal
 Loop Operation Factoring & Distribution
 Entire Loop Strength Reduction
 Array Copy Propagation
As translation validation improves,
Optimizer
Optimization
Generalizer
We want
Decomposer
• the speed of the rewriter
Fast
Rewriter
 Ran

on a ray tracer
Rewriter produced
high-quality code
Proof
Generalizer

Learn database
query optimizations

Improve type error

Assist with contract
debugging in Spec#

Infer polymorphism
in typed programs
 Algorithm


from programmers
from superoptimizers
 Abstract


to learn compiler optimizations
proof generalization algorithm
Applicable to other logics
Applicable to other domains
```