[llvm] Handle GEPs with negative offset and 'nuw' attribute (PR #117147)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 04:56:25 PST 2024


================
@@ -4363,10 +4363,15 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) {
         // In an inbounds GEP with an offset that is nonnegative even when
         // interpreted as signed, assume there is no unsigned overflow.
         SDNodeFlags Flags;
-        if (NW.hasNoUnsignedWrap() ||
-            (Offs.isNonNegative() && NW.hasNoUnsignedSignedWrap()))
+        if (NW.hasNoUnsignedWrap()) {
+          if (!Offs.isNonNegative() && NW.hasNoUnsignedSignedWrap()) {
+            Flags.setNoUnsignedWrap(false);
+          } else {
+            Flags.setNoUnsignedWrap(true);
+          }
----------------
RKSimon wrote:

Merge this if-else into:
`Flags.setNoUnsignedWrap(Offs.isNonNegative() || !NW.hasNoUnsignedSignedWrap()` ?

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


More information about the llvm-commits mailing list