<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 12, 2015 at 7:30 AM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Mon, Jan 12, 2015 at 4:09 AM, Nicola Gigante <span dir="ltr"><<a href="mailto:nicola.gigante@gmail.com" target="_blank">nicola.gigante@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi all.<br>
<br>
I’ve heard a couple of times that some of the problems solved by various<br>
passes in the optimizer are indeed NP-hard, even though the instances<br>
are small enough to be tractable (and very quickly).<br>
<br>
Is this true?</blockquote></span><div><br>Some are NP-Hard, some are NP-complete.</div><span class=""><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> If so, which are these problems?<br>
Register allocation? Instruction scheduling?<br></blockquote></span><div>Depends on how you define register allocation (IE optimal register coloring, optimal spilling, optimal copy coalescing, optimal dematerialization, etc), but even some of the subtasks are np-complete for normal programs.</div><div><br></div><div>You can also prove that strict SSA programs have some properties that make some of these subtasks *not* NP-complete when taken in isolation, for example, register coloring can be done optimally because strict SSA programs produce chordal graphs, *despite* the fact that register coloring is an NP-complete problem in general.</div><div><br></div><div>But in general, even the simple task of "figuring out the smallest number of registers it takes to color a given register interference graph" is NP-complete </div><div><br></div><div>Scheduling is also full of NP-complete and np-hard problems.</div><div>Even if you restrict scheduling instructions to assume a fixed 2-cycle latency (IE no funky pipeline constraints, etc), it's *still* np hard (see <a href="http://dl.acm.org/citation.cfm?id=155183.155190" target="_blank">http://dl.acm.org/citation.cfm?id=155183.155190</a>)</div><span class=""><div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Are they solved exactly or by approximations?<br></blockquote><div><br></div></span><div>Approximations in some cases, not trying in others (IE not even approximating optimal, or considering optimal in the formulation, but just trying to do something that seems to turn out good in practice. I wouldn't call these approximations since they are not related to solving the NP complete problems, just generating good code).</div><div><br></div><div>The only case i'm aware of using real exact/approximation solutions is PBQP, which solves a subclass of the NP complete problem it attacks in linear time. </div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I believe it uses heuristics to approximate an optimal answer in the rest, but don't quote me on that :)</div></div></div></div></blockquote><div><br>Yep, that's the general idea. Optimal for some simple graphs, domain-specific heuristic for the complex parts.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Or not solved at all (the need of solving them is avoided in some way)?<br></blockquote><div><br></div></span><div>It only avoids them in the sense that it simply ignores optimality as a constraint.</div><div><br></div></div></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>