[llvm-dev] Is trapping allowed when an add with nsw flag overflows?

David Majnemer via llvm-dev llvm-dev at lists.llvm.org
Fri Apr 15 10:42:21 PDT 2016

On Fri, Apr 15, 2016 at 10:28 AM, Manuel Jacob via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
> In our backend, we currently emit add operations that trap on overflow if
> the IR operation has the nsw flag set.  Is this allowed?

No.  Operations like `add nsw` can be hoisted around control dependencies
and unconditionally executed.

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.

> 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?
> -Manuel
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160415/8e50c324/attachment.html>

More information about the llvm-dev mailing list