[PATCH] [BUG] Fix regression in the instruction combiner after r214385

David Majnemer david.majnemer at gmail.com
Fri Aug 22 08:38:27 PDT 2014


Your preservation of `nsw` is wrong for the following case:
  %x i16 = 32768

`sub nsw %x, 32768` will be 0.
`add nsw %x, -32768` will be undef.

Your preservation of `nuw` is wrong for the following case:
  %x i16 = 63488

`sub nuw %x, 8` will be 63480.
`add nuw %x, -8` will be undef.

================
Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:1542-1545
@@ -1541,2 +1541,6 @@
         Res->setHasNoSignedWrap(true);
+    } else {
+      // Preserve nsw/nuw for non-binary operations.
+      Res->setHasNoSignedWrap(I.hasNoSignedWrap());
+      Res->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());
     }
----------------
The following should work better:
  } else {
    const auto *C = cast<Op1>(Constant);
    if (!C->isMinSignedValue() && I.hasNoSignedWrap())
      Res->setHasNoSignedWrap(true);

http://reviews.llvm.org/D5007






More information about the llvm-commits mailing list