<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Mar 17, 2013, at 4:51 PM, John McCall <<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">On Mar 16, 2013, at 10:14 AM, Argyrios Kyrtzidis <<a href="mailto:kyrtzidis@apple.com">kyrtzidis@apple.com</a>> wrote:<br><blockquote type="cite">The attached patch adds a check so that, if we flow off the end of a value-returning function, the implicit unreachable will only be emitted if the returning block is empty.<br>For example:<br><br>int baz(int x) {<br>switch (x) {<br>  case 1: return 10;<br>  case 2: return 20;<br>}<br>// implicit unreachable is inserted<br>}<br><br>int baz2(int x) {<br>switch (x) {<br>  case 1: return 10;<br>  case 2: return 20;<br>}<br>foo();<br>// no unreachable<br>}<br><br>As a consequence, functions that have no returns, will not get the implicit unreachable:<br><br>int baz2(int x) {<br>foo();<br>// no unreachable<br>}<br><br><br>I believe this allows taking advantage of the optimization opportunities that the implicit unreachable intended, in a safer manner.<br></blockquote><br>Hmm.  There's a pretty large spectrum of ways in which something could end up with a non-empty return block while still conceptually falling off the end in a way we'd like to optimize.</div></blockquote><div><br></div><div>Could you give some examples ?</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;">We were talking about maybe re-using the same logic that we'd use for -Wreturn-type;</div></blockquote><div><br></div><div>You mean, "don't put implicit unreachable if the warning would be triggered" ?</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"> what's the value in doing this intermediate stage?<br></div></blockquote><div><br></div><div>Compared to "using" -Wreturn-type, I think checking the flowing-off-the-end block is much simpler and:</div><div><br></div><div>-We won't need to start always computing the CFG</div><div>- -Wreturn-type does not seem to fit all the cases that are applicable for the unreachable optimization, for example -Wreturn-type will be triggered for this:</div><div><br></div><div><div>int no_return2(int x) {</div><div>  if (x > 10)</div><div>    return 2;</div><div>  if (x > 0)</div><div>    return 1;</div><div> // assert(0) invisible in release build</div><div>}</div></div><div><br></div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>Also, if we do decide to do this, please don't use empty();  that can lead to us generating semantically different code based on the presence of debug info.  I believe you can instead ask whether getFirstNonPHIOrDbgOrLifetime() returns null.<br></div></blockquote><div><br></div><div>Thanks for letting me know.</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><br>John.<br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></blockquote></div><br></body></html>