[PATCH] D37209: [LSR] Fix Shadow IV in case of integer overflow

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 09:46:07 PDT 2017


reames added a comment.

In https://reviews.llvm.org/D37209#854175, @evstupac wrote:

> Hi Max,
>
> I believe, C and C++ standards say that signed integers overflow has undefined behavior.
>  So in your example we can safely change program behavior in case of overflow.
>
> "If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined. [...]"
>  Unsigned case is more complicated.
>
> Thanks,
> Evgeny


Evgeny, what the C and C++ standards say is irrelevant to the semantics of LLVM IR and do not come into the discussion at all.  It does not effect the legality of the transform in any way.

In this particular example, Clang would mark the add as being nsw when generating the IR.  That encodes the semantics you're concerned about.


https://reviews.llvm.org/D37209





More information about the llvm-commits mailing list