Weakest Precondition Synthesis for Compiler Optimizations

Compiler optimizations play an increasingly important role in code generation. This is especially true with the advent of resourcelimited mobile devices. We rely on compiler optimizations to improve performance, reduce code size, and reduce power consumption of our programs. Despite being a mature field, compiler optimizations are still designed and implemented by hand, and usually without providing any guarantee of correctness. In addition to devising the code transformations, designers and implementers have to come up with an analysis that determines in which cases the optimization can be safely applied. In other words, the optimization designer has to specify a precondition that ensures that the optimization is semantics-preserving. However, devising preconditions for optimizations by hand is a non-trivial task. It is easy to specify a precondition that, although correct, is too restrictive, and therefore misses some optimization opportunities. In this paper, we propose, to the best of our knowledge, the first algorithm for the automatic synthesis of preconditions for compiler optimizations. The synthesized preconditions are provably correct by construction, and they are guaranteed to be the weakest in the precondition language that we consider. We implemented the proposed technique in a tool named PSyCO. We present examples of preconditions synthesized by PSyCO, as well as the results of running PSyCO on a set of optimizations.

[1]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools (2nd Edition) , 2006 .

[2]  Kaisa Sere,et al.  FM 2008: Formal Methods, 15th International Symposium on Formal Methods, Turku, Finland, May 26-30, 2008, Proceedings , 2008, FM.

[3]  Ulrich Junker,et al.  QUICKXPLAIN: Preferred Explanations and Relaxations for Over-Constrained Problems , 2004, AAAI.

[4]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[5]  Andreas Podelski,et al.  ACSAR: Software Model Checking with Transfinite Refinement , 2007, SPIN.

[6]  Michael Stepp,et al.  Generating compiler optimizations from proofs , 2010, POPL '10.

[7]  Sumit Gulwani,et al.  Constraint-Based Invariant Inference over Predicate Abstraction , 2008, VMCAI.

[8]  Leonardo Mendonça de Moura,et al.  Computation in Real Closed Infinitesimal and Transcendental Extensions of the Rationals , 2013, CADE.

[9]  Marius Bozga,et al.  Deciding Conditional Termination , 2012, TACAS.

[10]  Sorin Lerner,et al.  Bringing extensibility to verified compilers , 2010, PLDI '10.

[11]  Amir Pnueli,et al.  Translation Validation , 1998, TACAS.

[12]  Benjamin Goldberg,et al.  Into the Loops: Practical Issues in Translation Validation for Optimizing Compilers , 2005, COCV@ETAPS.

[13]  Yannick Moy,et al.  Sufficient Preconditions for Modular Assertion Checking , 2008, VMCAI.

[14]  Edsger W. Dijkstra,et al.  Guarded commands, nondeterminacy and formal derivation of programs , 1975, Commun. ACM.

[15]  Jens Palsberg,et al.  The essence of compiling with traces , 2011, POPL '11.

[16]  Yunhong Zhou,et al.  Denali: A practical algorithm for generating optimal code , 2006, ACM Trans. Program. Lang. Syst..

[17]  Krzysztof R. Apt,et al.  Logic Programming , 1990, Handbook of Theoretical Computer Science, Volume B: Formal Models and Sematics.

[18]  Sorin Lerner,et al.  Automatically proving the correctness of compiler optimizations , 2003, PLDI '03.

[19]  Michael Stepp,et al.  Equality saturation: a new approach to optimization , 2009, POPL '09.

[20]  Sorin Lerner,et al.  Proving optimizations correct using parameterized program equivalence , 2009, PLDI '09.

[21]  Nikolaj Bjørner,et al.  Z3: An Efficient SMT Solver , 2008, TACAS.

[22]  Milo M. K. Martin,et al.  Formal verification of SSA-based optimizations for LLVM , 2013, PLDI.

[23]  George C. Necula,et al.  Translation validation for an optimizing compiler , 2000, PLDI '00.

[24]  Mikolás Janota,et al.  Minimal Sets over Monotone Predicates in Boolean Formulae , 2013, CAV.

[25]  Kedar S. Namjoshi,et al.  Witnessing Program Transformations , 2013, SAS.

[26]  K. Rustan M. Leino,et al.  Efficient weakest preconditions , 2005, Inf. Process. Lett..

[27]  Kousha Etessami,et al.  Analysis of Recursive Game Graphs Using Data Flow Equations , 2004, VMCAI.

[28]  Xavier Leroy,et al.  Formal verification of a realistic compiler , 2009, CACM.

[29]  Rajeev Alur,et al.  A Temporal Logic of Nested Calls and Returns , 2004, TACAS.

[30]  Alexander Aiken,et al.  Automatic generation of peephole superoptimizers , 2006, ASPLOS XII.

[31]  Marina De Vos,et al.  TOAST: Applying Answer Set Programming to Superoptimisation , 2006, ICLP.

[32]  Sumit Gulwani,et al.  Synthesis of loop-free programs , 2011, PLDI '11.

[33]  Shuvendu K. Lahiri,et al.  Towards Modularly Comparing Programs Using Automated Theorem Provers , 2013, CADE.

[34]  Sorin Lerner,et al.  Equality-Based Translation Validator for LLVM , 2011, CAV.

[35]  Nick Benton,et al.  Simple relational correctness proofs for static analyses and program transformations , 2004, POPL.

[36]  Sorin Lerner,et al.  Automatic inference of optimizer flow functions from semantic meanings , 2007, PLDI '07.

[37]  Peter W. O'Hearn,et al.  Compositional Shape Analysis by Means of Bi-Abduction , 2011, JACM.

[38]  Patrick Cousot,et al.  Automatic Inference of Necessary Preconditions , 2013, VMCAI.

[39]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[40]  J. Gregory Morrisett,et al.  Evaluating value-graph translation validation for LLVM , 2011, PLDI '11.

[41]  Wolfram Schulte,et al.  FM 2011: Formal Methods - 17th International Symposium on Formal Methods, Limerick, Ireland, June 20-24, 2011. Proceedings , 2011, FM.

[42]  Sumit Gulwani,et al.  Proving Conditional Termination , 2008, CAV.

[43]  Xuejun Yang,et al.  Finding and understanding bugs in C compilers , 2011, PLDI '11.

[44]  José C. Monteiro,et al.  Automatic Equivalence Checking of UF+IA Programs , 2013, SPIN.

[45]  Sorin Lerner,et al.  Automated soundness proofs for dataflow analyses and transformations via local rules , 2005, POPL '05.

[46]  Amir Pnueli,et al.  Translation and Run-Time Validation of Loop Transformations , 2005, Formal Methods Syst. Des..

[47]  Daniel Kroening,et al.  Counterexample-Guided Precondition Inference , 2013, ESOP.

[48]  Amir Pnueli,et al.  CoVaC: Compiler Validation by Program Analysis of the Cross-Product , 2008, FM.

[49]  Gilles Barthe,et al.  Relational Verification Using Product Programs , 2011, FM.

[50]  Steven S. Muchnick,et al.  Advanced Compiler Design and Implementation , 1997 .