diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp index 04a1b68e072..8bab5377952 100644 --- a/lib/Support/ConstantRange.cpp +++ b/lib/Support/ConstantRange.cpp @@ -533,6 +533,8 @@ ConstantRange ConstantRange::add(const ConstantRange &Other) const { if (isEmptySet() || Other.isEmptySet()) return ConstantRange(getBitWidth(), /*isFullSet=*/false); + if (isFullSet() || Other.isFullSet()) + return ConstantRange(getBitWidth(), /*isFullSet=*/true); APInt Spread_X = getSetSize(), Spread_Y = Other.getSetSize(); APInt NewLower = getLower() + Other.getLower(); diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp index 891c209f11c..cd91a9e103c 100644 --- a/unittests/Support/ConstantRangeTest.cpp +++ b/unittests/Support/ConstantRangeTest.cpp @@ -239,6 +239,7 @@ TEST_F(ConstantRangeTest, SubtractAPInt) { TEST_F(ConstantRangeTest, Add) { EXPECT_TRUE(Full.add(APInt(16, 4)).isFullSet()); + EXPECT_EQ(Full.add(Full), Full); EXPECT_EQ(Full.add(Empty), Empty); EXPECT_EQ(Full.add(One), Full); EXPECT_EQ(Full.add(Some), Full);