<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 15, 2016 at 10:28 AM, Manuel Jacob via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
In our backend, we currently emit add operations that trap on overflow if the IR operation has the nsw flag set.  Is this allowed?<br></blockquote><div><br></div><div>No.  Operations like `add nsw` can be hoisted around control dependencies and unconditionally executed.</div><div><br></div><div>The only information that flag yields is that downstream users of the instruction don't need to worry about the instruction producing a result which results in wrapping when taking it's operands into account.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
According to the documentation about poison values, overflowing a nsw add is undefined behavior.  However I didn't find a formal definition of undefined behavior in LLVM.  Judging from previous discussions on the mailing list, there seems to be a vague line of what LLVM is allowed to do in case of undefined behavior.  Is trapping allowed?<br>
<br>
-Manuel<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div></div>