Technology from seed Weakest Precondition Synthesis for Compiler Optimizations Nuno Lopes and José Monteiro.

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Technology from seed Automatic Equivalence Checking of UF+IA Programs Nuno Lopes and José Monteiro.
Semantics Static semantics Dynamic semantics attribute grammars
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Programming with Constraint Solvers CS294: Program Synthesis for Everyone Ras Bodik Emina Torlak Division of Computer Science University of California,
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Program Analysis as Constraint Solving Sumit Gulwani (MSR Redmond) Ramarathnam Venkatesan (MSR Redmond) Saurabh Srivastava (Univ. of Maryland) TexPoint.
Partial correctness © Marcelo d’Amorim 2010.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Predicate Transformers
Program Proving Notes Ellen L. Walker.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
Technology from seed Automatic Synthesis of Weakest Preconditions for Compiler Optimizations Nuno Lopes Advisor: José Monteiro.
CS 355 – Programming Languages
Automated Soundness Proofs for Dataflow Analyses and Transformations via Local Rules Sorin Lerner* Todd Millstein** Erika Rice* Craig Chambers* * University.
An Integration of Program Analysis and Automated Theorem Proving Bill J. Ellis & Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt.
Rahul Sharma Işil Dillig, Thomas Dillig, and Alex Aiken Stanford University Simplifying Loop Invariant Generation Using Splitter Predicates.
Proof-system search ( ` ) Interpretation search ( ² ) Main search strategy DPLL Backtracking Incremental SAT Natural deduction Sequents Resolution Main.
Automatically Proving the Correctness of Compiler Optimizations Sorin Lerner Todd Millstein Craig Chambers University of Washington.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
ECI 2007: Specification and Verification of Object- Oriented Programs Lecture 1.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
From last time S1: l := new Cons p := l S2: t := new Cons *p := t p := t l p S1 l p tS2 l p S1 t S2 l t S1 p S2 l t S1 p S2 l t S1 p L2 l t S1 p S2 l t.
VS 3 : Verification and Synthesis using SMT Solvers SMT Solvers for Program Verification Saurabh Srivastava * Sumit Gulwani ** Jeffrey S. Foster * * University.
Program Verification using Templates over Predicate Abstraction Saurabh Srivastava University of Maryland, College Park Sumit Gulwani Microsoft Research,
Describing Syntax and Semantics
Floyd Hoare Logic. Semantics A programming language specification consists of a syntactic description and a semantic description. Syntactic description:symbols.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Overview of program analysis Mooly Sagiv html://
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
Inferring Specifications to Detect Errors in Code Mana Taghdiri Presented by: Robert Seater MIT Computer Science & AI Lab.
CS 363 Comparative Programming Languages Semantics.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Reasoning about programs March CSE 403, Winter 2011, Brun.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Provably Correct Peephole Optimizations with Alive.
COMP 170 L2 L08: Quantifiers. COMP 170 L2 Outline l Quantifiers: Motivation and Concepts l Quantifiers: Notations and Meaning l Saying things with Quantified.
13 Aug 2013 Program Verification. Proofs about Programs Why make you study logic? Why make you do proofs? Because we want to prove properties of programs.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Proving Optimizations Correct using Parameterized Program Equivalence University of California, San Diego Sudipta Kundu Zachary Tatlock Sorin Lerner.
Finding and Understanding Bugs in C Compilers Xuejun Yang Yang Chen Eric Eide John Regehr University of Utah.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Weakest Precondition of Unstructured Programs
Sequence, Selection, Iteration The IF Statement
Expressions and Control Flow in JavaScript
Computers & Programming Languages
Programming Languages and Compilers (CS 421)
Improving Reliability of Compilers
Semantics In Text: Chapter 3.
A Brief Summary for Exam 1
Computer Science Core Concepts
Complete Program Synthesis for Linear Arithmetics
Statements joined by “And” (Conjunctions)
Relational Operators.
Advanced Compiler Design
The Zoo of Software Security Techniques
COP4020 Programming Languages
Presentation transcript:

technology from seed Weakest Precondition Synthesis for Compiler Optimizations Nuno Lopes and José Monteiro

technology from seed Deriving preconditions by hand is hard; WPs are often non-trivial WPs derived by hand are often wrong! Weaker preconditions expose more optimization opportunities Weakest Precondition Synthesis for Compiler Optimizations Why WP Synthesis for Compiler Optimizations?

technology from seed Yang, Chen, Eide, Regehr. Finding and Understanding Bugs in C Compilers, PLDI’12: –79 bugs in GCC (25 P1) –202 bugs in LLVM –2 wrong-code bugs in CompCert 32 open P1 bug reports in GCC (as of last week) 403 open wrong-code bug reports in GCC 16 open wrong-code bug reports in LLVM Weakest Precondition Synthesis for Compiler Optimizations Motivation: Compilers are Full of Bugs

technology from seed // For a logical right shift, we can fold if the comparison is not // signed. We can also fold a signed comparison if the shifted mask // value and the shifted comparison value are not negative. // These constraints are not obvious, but we can prove that they are // correct using an SMT solver such as "Z3" : // Weakest Precondition Synthesis for Compiler Optimizations Verification to the Rescue: LLVM PR17827 if (ShiftOpcode == Instruction::AShr) { // There may be some constraints that make this possible, // but nothing simple has been discovered yet. CanFold = false; } lib/Transforms/InstCombine/InstCombineCompares.cpp

technology from seed Preliminaries Language of Preconditions Example Algorithm Evaluation: PSyCO Weakest Precondition Synthesis for Compiler Optimizations Outline

technology from seed Preliminaries Language of Preconditions Example Algorithm Evaluation: PSyCO Weakest Precondition Synthesis for Compiler Optimizations Outline

technology from seed Compiler optimization –Transformation function –Precondition –Profitability heuristic Weakest Precondition Synthesis for Compiler Optimizations Compiler Optimizations

technology from seed Weakest Precondition Synthesis for Compiler Optimizations Loop Unswitching while I < N do if B then S 1 else S 2 I := I + 1 if B then while I < N do S 1 I := I + 1 else while I < N do S 2 I := I + 1 → S 1, S 2 are template statements B is a template Boolean expression

technology from seed Weakest Precondition Synthesis for Compiler Optimizations Loop Unswitching: Example Instantiation … while I < N do if N > 5 then A := A + N else A := A + 1 I := I + 1 … if N > 5 then while I < N do A := A + N I := I + 1 else while I < N do A := A + 1 I := I + 1 → while I < N do if B then S 1 else S 2 I := I + 1

technology from seed Weakest Precondition Synthesis for Compiler Optimizations Loop Unswitching: Weakest Precondition while I < N do if B then S 1 else S 2 I := I + 1 if B then while I < N do S 1 I := I + 1 else while I < N do S 2 I := I + 1 →

technology from seed Preliminaries Language of Preconditions Example Algorithm Evaluation: PSyCO Weakest Precondition Synthesis for Compiler Optimizations Outline

technology from seed Weakest Precondition Synthesis for Compiler Optimizations Language of Preconditions

technology from seed Books and developers already informally speak about read and write sets Can be efficiently discharged using current compiler technology: –Memory dependence analysis –Alias/pointer analysis –Loop analysis –Range analysis –… Weakest Precondition Synthesis for Compiler Optimizations Language of Preconditions: Suitability

technology from seed Preliminaries Language of Preconditions Example Algorithm Evaluation: PSyCO Weakest Precondition Synthesis for Compiler Optimizations Outline

technology from seed Weakest Precondition Synthesis for Compiler Optimizations Synthesizing WP for Loop Unswitching while I < N do if B then S 1 else S 2 I := I + 1 if B then while I < N do S 1 I := I + 1 else while I < N do S 2 I := I + 1 →

technology from seed Weakest Precondition Synthesis for Compiler Optimizations 1) Find counterexample while I < N do if B then S 1 else S 2 I := I + 1 if B then while I < N do S 1 I := I + 1 else while I < N do S 2 I := I + 1 → B I < N S 1 I := I + 1 I < N S 1 I := I + 1 I ≥ N Pre = true

technology from seed Weakest Precondition Synthesis for Compiler Optimizations 2) Synthesize WP for counterexample: VC Gen

technology from seed Weakest Precondition Synthesis for Compiler Optimizations 2) Synthesize WP for counterexample: Conditional Ackermannization B 0 and B 1 are equal if the values of the variables in R(B) are equal

technology from seed Weakest Precondition Synthesis for Compiler Optimizations 2) Synthesize WP for counterexample: Must-write vs may-write If a variable is in the write set of a statement, it may or may not be written.

technology from seed Weakest Precondition Synthesis for Compiler Optimizations 2) Synthesize WP for counterexample: Final constraint S = Read/Write sets V = Vars from VCGen, Must-write vars B I < N S 1 I := I + 1 I < N S 1 I := I + 1 I ≥ N

technology from seed Weakest Precondition Synthesis for Compiler Optimizations 2) Synthesize WP for counterexample: Disjunction of all models B I < N S 1 I := I + 1 I < N S 1 I := I + 1 I ≥ N

technology from seed Weakest Precondition Synthesis for Compiler Optimizations 3) Iterate until no more counterexamples can be found while I < N do if B then S 1 else S 2 I := I + 1 if B then while I < N do S 1 I := I + 1 else while I < N do S 2 I := I + 1 →

technology from seed Preliminaries Language of Preconditions Example Algorithm Evaluation: PSyCO Weakest Precondition Synthesis for Compiler Optimizations Outline

technology from seed 1) Find counterexample 2) Generate WP that rules out the counterexample 3) Iterate until no more counterexamples can be found Weakest Precondition Synthesis for Compiler Optimizations Algorithm

technology from seed Model generalization Exploit UNSAT cores Bias towards R/W and W/W intersections Weakest Precondition Synthesis for Compiler Optimizations Optimizations

technology from seed Preliminaries Language of Preconditions Example Algorithm Evaluation: PSyCO Weakest Precondition Synthesis for Compiler Optimizations Outline

technology from seed About 1,400 lines of Python Uses Z3 for constraint solving Source code and benchmarks available from Weakest Precondition Synthesis for Compiler Optimizations PSyCO: Precondition Synthesizer for Compiler Optimizations

technology from seed Weakest Precondition Synthesis for Compiler Optimizations PSyCO: Results

technology from seed Weakest Precondition Synthesis for Compiler Optimizations Example of Synthesized WP: Software Pipelining Precondition: (Weaker than PEC’s [PLDI’09])

technology from seed Deriving WPs by hand is hard and error-prone Weaker preconditions enable more optimization opportunities Presented the first algorithm for the automatic synthesis of WPs for compiler optimizations Weakest Precondition Synthesis for Compiler Optimizations Conclusion

technology from seed Título da apresentação technology from seed