<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="">Thanks for the interest, everyone! The intention of this patch was exactly to ignite the discussion, I expected that it should be changed/reworked before going in (if ever).<div class=""><br class=""></div><div class="">The profile I used was not a time profile, it was a frequency-based report, as Sanjay noticed. The idea was to find patterns that are (almost) unused, and that was the patterns I later moved under 'ExpensiveCombines' - I admit it was kind of arbitrary on my side, I kept the ones which looked pretty cheap, and picked the others.</div><div class=""><br class=""></div><div class="">Let me try to keep only the ValueTracking related patterns and remeasure the numbers for now, and then we can decide if we want to do anything about the others. I think it still would be nice to avoid checking for them - maybe we can keep one 'full' InstCombine run for canonicalization, and in subsequent runs only check frequent patterns.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Michael</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Mar 20, 2017, at 9:36 AM, Amara Emerson 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 dir="ltr" class="">Agree, it would be nice if instcombine was more modular, such that we could choose whether or not we wanted a canonicalisation run or wanted optimizations. And of the optimisations, it would also be good to be able to select which categories of combines to run. Splitting out canonicalisation would also make it clearer to all what the standard forms are for certain constructs.<br class=""><br class="">Amara<br class=""><div class=""><br class=""></div><div class=""><br class=""><div class="">On 20 March 2017 at 15:37, Mehdi Amini via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class="">><br class="">><br class="">> On Mar 17, 2017, at 6:12 PM, David Majnemer <<a href="mailto:david.majnemer@gmail.com" class="">david.majnemer@gmail.com</a>> wrote:<br class="">><br class="">> Honestly, I'm not a huge fan of this change as-is. The set of transforms that were added behind ExpensiveChecks seems awfully strange and many would not lead the reader to believe that they are expensive at all (the SimplifyDemandedInstructionBits and foldICmpUsingKnownBits calls being the obvious expensive routines).<br class="">><br class="">> The purpose of many of InstCombine's xforms is to canonicalize the IR to make life easier for downstream passes and analyses.<br class="">><br class="">><br class="">> OK, but is it true of *all* the combines today?<br class="">><br class="">><br class="">> InstCombine internally relies on knowing what transforms it may or may not perform. This is important: canonicalizations may duel endlessly if we get this wrong; the order of the combines is also important for exactly the same reason (SelectionDAG deals with this problem in a different way with its pattern complexity field).<br class="">><br class="">> Another concern with moving seemingly arbitrary combines under ExpensiveCombines is that it will make it that much harder to understand what is and is not canonical at a given point during the execution of the optimizer.<br class="">><br class="">><br class="">> If a canonicalization is too costly to achieve, maybe it is not a reasonable one?<br class="">> It is also not clear to me that canonicalizations that are using complex analyses (ValueTracking / computeKnownBits) are really making it easy to "understand what is canonical” anyway. This is my impression in general as the scope of what is needed to achieve the transformation gets larger: the more context needed the less it looks like a “canonicalization” to me.<br class="">> WDYT?<br class="">><br class="">> — <br class="">> Mehdi<br class="">><br class="">><br class="">><br class="">> I'd be much more interested in a patch which caches the result of frequently called ValueTracking functionality like ComputeKnownBits, ComputeSignBit, etc. which often doesn't change but is not intelligently reused. I imagine that the performance win might be quite comparable. Such a patch would have the benefit of keeping the set of available transforms constant throughout the pipeline while bringing execution time down; I wouldn't be at all surprised if caching the ValueTracking functions resulted in a bigger time savings.<br class="">><br class="">> On Fri, Mar 17, 2017 at 5:49 PM, Hal Finkel via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class="">>><br class="">>><br class="">>> On 03/17/2017 04:30 PM, Mehdi Amini via llvm-dev wrote:<br class="">>><br class="">>><br class="">>> 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:<br class="">>><br class="">>> Hi,<br class="">>><br 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.<br class="">>><br class="">>><br 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 :)<br class="">>><br class="">>><br class="">>> +1<br class="">>><br class="">>> Also, did your profiling reveal why the other combines are expensive? Among other things, I'm curious if the expensive ones tend to spend a lot of time in ValueTracking (getting known bits and similar)?<br class="">>><br class="">>> -Hal<br class="">>><br class="">>><br class="">>><br class="">>> CC: David for the general direction on InstCombine though.<br class="">>><br class="">>><br class="">>> — <br class="">>> Mehdi<br class="">>><br class="">>><br class="">>><br class="">>><br class="">>> Trying to find out, which patterns are important, and which are rare, I profiled clang using CTMark and got the following coverage report:<br class="">>> <InstCombine_covreport.html><br class="">>> (beware, the file is ~6MB).<br class="">>><br 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).<br class="">>><br class="">>> Performance Improvements - Compile Time Δ Previous Current σ <br class="">>> CTMark/sqlite3/sqlite3 -1.55% 6.8155 6.7102 0.0081<br class="">>> CTMark/mafft/pairlocalalign -1.05% 8.0407 7.9559 0.0193<br class="">>> CTMark/ClamAV/clamscan -1.02% 11.3893 11.2734 0.0081<br class="">>> CTMark/lencod/lencod -1.01% 12.8763 12.7461 0.0244<br class="">>> CTMark/SPASS/SPASS -1.01% 12.5048 12.3791 0.0340<br class="">>><br class="">>> Performance Improvements - Compile Time Δ Previous Current σ <br class="">>> External/SPEC/CINT2006/403.gcc/403.gcc -1.64% 54.0801 53.1930 -<br class="">>> External/SPEC/CINT2006/400.perlbench/400.perlbench -1.25% 19.1481 18.9091 -<br class="">>> External/SPEC/CINT2006/445.gobmk/445.gobmk -1.01% 15.2819 15.1274 -<br class="">>><br class="">>><br 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).<br class="">>><br class="">>> The patch is attached for the reference, if we decide to go for it, I'll upload it to phab:<br class="">>><br class="">>> <0001-InstCombine-Move-some-infrequent-patterns-under-if-E.patch><br class="">>><br class="">>><br class="">>> Thanks,<br class="">>> Michael<br class="">>><br 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><br class="">>><br class="">>> _______________________________________________<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="">>><br class="">>><br class="">>><br class="">>><br class="">>> _______________________________________________<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="">>><br class="">>><br class="">>> -- <br class="">>> Hal Finkel<br class="">>> Lead, Compiler Technology and Programming Languages<br class="">>> Leadership Computing Facility<br class="">>> Argonne National Laboratory<br class="">>><br class="">>><br class="">>> _______________________________________________<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="">>><br class="">><br class="">><br class="">><br class="">> _______________________________________________<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="">><br class=""></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="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></div></body></html>