skip to main content
10.1145/3178372.3179521acmconferencesArticle/Chapter ViewAbstractPublication PagesccConference Proceedingsconference-collections
research-article

Finding missed compiler optimizations by differential testing

Published:24 February 2018Publication History

ABSTRACT

Randomized differential testing of compilers has had great success in finding compiler crashes and silent miscompilations. In this paper we investigate whether we can use similar techniques to improve the quality of the generated code: Can we compare the code generated by different compilers to find optimizations performed by one but missed by another?

We have developed a set of tools for running such tests. We compile C code generated by standard random program generators and use a custom binary analysis tool to compare the output programs. Depending on the optimization of interest, the tool can be configured to compare features such as the number of total instructions, multiply or divide instructions, function calls, stack accesses, and more. A standard test case reduction tool produces minimal examples once an interesting difference has been found.

We have used our tools to compare the code generated by GCC, Clang, and CompCert. We have found previously unreported missing arithmetic optimizations in all three compilers, as well as individual cases of unnecessary register spilling, missed opportunities for register coalescing, dead stores, redundant computations, and missing instruction selection patterns.

References

  1. Antoine Balestrat. 2016. CCG: A random C code generator. Source code repository. (2016). https://github.com/Mrktn/ccgGoogle ScholarGoogle Scholar
  2. Gergö Barany. 2017. Liveness-Driven Random Program Generation. In Pre-proceedings of LOPSTR 2017. https://arxiv.org/abs/1709.04421Google ScholarGoogle Scholar
  3. Dirk Beyer and M. Erkan Keremoglu. 2011. CPAchecker: A Tool for Configurable Software Verification. In Computer Aided Verification -23rd International Conference, CAV. 184–190. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Sandrine Blazy, David Bühler, and Boris Yakobowski. 2017. Structuring Abstract Interpreters Through State and Value Abstractions. In Verification, Model Checking, and Abstract Interpretation (VMCAI).Google ScholarGoogle Scholar
  5. Sebastian Buchwald. 2015. Optgen: A Generator for Local Optimizations. In Compiler Construction: 24th International Conference, CC 2015.Google ScholarGoogle Scholar
  6. Yang Chen and John Regehr. 2010. Comparing Compiler Optimizations. Blog post. (2010). https://blog.regehr.org/archives/320Google ScholarGoogle Scholar
  7. Pascal Cuoq, Benjamin Monate, Anne Pacalet, Virgile Prevosto, John Regehr, Boris Yakobowski, and Xuejun Yang. 2012. Testing static analyzers with randomly generated programs. In Proceedings of the 4th NASA Formal Methods Symposium (NFM 2012). http://www.cs.utah.edu/~regehr/ papers/nfm12.pdf Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Eric Eide and John Regehr. 2008. Volatiles Are Miscompiled, and What to Do About It. In Proceedings of the 8th ACM International Conference on Embedded Software (EMSOFT ’08). 255–264. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Lal George and Andrew W. Appel. 1996. Iterated Register Coalescing. In POPL ’96. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Atsushi Hashimoto and Nagisa Ishiura. 2016. Detecting Arithmetic Optimization Opportunities for C Compilers by Randomly Generated Equivalent Programs. IPSJ Transactions on System LSI Design Methodology 9 (2016), 21–29.Google ScholarGoogle ScholarCross RefCross Ref
  11. Mitsuyoshi Iwatsuji, Atsushi Hashimoto, and Nagisa Ishiura. 2016. Detecting Missed Arithmetic Optimization in C Compilers by Differential Random Testing. In The 20th Workshop on Synthesis And System Integration of Mixed Information technologies (SASIMI 2016). http://ist.ksc.kwansei.ac. jp/~ishiura/publications/C2016-10a.pdfGoogle ScholarGoogle Scholar
  12. Florent Kirchner, Nikolai Kosmatov, Virgile Prevosto, Julien Signoles, and Boris Yakobowski. 2015. Frama-C: A software analysis perspective. Formal Aspects of Computing 27, 3 (2015), 573–609. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Christopher Lidbury, Andrei Lascu, Nathan Chong, and Alastair F. Donaldson. 2015. Many-core Compiler Fuzzing. In Proceedings of PLDI ’15. 65–76. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Henry Massalin. 1987. Superoptimizer: A Look at the Smallest Program. In Proceedings of ASPLOS II. 122–126. Google ScholarGoogle ScholarCross RefCross Ref
  15. William M. McKeeman. 1998. Differential Testing for Software. Digital Technical Journal 10, 1 (1998). http://www.cs.dartmouth.edu/~mckeeman/ references/DifferentialTestingForSoftware.pdfGoogle ScholarGoogle Scholar
  16. Jan Midtgaard, Mathias Nygaard Justesen, Patrick Kasting, Flemming Nielson, and Hanne Riis Nielson. 2017. Effect-driven QuickChecking of Compilers. Proc. ACM Program. Lang. 1, ICFP, Article 15 (Aug. 2017). Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Tipp Moseley, Dirk Grunwald, and Ramesh Peri. 2009a. Chainsaw: Using Binary Matching for Relative Instruction Mix Comparison. In PACT 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Tipp Moseley, Dirk Grunwald, and Ramesh Peri. 2009b. OptiScope: Performance Accountability for Optimizing Compilers. In Proceedings of CGO ’09. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Eriko Nagai, Atsushi Hashimoto, and Nagisa Ishiura. 2014. Reinforcing Random Testing of Arithmetic Optimization of C Compilers by Scaling up Size and Number of Expressions. IPSJ Transactions on System LSI Design Methodology 7 (2014), 91–100.Google ScholarGoogle ScholarCross RefCross Ref
  20. Phitchaya Mangpo Phothilimthana, Aditya Thakur, Rastislav Bodik, and Dinakar Dhurjati. 2016. Scaling Up Superoptimization. In Proceedings of ASPLOS ’16. 297–310. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. John Regehr, Yang Chen, Pascal Cuoq, Eric Eide, Chucky Ellison, and Xuejun Yang. 2012. Test-case Reduction for C Compiler Bugs. In PLDI ’12. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Jesse Ruderman. 2015. jsfunfuzz. Source code repository. (2015). https: //github.com/MozillaSecurity/funfuzz/tree/master/js/jsfunfuzzGoogle ScholarGoogle Scholar
  23. Raimondas Sasnauskas, Yang Chen, Peter Collingbourne, Jeroen Ketema, Jubi Taneja, and John Regehr. 2017. Souper: A Synthesizing Superoptimizer. CoRR abs/1711.04422 (2017). arXiv: 1711.04422 http://arxiv.org/ abs/1711.04422Google ScholarGoogle Scholar
  24. Yan Shoshitaishvili, Ruoyu Wang, Christopher Salls, Nick Stephens, Mario Polino, Andrew Dutcher, John Grosen, Siji Feng, Christophe Hauser, Christopher Kruegel, and Giovanni Vigna. 2016. SoK: (State of ) The Art of War: Offensive Techniques in Binary Analysis. In IEEE Symposium on Security and Privacy.Google ScholarGoogle ScholarCross RefCross Ref
  25. Chengnian Sun, Vu Le, Qirun Zhang, and Zhendong Su. 2016. Toward Understanding Compiler Bugs in GCC and LLVM. In ISSTA 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Tao Wei, Jian Mao, Wei Zou, and Yu Chen. 2007. A New Algorithm for Identifying Loops in Decompilation. In SAS’07. http://dl.acm.org/citation. cfm?id=2391451.2391464 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Xuejun Yang, Yang Chen, Eric Eide, and John Regehr. 2011. Finding and Understanding Bugs in C Compilers. In Proceedings of PLDI ’11. 283–294. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Finding missed compiler optimizations by differential testing

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in
        • Published in

          cover image ACM Conferences
          CC 2018: Proceedings of the 27th International Conference on Compiler Construction
          February 2018
          206 pages
          ISBN:9781450356442
          DOI:10.1145/3178372

          Copyright © 2018 ACM

          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 the author(s) 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].

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 24 February 2018

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader