[PATCH] Add NSW/NUW flags in InstCombine

Joey Gouly joey.gouly at arm.com
Thu Mar 20 10:16:19 PDT 2014

Sorry about the (really) late reply.

> I have a few points regarding the implementation details of the patch, but
first:  I'm not clear on the benefit.  AFAIK, the nuw/nsw flags just serve
to provide poison values when overflow leads to
> undefined behavior.  If we know these operations won't overflow, why add
the flags?

As far as I know, there is no other flags to denote more specifically that
overflow will not happen - but adding the nuw/nsw flags can help later
passes assume that no overflow will happen in this instruction, otherwise
the results can be undefined.  Adding these flags when creating a new
instruction seems like a good idea, besides WillNotOverflowSignedAdd already
exists in instcombine, so it felt natural to extend this functionality. I am
not sure what you mean by "we know these operations won't overflow". Are you
suggesting that every piece of code that relies on nsw/nuw flags should
duplicate this functionality for checking whether overflow is impossible
instead? (Comment from Georgia, who wrote the patch)

We addressed all the other comments you made!

Updated patch is attached.

Does it look good now? Anyone else got any comments?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: nsw_nuw_updated.diff
Type: text/x-patch
Size: 15563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140320/85fcc70d/attachment.bin>

More information about the llvm-commits mailing list