Provably correct peephole optimizations with alive

Compilers should not miscompile. Our work addresses problems in developing peephole optimizations that perform local rewriting to improve the efficiency of LLVM code. These optimizations are individually difficult to get right, particularly in the presence of undefined behavior; taken together they represent a persistent source of bugs. This paper presents Alive, a domain-specific language for writing optimizations and for automatically either proving them correct or else generating counterexamples. Furthermore, Alive can be automatically translated into C++ code that is suitable for inclusion in an LLVM optimization pass. Alive is based on an attempt to balance usability and formal methods; for example, it captures---but largely hides---the detailed semantics of three different kinds of undefined behavior in LLVM. We have translated more than 300 LLVM optimizations into Alive and, in the process, found that eight of them were wrong.

[1]  Simon L. Peyton Jones,et al.  Hoopl: a modular, reusable library for dataflow analysis and transformation , 2010, Haskell.

[2]  José C. Monteiro,et al.  Automatic equivalence checking of programs with uninterpreted functions and integer arithmetic , 2015, International Journal on Software Tools for Technology Transfer.

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

[4]  Shuvendu K. Lahiri,et al.  Will you still compile me tomorrow? static cross-version compiler validation , 2013, ESEC/FSE 2013.

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

[6]  E. Gunter,et al.  A Cross-Language Framework for Verifying Compiler Optimizations , 2014 .

[7]  Mark N. Wegman,et al.  Efficiently computing static single assignment form and the control dependence graph , 1991, TOPL.

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

[9]  José C. Monteiro,et al.  Weakest Precondition Synthesis for Compiler Optimizations , 2014, VMCAI.

[10]  W. M. McKeeman,et al.  Differential Testing for Software , 1998, Digit. Tech. J..

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

[12]  Santosh Nagarakatte,et al.  Formal verification of SSA-based optimizations for LLVM , 2013, PLDI.

[13]  Sebastian Buchwald Optgen: A Generator for Local Optimizations , 2015, CC.

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

[15]  Hanan Samet,et al.  Proving the correctness of heuristically optimized code , 1978, CACM.

[16]  Dexter Kozen,et al.  Certification of Compiler Optimizations Using Kleene Algebra with Tests , 2000, Computational Logic.

[17]  Alexander Aiken,et al.  Stochastic superoptimization , 2012, ASPLOS '13.

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

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

[20]  Viktor Vafeiadis,et al.  Common Compiler Optimisations are Invalid in the C11 Memory Model and what we can do about it , 2015, POPL.

[21]  Francesco Zappa Nardelli,et al.  Compiler testing via a theory of sound optimisations in the C11/C++11 memory model , 2013, PLDI.

[22]  Milo M. K. Martin,et al.  Formalizing the LLVM intermediate representation for verified program transformations , 2012, POPL '12.

[23]  Magnus O. Myreen,et al.  Translation validation for a verified OS kernel , 2013, PLDI.

[24]  Calvin Lin,et al.  Broadway: A Compiler for Exploiting the Domain-Specific Semantics of Software Libraries , 2005, Proceedings of the IEEE.

[25]  Zhendong Su,et al.  Compiler validation via equivalence modulo inputs , 2014, PLDI.

[26]  Eric Van Wyk,et al.  Compiler Optimization Correctness by Temporal Logic , 2004, High. Order Symb. Comput..

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

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

[29]  Yunhong Zhou,et al.  Denali: A practical algorithm for generating optimal code , 2006, TOPL.

[30]  Wilhelm Ackermann,et al.  Solvable Cases Of The Decision Problem , 1954 .

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

[32]  Mary Lou Soffa,et al.  An approach for exploring code improving transformations , 1997, TOPL.

[33]  Tarmo Uustalu,et al.  Program and proof optimizations with type systems , 2008, J. Log. Algebraic Methods Program..

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

[35]  Francesco Ranzato,et al.  Tracing compilation by abstract interpretation , 2014, POPL.

[36]  Christopher W. Fraser,et al.  Automatic generation of peephole optimizations , 2004, SIGP.

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

[38]  Uwe Aamann How to Uniformly Specify Program Analysis and Transformation with Graph Rewrite Systems , 1996 .