[llvm] [InstCombine] Detect uadd with overflow idiom (PR #140178)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu May 22 10:47:14 PDT 2025


topperc wrote:

> Note that uadd_with_zext_neg_use doesn't have nuw, but it works because it is always given nuw.



> @topperc since you are here:
> 
> m_NUWAdd is not needed in theory, because this will always be nuw. alive2 works without the nuw tag.
> 
> Should I just change it to m_Add, or keep NUWAdd, because any condition that will be tranformed will ALWAYS be nuwadd, well, assuming the rest of the llvm code works properly.

The NUW is definitely needed for multiplication because there is no check in the code that there are enough bits to hold the full product. The code that sets the nuw flag is responsible for that. For add, we only need one extra bit and a zext has to increase the size by at least 1 bit so the NUWAdd probably isn't explicitly needed, but it should always be there since the add will be visited by InstCombine before the icmp.

https://github.com/llvm/llvm-project/pull/140178


More information about the llvm-commits mailing list