<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 24, 2015 at 5:56 PM, Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> Handling unreachable code is annoying. I agree. However, its important to<br>
> characterize how annoying. Most code is not unreachable, and we're<br>
> (obviously) fine just bailing on such crazy code paths. So in practice the<br>
> common cost is keeping a local set to detect cycles in the graph where we<br>
> aren't expecting them. We are essentially always traversing a linked list<br>
> representing this graph. Because these linked list nodes don't have any<br>
> particular reason to have high locality, we have a cache-hostile traversal<br>
> where we have to do primarily local and cache friendly book-keeping at each<br>
> step to catch duplication. I suspect that this has a very small (but<br>
> non-zero) impact on compile time.<br>
<br>
</span>Why not have an analysis pass that does a DFS starting from the entry<br>
block?  Is that likely to be very costly?  Having an analysis pass is<br>
attractive because that allows some transformation passes to put in<br>
some extra work to preserve it if they so desire.<br>
<br>
The analysis pass does not have to be clever at all, since the<br>
verifier (rightly, I think) considers a block reachable even if it is<br>
predicated on a literal false -- the following IR does not verify:<br>
<br>
define void @f() {<br>
 entry:<br>
  br i1 false, label %t, label %f<br>
<br>
 t:<br>
  ret void<br>
<br>
 f:<br>
  %m = add i32 %m, 1<br>
  ret void<br>
}</blockquote><div><br></div><div>Programmers don't usually write code like this directly, but it is common for it to happen as a result of the expansion of macros or inline functions. You would not want to require that a compiler front end *not* produce this.</div><div><br></div></div></div></div>