<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 15, 2017 at 11:53 AM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@nondot.org" target="_blank">clattner@nondot.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class="">On Apr 13, 2017, at 8:27 PM, Daniel Berlin via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br><div><blockquote type="cite">Out of 35% InstCombine time, about half is spent in the top 5 visitor routines.<br><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I wanted to see what transformations InstCombine actually performs. Using -debug option turned out not to be very scalable. Never mind the large output size of the trace, running "opt -debug -instcombine”</blockquote><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> on anything other than a small IR is excruciatingly slow. Out of curiosity I profiled it too: 96% of the time is spent decoding and printing instructions. Is this a known problem?</blockquote><div><br></div><div>Yes</div><div><br></div><div>The problem is *every* value print call builds an assembly writer, which  calls the module typefinder to be able to print the types.  This walks everything in the module to find the types.</div><div>For large ir with a lot of types, this is *ridiculously* slow.</div><div><br></div><div>IE it's basically processing a large part of the module for *every operand* it prints.</div><div><br></div><div>You can, for something like what you are doing, just hack it up to build it once or not at all.</div><div><br></div><div>I've never understood why this doesn't annoy people more :)</div><div><br></div><div>As a hack, you can comment out AsmWriter.cpp:2137</div></div></div></div></div></blockquote><br></div></span><div>You can just create a ModuleSlotTracker and pass it back into the print functions.</div></div></blockquote><div>It's not the slot tracker (which does not waste any time, AFAICT), it's the type incorporation of the typeprinter, which walks the entire module, and is getting recreated on every single operator << call.</div><div><br></div><div>But yes, you could create a typeprinter and pass it back in (if typeprinter wasn't internal to AsmWriter.cpp).</div><div> </div><div>But then every operator << you use has to be passed a typeprinter or be super slow. That also seems silly, because most people want to do</div><div><br></div><div>DEBUG(dbgs() << "This instruction: " << *I << " did a thing\n");</div><div><br></div><div>and trying to keep and pass a type printer into all of these, ...</div><div>alternatively, rewriting them also sucks.</div><div><br></div><div>This is in fact, why nobody does it. Because they just want the above to work and not worry about the fact that deep down, we are wasting tremendous amounts of time.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Chris</div><div><br></div><div><br></div><br></font></span></div></blockquote></div><br></div></div>