[PATCH] D67339: [ConstantRange] add helper function addWithNoWrap

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 12:02:16 PST 2019


nikic added inline comments.


================
Comment at: llvm/trunk/lib/IR/ConstantRange.cpp:834-856
+    bool Overflow;
+    APInt NewMin = LMin.uadd_ov(RMin, Overflow);
+    if (Overflow)
+      return getEmpty();
+    APInt NewMax = LMax.uadd_sat(RMax);
+    return getNonEmpty(std::move(NewMin), std::move(NewMax) + 1);
+  };
----------------
lebedev.ri wrote:
> @nikic @shchenz
> So i'm trying to look into `sub` variant, and i'm missing a subtlety here.
> 
> In `addWithNoSignedWrap()` why those overflow checks are needed?
> All tests pass without them.
> 
> In `addWithNoUnsignedWrap()` why is that overflow check needed?
> All tests pass without it (with it replaced with `uadd_sat`)
`[i8 200, i8 200] add nuw [i8 200, i8 200]` should result in `empty-set` rather than `[i8 255, i8 255]`, this is what the overflow check is for.

Not sure why there is not test failure, I'd expect one of the `EXPECT_TRUE(CR.isEmptySet())` checks to fail.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67339/new/

https://reviews.llvm.org/D67339





More information about the llvm-commits mailing list