<div dir="ltr"><div>If you do it on literally every two entry phi nodes, why is the answer not:<div><br></div><div>Number each node of dominator tree with depth in dom tree (IE level). <br></div><div>Process dominator tree in level order, visiting all nodes of a given level before the next deeper level:</div><div>  Try to speculate a given phi node.</div><div>  Stop anytime you hit a phi node with a level above you above you (because you will have already speculated it if you could).</div><div>  Track visited phi nodes to avoid cycles.</div><div><br></div><div><br></div><div>Or something similar.</div><div>Over time, we seem to expand a lot of lazy-walking optimizations to do these "walk possibly everything backwards" types of algorithms, and at the point we want to walk *everything of a certain type* there is no point in doing it lazily.</div><div><br></div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 27, 2016 at 10:32 AM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">majnemer added a comment.<br>
<span class=""><br>
In <a href="http://reviews.llvm.org/D16637#337461" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16637#337461</a>, @dberlin wrote:<br>
<br>
> Errr, rather than limit recursion depth, why not just keep track of what's<br>
>  visited and avoid the cycles?<br>
><br>
> (You could also cheaply build sccs of the instruction and it's uses, and<br>
>  decide what to do for each SCC as a whole, which would avoid this issue as<br>
>  well)<br>
<br>
<br>
</span>We run DominatesMergePoint on every two entry phi node.  Using a set of visited blocks would still be pretty expensive because, in the worst case, DominatesMergePoint might recurse back to the entry node if there are a lot of cheap BBs.  I think it would make sense to have a depth limit to handle such pathological cases.<br>
<br>
<br>
<a href="http://reviews.llvm.org/D16637" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16637</a><br>
<br>
<br>
<br>
</blockquote></div><br></div></div></div></div>