1 / 16

Generating Compiler Optimizations from Proofs - PowerPoint PPT Presentation

Generating Compiler Optimizations from Proofs. Ross Tate Michael Stepp Sorin Lerner University of California, San Diego. Optimizing by Hand. Original. Optimized. for (i = 0; i < 5 0 ; i++) for (j = 0; j < 5 0 ; j++) *(img++) = f(i, j); Executes more efficiently.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

PowerPoint Slideshow about ' Generating Compiler Optimizations from Proofs' - asis

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Generating Compiler Optimizations from Proofs

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++) = f(i, j);

Executes more efficiently

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

img[i*50 + j] = f(i, j);

• Easier to understand

Make the compiler do it!

Train the compiler to do it!

Many compilers do not perform this optimization

Original

Optimized

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++))

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

img[i*50 + j] = f(i, j);

for (i = 0; i < w; i++)

for (j = 0; j < h; j++)

use(img[i*h+ j])

Generalize

Generalized

h is loop-invariant

use does not modify i, j, or img

Original

Optimized

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

*(img++) = f(i, j);

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

img[i*50 + j] = f(i, j);

How it works

Instantiation

Translation Validator

Proof Generalizer

• Programmers can teach the compiler

• with just one concrete example

• using a language they already know

8 + 8 – 8 important

Translation Validator

8 + 8 – 8 = 8

8

Generalized Proof important

∃e.

e – e = 0

∃c,d.

c = 0

d + c = d

Uses fact i

Translation Validator

Proof Generalizer

Proof Generalizer

a

d + e – e

d + c

c

a

i) e – e = 0

i) c = 0

ii) a = b

i) c = 0

ii) a = b

i) c = 0

ii) d + c = b

i) c = 0

ii) d + c = d

i) e – e = 0

ii) d + e – e = d

c = 0

c

c

a = b

a

c

b

∀x. x – x = 0

∀x,y. x = 0 ⇒y + x = y

b

d

b

Instantiation: d,e↦ 8

Uses fact i

8 + 8 – 8

i) 8 – 8 = 0

i) 8 – 8 = 0

ii) 8 + 8 – 8 = 8

8

d + e – e

Translation Validator

Proof Generalizer

Learned Optimization

d

by examining a proof of equivalence

8 + 8 – 8

8

Abstract Algorithm important

• Formalized using category theory

• Pushouts

• Pullbacks

• Pushout Completions

• Different categories for different logics

• Different representations of programs

• Domains besides program optimizations

Proof Generalizer

Application & importantEvaluation

Training the Optimizer important

• Need a more expressive logic

• Program Expression Graphs [POPL ‘09]

Translation Validator

Proof Generalizer

Training the Optimizer important

• 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,

Speeding Up Optimization important

• Ran on a ray tracer

• Rewriter produced high-quality code

Optimization Generalizer

• We want

• the speed of the rewriter

Decomposer

Fast Rewriter

Flexible Proof Generalization important

• Learn database query optimizations

• Improve type error messages in Haskell

• Assist with contract debugging in Spec#

• Infer polymorphism in typed programs

Proof Generalizer

τ

Conclusion important

• Algorithm to learn compiler optimizations

• from programmers

• from superoptimizers

• Abstract proof generalization algorithm

• Applicable to other logics

• Applicable to other domains

Thank You