ABSTRACT
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.
- W. Ackermann. Solvable Cases of the Decision Problem. Studies in Logic and the Foundations of Mathematics, 1954.Google Scholar
- U. Aßmann. How to uniformly specify program analysis and transformation with graph rewrite systems. In Proc. of the 6th International Conference on Compiler Construction, pages 121–135, 1996. Google ScholarDigital Library
- S. Bansal and A. Aiken. Automatic generation of peephole superoptimizers. In Proc. of the 12th International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS), pages 394–403, 2006. Google ScholarDigital Library
- S. Buchwald. Optgen: A generator for local optimizations. In Proc. of the 24th International Conference on Compiler Construction (CC), pages 171–189, Apr. 2015.Google ScholarCross Ref
- R. Cytron, J. Ferrante, B. K. Rosen, M. N. Wegman, and F. K. Zadeck. Efficiently computing static single assignment form and the control dependence graph. ACM Trans. Program. Lang. Syst., 13(4):451–490, Oct. 1991. Google ScholarDigital Library
- J. W. Davidson and C. W. Fraser. Automatic generation of peephole optimizations. In Proc. of the 1984 SIGPLAN Symposium on Compiler Construction, pages 111–116, 1984. Google ScholarDigital Library
- L. De Moura and N. Bjørner. Z3: An efficient SMT solver. In Proc. of the 14th International Conference on Tools and Algorithms for the Construction and Analysis of Systems, pages 337–340, 2008. Google ScholarDigital Library
- S. Dissegna, F. Logozzo, and F. Ranzato. Tracing compilation by abstract interpretation. In Proc. of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 47–59, 2014. Google ScholarDigital Library
- S. Guyer and C. Lin. Broadway: A compiler for exploiting the domainspecific semantics of software libraries. Proceedings of the IEEE, 93 (2), 2005.Google ScholarCross Ref
- C. Hawblitzel, S. K. Lahiri, K. Pawar, H. Hashmi, S. Gokbulut, L. Fernando, D. Detlefs, and S. Wadsworth. Will you still compile me tomorrow? Static cross-version compiler validation. In Proc. of the 9th Joint Meeting on Foundations of Software Engineering (FSE), 2013. Google ScholarDigital Library
- R. Joshi, G. Nelson, and Y. Zhou. Denali: A practical algorithm for generating optimal code. ACM Trans. Program. Lang. Syst., 28(6): 967–989, Nov. 2006. Google ScholarDigital Library
- D. Kozen and M.-C. Patron. Certification of compiler optimizations using Kleene algebra with tests. In Proc. of the 1st International Conference on Computational Logic, pages 568–582, 2000. Google ScholarDigital Library
- S. Kundu, Z. Tatlock, and S. Lerner. Proving optimizations correct using parameterized program equivalence. In Proc. of the 2009 ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 327–337, 2009. Google ScholarDigital Library
- D. Lacey, N. D. Jones, E. Van Wyk, and C. C. Frederiksen. Compiler optimization correctness by temporal logic. Higher Order Symbol. Comput., 17(3):173–206, Sept. 2004. Google ScholarDigital Library
- V. Le, M. Afshari, and Z. Su. Compiler validation via equivalence modulo inputs. In Proc. of the 35th ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 216–226, 2014. Google ScholarDigital Library
- S. Lerner, T. Millstein, E. Rice, and C. Chambers. Automated soundness proofs for dataflow analyses and transformations via local rules. In Proc. of the 32nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 364–377, 2005. Google ScholarDigital Library
- X. Leroy. Formal verification of a realistic compiler. Communications of the ACM, 52(7):107–115, 2009. Google ScholarDigital Library
- LLVM Developers. LLVM Language Reference Manual. Available from http://llvm.org/docs/LangRef.html, 2014.Google Scholar
- N. P. Lopes and J. Monteiro. Weakest precondition synthesis for compiler optimizations. In Proc. of the 15th International Conference on Verification, Model Checking, and Abstract Interpretation, pages 203–221, 2014.Google ScholarDigital Library
- N. P. Lopes and J. Monteiro. Automatic equivalence checking of programs with uninterpreted functions and integer arithmetic. Int. J. Softw. Tools Technol. Transf., 2015.Google Scholar
- W. Mansky and E. Gunter. A cross-language framework for verifying compiler optimizations. In Proc. of the 5th Workshop on Syntax and Semantics of Low-Level Languages, 2014.Google Scholar
- H. Massalin. Superoptimizer: A look at the smallest program. In Proc. of the 2nd International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS), pages 122–126, 1987. Google ScholarCross Ref
- W. M. McKeeman. Differential testing for software. Digital Technical Journal, 10(1):100–107, Dec. 1998.Google Scholar
- R. Morisset, P. Pawan, and F. Z. Nardelli. Compiler testing via a theory of sound optimisations in the C11/C++11 memory model. In Proc. of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 187–196, 2013. Google ScholarDigital Library
- G. C. Necula. Translation validation for an optimizing compiler. In Proc. of the ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation, pages 83–94, 2000. Google ScholarDigital Library
- A. Pnueli, M. Siegel, and E. Singerman. Translation validation. In Proc. of the 4th International Conference on Tools and Algorithms for Construction and Analysis of Systems, pages 151–166, 1998. Google ScholarDigital Library
- N. Ramsey, J. Dias, and S. P. Jones. Hoopl: A modular, reusable library for dataflow analysis and transformation. In Proc. of the 3rd ACM Symposium on Haskell, 2010. Google ScholarDigital Library
- A. Saabas and T. Uustalu. Program and proof optimizations with type systems. The Journal of Logic and Algebraic Programming, 77(1–2): 131–154, 2008.Google ScholarCross Ref
- H. Samet. Proving the correctness of heuristically optimized code. In Communications of the ACM, 1978. Google ScholarDigital Library
- E. Schkufza, R. Sharma, and A. Aiken. Stochastic superoptimization. In Proc. of the 18th International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS), 2013. Google ScholarDigital Library
- T. A. L. Sewell, M. O. Myreen, and G. Klein. Translation validation for a verified OS kernel. In Proc. of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 471– 482, 2013. Google ScholarDigital Library
- M. Stepp, R. Tate, and S. Lerner. Equality-based translation validator for LLVM. In Proc. of the 23rd International Conference on Computer Aided Verification, pages 737–742, 2011. Google ScholarDigital Library
- R. Tate, M. Stepp, and S. Lerner. Generating compiler optimizations from proofs. In Proc. of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 2010. Google ScholarDigital Library
- J.-B. Tristan, P. Govereau, and G. Morrisett. Evaluating value-graph translation validation for LLVM. In Proc. of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 295–305, 2011. Google ScholarDigital Library
- V. Vafeiadis, T. Balabonski, S. Chakraborty, R. Morisset, and F. Z. Nardelli. Common compiler optimisations are invalid in the C11 memory model and what we can do about it. In Proc. of the 42nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 2015. Google ScholarDigital Library
- D. L. Whitfield and M. L. Soffa. An approach for exploring code improving transformations. ACM Trans. Program. Lang. Syst., 19(6): 1053–1084, Nov. 1997. Google ScholarDigital Library
- X. Yang, Y. Chen, E. Eide, and J. Regehr. Finding and understanding bugs in C compilers. In Proc. of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 283– 294, 2011. Google ScholarDigital Library
- A. Zaks and A. Pnueli. CoVaC: Compiler validation by program analysis of the cross-product. In Proc. of the 15th International Symposium on Formal Methods, pages 35–51, 2008. Google ScholarDigital Library
- J. Zhao, S. Nagarakatte, M. M. Martin, and S. Zdancewic. Formalizing the LLVM intermediate representation for verified program transformations. In Proc. of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 427–440, 2012. Google ScholarDigital Library
- J. Zhao, S. Nagarakatte, M. M. Martin, and S. Zdancewic. Formal verification of SSA-based optimizations for LLVM. In Proc. of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 175–186, 2013. Google ScholarDigital Library
Index Terms
- Provably correct peephole optimizations with alive
Recommendations
Provably correct peephole optimizations with alive
PLDI '15Compilers 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 ...
Termination-checking for LLVM peephole optimizations
ICSE '16: Proceedings of the 38th International Conference on Software EngineeringMainstream compilers contain a large number of peephole optimizations, which perform algebraic simplification of the input program with local rewriting of the code. These optimizations are a persistent source of bugs. Our recent research on Alive, a ...
Alive-Infer: data-driven precondition inference for peephole optimizations in LLVM
PLDI '17Peephole optimizations are a common source of compiler bugs. Compiler developers typically transform an incorrect peephole optimization into a valid one by strengthening the precondition. This process is challenging and tedious. This paper proposes ...
Comments