diff options
-rw-r--r-- | lib/Support/ConstantRange.cpp | 12 | ||||
-rw-r--r-- | unittests/Support/ConstantRangeTest.cpp | 5 |
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp index 8bab537..d7a57bb 100644 --- a/lib/Support/ConstantRange.cpp +++ b/lib/Support/ConstantRange.cpp @@ -557,13 +557,13 @@ ConstantRange::multiply(const ConstantRange &Other) const { if (isFullSet() || Other.isFullSet()) return ConstantRange(getBitWidth(), /*isFullSet=*/true); - ConstantRange this_zext = zeroExtend(getBitWidth() * 2); - ConstantRange Other_zext = Other.zeroExtend(getBitWidth() * 2); - - ConstantRange Result_zext = ConstantRange( - this_zext.getLower() * Other_zext.getLower(), - ((this_zext.getUpper()-1) * (Other_zext.getUpper()-1)) + 1); + APInt this_min = getUnsignedMin().zext(getBitWidth() * 2); + APInt this_max = getUnsignedMax().zext(getBitWidth() * 2); + APInt Other_min = Other.getUnsignedMin().zext(getBitWidth() * 2); + APInt Other_max = Other.getUnsignedMax().zext(getBitWidth() * 2); + ConstantRange Result_zext = ConstantRange(this_min * Other_min, + this_max * Other_max + 1); return Result_zext.truncate(getBitWidth()); } diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp index cd91a9e..2b073d8 100644 --- a/unittests/Support/ConstantRangeTest.cpp +++ b/unittests/Support/ConstantRangeTest.cpp @@ -275,6 +275,11 @@ TEST_F(ConstantRangeTest, Multiply) { EXPECT_TRUE(Some.multiply(Some).isFullSet()); EXPECT_EQ(Some.multiply(Wrap), Full); EXPECT_EQ(Wrap.multiply(Wrap), Full); + + // http://llvm.org/PR4545 + EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply( + ConstantRange(APInt(4, 6), APInt(4, 2))), + ConstantRange(4, /*isFullSet=*/true)); } TEST_F(ConstantRangeTest, UMax) { |