On Sat, Jul 21, 2012 at 2:54 AM, Richard Osborne <span dir="ltr"><<a href="mailto:richard@xmos.com" target="_blank" class="cremed">richard@xmos.com</a>></span> wrote:<br><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">



<div style="word-wrap:break-word">
<div>Yes, this is about infinite loops and it isn't me marking the function readonly - its the -functionattrs pass.</div></div></blockquote><div><br></div><div>When I said "you" I merely meant whatever passes you're running. It seems natural that it is the functionattrs pass.</div>
<div> </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"><div> Consider the following example:</div>
<div><br>
</div>
<div>void f() {</div>
<div>  while(1) {}</div>
<div>}</div>
<div><br>
</div>
<div>int main() {</div>
<div>  f();</div>
<div>  return 0;</div>
<div>}</div>
<div><br>
</div>
<div>I'm seeing the following sequence of transforms:</div>
<div><br>
</div>
<div>1) -prune-eh marks f() as noreturn</div>
<div>2) -prune-eh replaces the code after the call to f() in main with unreachable.</div>
<div>2) -functionattrs marks f() as readnone.</div>
<div>3) -early-cse deletes the call to f().</div>
<div><br>
</div>
<div>The net effect is more than just having the loop deleted</div></div></blockquote><div><br></div><div>I actually think the net effect is in essence the same as having the loop deleted. =/ If all we did was delete the loop, 'f()' would contain just an unreachable instruction. Everything past the call to f would still be deleted, and the call would be followed by an unreachable instruction. If you ran the program it would still crash.</div>
<div><br></div><div>Anyways, LLVM, much to my regret, decided to make infinite loops a magical observable side-effect, and not delete them. One of the consequences of this decision is that there is one of two bugs in the current system now:</div>
<div><br></div><div>1) functionattrs shouldn't mark functions with infinite loops as readonly, or</div><div>2) noreturn functions should have the same "observable" property as infinite loops.</div><div><br></div>
<div>As there are many noreturn functions which do not have infinite loops and to which this magical property really shouldn't apply, I strongly prefer #1. It also clarifies the cost of this treatment of infinite loops -- they are implicitly a side-effect carrying construct.</div>
<div><br></div><div>So in essence, I think this is a bug in functionattrs which stems from the decision to not delete infinite loops.</div></div></div>