<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">In general it is great that we investigate these things! We have been liberally adding pass invocations and patterns for years without checking the compiletime consequences.</div><div class=""><br class=""></div><div class="">However intuitively it feels wrong to disable some patterns completely (there will always be that one program that gets so much better when you have a certain pattern).</div><div class="">- Do you have an idea what would happen if we only disable them in 5 of the 6 invocations?</div><div class="">- Or alternatively what happens when we just not put as many InstCombine instances into the pass pipeline in -Os?</div><div class=""><br class=""></div><div class="">- Matthias</div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 17, 2017, at 2:30 PM, Mehdi Amini via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Mar 17, 2017, at 11:50 AM, Mikhail Zolotukhin via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">Hi,</div><div class=""><br class=""></div><div class="">One of the most time-consuming passes in LLVM middle-end is InstCombine (see e.g. [1]). It is a very powerful pass capable of doing all the crazy stuff, and new patterns are being constantly introduced there. The problem is that we often use it just as a clean-up pass: it's scheduled 6 times in the current pass pipeline, and each time it's invoked it checks all known patterns. It sounds ok for O3, where we try to squeeze as much performance as possible, but it is too excessive for other opt-levels. InstCombine has an ExpensiveCombines parameter to address that - but I think it's underused at the moment.</div></div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Yes, the “ExpensiveCombines” has been added recently (4.0? 3.9?) but I believe has always been intended to be extended the way you’re doing it. So I support this effort :)</div><div class=""><br class=""></div><div class="">CC: David for the general direction on InstCombine though.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">Trying to find out, which patterns are important, and which are rare, I profiled clang using CTMark and got the following coverage report:</div><div class=""></div></div></div></div></div><span id="cid:CEA3012D-A9E2-4318-AA90-C372667C70A9@apple.com" class=""><InstCombine_covreport.html></span><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""></div><div class=""><div class="">(beware, the file is ~6MB).</div></div><div class=""><br class=""></div><div class="">Guided by this profile I moved some patterns under the "if (ExpensiveCombines)" check, which expectedly happened to be neutral for runtime performance, but improved compile-time. The testing results are below (measured for Os).</div><div class=""><br class=""></div><div class=""><table class="" style="font-family: Helvetica, sans-serif; font-size: 9pt; border-spacing: 0px; border: 1px solid black;"><thead class=""><tr class=""><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px; width: 500px;">Performance Improvements - Compile Time</th><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px;">Δ </th><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px;">Previous</th><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px;">Current</th><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px;">σ </th></tr></thead><tbody class="searchable"><tr class=""><td class="benchmark-name" style="padding: 5px 5px 5px 8px;"><a href="http://michaelsmacmini.local/perf/v4/nts/2/graph?test.15=2" class="">CTMark/sqlite3/sqlite3</a></td><td class="" style="padding: 5px 5px 5px 8px; background-color: rgb(200, 255, 200);">-1.55%</td><td class="" style="padding: 5px 5px 5px 8px;">6.8155</td><td class="" style="padding: 5px 5px 5px 8px;">6.7102</td><td class="" style="padding: 5px 5px 5px 8px;">0.0081</td></tr><tr class=""><td class="benchmark-name" style="padding: 5px 5px 5px 8px;"><a href="http://michaelsmacmini.local/perf/v4/nts/2/graph?test.1=2" class="">CTMark/mafft/pairlocalalign</a></td><td class="" style="padding: 5px 5px 5px 8px; background-color: rgb(209, 255, 209);">-1.05%</td><td class="" style="padding: 5px 5px 5px 8px;">8.0407</td><td class="" style="padding: 5px 5px 5px 8px;">7.9559</td><td class="" style="padding: 5px 5px 5px 8px;">0.0193</td></tr><tr class=""><td class="benchmark-name" style="padding: 5px 5px 5px 8px;"><a href="http://michaelsmacmini.local/perf/v4/nts/2/graph?test.7=2" class="">CTMark/ClamAV/clamscan</a></td><td class="" style="padding: 5px 5px 5px 8px; background-color: rgb(210, 255, 210);">-1.02%</td><td class="" style="padding: 5px 5px 5px 8px;">11.3893</td><td class="" style="padding: 5px 5px 5px 8px;">11.2734</td><td class="" style="padding: 5px 5px 5px 8px;">0.0081</td></tr><tr class=""><td class="benchmark-name" style="padding: 5px 5px 5px 8px;"><a href="http://michaelsmacmini.local/perf/v4/nts/2/graph?test.10=2" class="">CTMark/lencod/lencod</a></td><td class="" style="padding: 5px 5px 5px 8px; background-color: rgb(210, 255, 210);">-1.01%</td><td class="" style="padding: 5px 5px 5px 8px;">12.8763</td><td class="" style="padding: 5px 5px 5px 8px;">12.7461</td><td class="" style="padding: 5px 5px 5px 8px;">0.0244</td></tr><tr class=""><td class="benchmark-name" style="padding: 5px 5px 5px 8px;"><a href="http://michaelsmacmini.local/perf/v4/nts/2/graph?test.5=2" class="">CTMark/SPASS/SPASS</a></td><td class="" style="padding: 5px 5px 5px 8px; background-color: rgb(210, 255, 210);">-1.01%</td><td class="" style="padding: 5px 5px 5px 8px;">12.5048</td><td class="" style="padding: 5px 5px 5px 8px;">12.3791</td><td class="" style="padding: 5px 5px 5px 8px;">0.0340</td></tr></tbody></table><div class=""><br class=""></div><table class="" style="font-family: Helvetica, sans-serif; font-size: 9pt; border-spacing: 0px; border: 1px solid black;"><thead class=""><tr class=""><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px; width: 500px;">Performance Improvements - Compile Time</th><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px;">Δ </th><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px;">Previous</th><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px;">Current</th><th class="" style="background-color: rgb(238, 238, 238); color: rgb(102, 102, 102); cursor: default; text-align: center; font-family: Verdana; padding: 5px 5px 5px 8px;">σ </th></tr></thead><tbody class="searchable"><tr class=""><td class="benchmark-name" style="padding: 5px 5px 5px 8px;"><a href="http://michaelsmacmini.local/perf/v4/nts/2/graph?test.14=2" class="">External/SPEC/CINT2006/403.gcc/403.gcc</a></td><td class="" style="padding: 5px 5px 5px 8px; background-color: rgb(199, 255, 199);">-1.64%</td><td class="" style="padding: 5px 5px 5px 8px;">54.0801</td><td class="" style="padding: 5px 5px 5px 8px;">53.1930</td><td class="" style="padding: 5px 5px 5px 8px;">-</td></tr><tr class=""><td class="benchmark-name" style="padding: 5px 5px 5px 8px;"><a href="http://michaelsmacmini.local/perf/v4/nts/2/graph?test.7=2" class="">External/SPEC/CINT2006/400.perlbench/400.perlbench</a></td><td class="" style="padding: 5px 5px 5px 8px; background-color: rgb(205, 255, 205);">-1.25%</td><td class="" style="padding: 5px 5px 5px 8px;">19.1481</td><td class="" style="padding: 5px 5px 5px 8px;">18.9091</td><td class="" style="padding: 5px 5px 5px 8px;">-</td></tr><tr class=""><td class="benchmark-name" style="padding: 5px 5px 5px 8px;"><a href="http://michaelsmacmini.local/perf/v4/nts/2/graph?test.15=2" class="">External/SPEC/CINT2006/445.gobmk/445.gobmk</a></td><td class="" style="padding: 5px 5px 5px 8px; background-color: rgb(210, 255, 210);">-1.01%</td><td class="" style="padding: 5px 5px 5px 8px;">15.2819</td><td class="" style="padding: 5px 5px 5px 8px;">15.1274</td><td class="" style="padding: 5px 5px 5px 8px;">-</td></tr></tbody></table><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Do such changes make sense? The patch doesn't change O3, but it does change Os and potentially can change performance there (though I didn't see any changes in my tests).</div></div><div class=""><br class=""></div><div class="">The patch is attached for the reference, if we decide to go for it, I'll upload it to phab:</div><div class=""><br class=""></div><div class=""></div></div></div></div></div><span id="cid:2A77C0D9-EE12-4C99-99A0-7A0CF5DF758A@apple.com" class=""><0001-InstCombine-Move-some-infrequent-patterns-under-if-E.patch></span><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div dir="auto" class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Michael</div><div class=""><br class=""></div><div class=""><div class="">[1]: <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-December/108279.html" class="">http://lists.llvm.org/pipermail/llvm-dev/2016-December/108279.html</a></div></div><div class=""><br class=""></div></div></div></div></div>_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class=""></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">LLVM Developers mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:llvm-dev@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">llvm-dev@lists.llvm.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div></blockquote></div><br class=""></body></html>