A Study of Conflicting Pairs of Compiler Optimizations
Yosi Ben Asher, Gadi Haber, Esti Stein · 2017
Modern compilers use dozens of optimizations which are typically applied serially one after the other and at the same order. Theoretically, for a given program, some of these optimizations, and the order in which they areapplied, can degrade the performance or produce suboptimal performance. In this work we formally define the problem of finding an optimized sequence of optimizations (OSO) for a given programbased on information on conflicting pairs of optimizations alone. Previous works studied heuristic search algorithmscovering the space $\cal{S}$ of all possible optimization sequences. These works proposed various heuristic techniques to search $\cal{S}$ by reducing the number of $s\in \cal{S}$that need to be evaluated (compiled and executed). In this work we show, for the first time, an algorithmic solutionto this problem of finding an OSO. We do not search or evaluate sequences $s\in \cal{S}$. Instead, we build a directed conflict graph $G$ witha weighted directed edge $x xt{g} y$ between every pair of optimizations $x,y$ wherein $g$ is the outcomeof applying optimization $y$ after optimization $x$ compared to applying only $x$ or $y$ alone. The optimal OSO is therefore a directed sub-path in $G$ with the maximal sum of triangle weights over all other sub-paths in $G$. The proposed algorithm uses transitive closure steps done by selecting every three edges $x xt{g_i} y,~y xt{g_j} z, x xt{g_k} z$ that form a triangleand contracting them to a new edge $x xt{g'=f(g_i,g_j,g_k)} z$. By selecting the triangle with maximal $g'$ in every step, the algorithm findsthe maximal OSO including repetitions. This technique was implemented in the LLVM compiler and applied to $9$ programs from SPEC 2006. The resulting OSOs obtained and average of $10\%$ improvement in execution time compare to using the $-O3$ optimizations sequence. This is the first algorithmic solution to this problem and the first technique that can handle repetitions of optimizations in thecompilation sequence.