skip to main content
10.1145/2737924.2737965acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
research-article

Provably correct peephole optimizations with alive

Published: 03 June 2015 Publication History

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.

References

[1]
W. Ackermann. Solvable Cases of the Decision Problem. Studies in Logic and the Foundations of Mathematics, 1954.
[2]
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.
[3]
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.
[4]
S. Buchwald. Optgen: A generator for local optimizations. In Proc. of the 24th International Conference on Compiler Construction (CC), pages 171–189, Apr. 2015.
[5]
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.
[6]
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.
[7]
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.
[8]
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.
[9]
S. Guyer and C. Lin. Broadway: A compiler for exploiting the domainspecific semantics of software libraries. Proceedings of the IEEE, 93 (2), 2005.
[10]
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.
[11]
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.
[12]
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.
[13]
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.
[14]
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.
[15]
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.
[16]
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.
[17]
X. Leroy. Formal verification of a realistic compiler. Communications of the ACM, 52(7):107–115, 2009.
[18]
LLVM Developers. LLVM Language Reference Manual. Available from http://llvm.org/docs/LangRef.html, 2014.
[19]
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.
[20]
N. P. Lopes and J. Monteiro. Automatic equivalence checking of programs with uninterpreted functions and integer arithmetic. Int. J. Softw. Tools Technol. Transf., 2015.
[21]
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.
[22]
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.
[23]
W. M. McKeeman. Differential testing for software. Digital Technical Journal, 10(1):100–107, Dec. 1998.
[24]
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.
[25]
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.
[26]
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.
[27]
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.
[28]
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.
[29]
H. Samet. Proving the correctness of heuristically optimized code. In Communications of the ACM, 1978.
[30]
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.
[31]
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.
[32]
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.
[33]
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.
[34]
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.
[35]
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.
[36]
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.
[37]
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.
[38]
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.
[39]
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.
[40]
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.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
PLDI '15: Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation
June 2015
630 pages
ISBN:9781450334686
DOI:10.1145/2737924
  • cover image ACM SIGPLAN Notices
    ACM SIGPLAN Notices  Volume 50, Issue 6
    PLDI '15
    June 2015
    630 pages
    ISSN:0362-1340
    EISSN:1558-1160
    DOI:10.1145/2813885
    • Editor:
    • Andy Gill
    Issue’s Table of Contents
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 03 June 2015

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Alive
  2. Compiler Verification
  3. Peephole Optimization

Qualifiers

  • Research-article

Conference

PLDI '15
Sponsor:

Acceptance Rates

Overall Acceptance Rate 406 of 2,067 submissions, 20%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)145
  • Downloads (Last 6 weeks)13
Reflects downloads up to 24 Dec 2024

Other Metrics

Citations

Cited By

View all

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media