Superoptimization is the process where a compiler automatically finds the optimal sequence for a loop-free sequence of instructions. Real-world compilers generally cannot produce genuinely optimal code, and while most standard compiler optimizations only improve code partly, a superoptimizer's goal is to find the optimal sequence, the canonical form. Superoptimizers can be used to improve conventional optimizers by highlighting missed opportunities so a human can write additional rules.
History
The term superoptimization was coined by Alexia Massalin in the 1987 paper Superoptimizer: A Look at the Smallest Program.
The label "program optimization" has been given to a field that does not aspire to optimize but only to improve.
This misnomer forced Massalin to call her system a superoptimizer, which is actually an optimizer to find an optimal program.
In 1992, the GNU Superoptimizer (GSO) was developed to integrate into the GNU Compiler Collection (GCC). Later work further developed and extended these ideas.
Techniques
Traditionally, superoptimizing is performed via exhaustive brute-force search in the space of valid instruction sequences. This is a costly method, and largely impractical for general-purpose compilers. Yet, it has been shown to be useful in optimizing performance-critical inner loops. It is also possible to use a SMT solver to approach the problem, vastly improving the search efficiency (although inputs more complex than a basic block remain out of reach).
In 2001, goal-directed superoptimizing was demonstrated in the Denali project by Compaq research. In 2006, answer setdeclarative programming was applied to superoptimization in the Total Optimisation using Answer Set Technology (TOAST) project at the University of Bath.
Superoptimization can be used to automatically generate general-purpose peephole optimizers.
Publicly available superoptimizers
Several superoptimizers are available for free download.
For the x86 family of instruction sets:
GNU superoptimizer (superopt) (GSO) (1992) – also supports many other ISAs
↑Massalin, Henry (1987). "Superoptimizer: A look at the smallest program"(PDF). ACM SIGARCH Computer Architecture News. 15 (5): 122–126. doi:10.1145/36177.36194. Retrieved 2023-05-01. Given an instruction set, the superoptimizer finds the shortest program to compute a function. Startling programs have been generated, many of them engaging in convoluted bit-fiddling bearing little resemblance to the source programs which defined the functions. The key idea in the superoptimizer is a probabilistic test that makes exhaustive searches practical for programs of useful size.
12Granlund, Torbjörn; Kenner, Richard (1992). "Eliminating branches using a superoptimizer and the GNU C compiler". Proceedings of the ACM SIGPLAN 1992 conference on Programming language design and implementation - PLDI '92. CiteSeerX10.1.1.58.3509. doi:10.1145/143095.14314 (inactive 2025-09-07). ISBN978-0-89791475-8. S2CID8825539. {{cite book}}: Cite uses deprecated parameter |citeseerx= (help)CS1 maint: DOI inactive as of September 2025 (link)
12"Index of /gnu/superopt". GNU Operating System. Free Software Foundation, Inc. 1995-06-14. Retrieved 2023-05-01.
12Jangda, Abhinav; Yorsh, Greta (2017-10-25). Unbounded superoptimization. Onward!’17, October 25–27, 2017, Vancouver, Canada. pp.78–88. doi:10.1145/3133850.3133856.
↑"TOAST – KRRwiki". Department of Computer Science, Mathematical Foundations Group. Knowledge Representation and Reasoning (KRR) group. University of Bath. 2007-08-07. Archived from the original on 2012-11-28. Retrieved 2016-09-03.
↑Brain, Martin; Crick, Tom; De Vos, Marina; Fitch, John (2006-08-17). "TOAST: Applying Answer Set Programming to Superoptimisation". In Etalle, Sandro; Truszczyński, Mirosław (eds.). Logic Programming. Lecture Notes in Computer Science. Vol.4079. Springer-Verlag. pp.270–284. doi:10.1007/11799573_21. ISBN978-3-540-36636-2.