<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Such an awesome change it was worth saying twice! :)<div><br></div><div>Sounds great, and I completely agree it's a nice enhancement to what we can effectively express to help the compiler optimize more effectively. Thanks for doing this.</div><div><br></div><div>-Jim<br><div><br></div><div><br><div><div>On Mar 11, 2011, at 6:55 PM, John McCall wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">This patch implements the current consensus of PR8973:<div>  <a href="http://llvm.org/bugs/show_bug.cgi?id=8973">http://llvm.org/bugs/show_bug.cgi?id=8973</a>.<div><br></div><div>The macro llvm_unreachable is used in LLVM to indicate that</div><div>a particular place in a function is not supposed to be reachable</div><div>during execution.  Like an assert macro, it takes a string</div><div>argument.  In +Asserts builds, this string argument, together with</div><div>some location information, is passed to a function which prints</div><div>the information and calls abort().  In -Asserts builds, this string</div><div>argument is dropped (to minimize code size impact), and</div><div>instead a bunch of zero arguments are passed to the same</div><div>function.</div><div><br></div><div>The problem is that that's still not very good for code size, as it</div><div>leaves a somewhat bulky function call in the emitted code.  It</div><div>also doesn't let give the compiler any opportunity to optimize</div><div>based on our assertion that the code is unreachable.  A much</div><div>better alternative is to use an intrinsic, provided by Clang and</div><div>GCC 4.5, called __builtin_unreachable;  it has the semantics</div><div>of being undefined behavior if reached, much like LLVM's own</div><div>"unreachable" instruction, which incidentally is what Clang</div><div>generates for it.</div><div><br></div><div>This patch keeps the old behavior of llvm_unreachable in</div><div> +Asserts (!defined(NDEBUG)) builds, but changes the behavior</div><div>in -Asserts builds to call __builtin_unreachable() (in GCC 4.5</div><div>and Clang) or abort() (in everything else).</div></div><div><br></div><div>This is effectively a change in the practical semantics of</div><div>llvm_unreachable:  if the call is actually reachable, then you</div><div>will get some really crazy behavior in -Asserts builds.  If you've</div><div>been using this macro in places that can logically be reached —</div><div>e.g., after you've tested for all the instructions you've actually</div><div>implemented in your backend — then you've been violating the</div><div>spirit of this macro, as communicated by its name, and you</div><div>should change your code to handle unexpected patterns</div><div>more responsibly.</div><div><br></div><div>John.</div><div><br></div><div></div></div><span><unreachable.patch.txt></span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div></div></div>_______________________________________________<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">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></div><br></div></div></body></html>