llvm.org GIT mirror llvm / 5ac536e
[ConstantRange] Shl considers full-set shifting to last bit position. if we do SHL of two 16-bit ranges like [0, 30000) with [1,2) we get "full-set" instead of what I would have expected [0, 60000) which is still in the 16-bit unsigned range. This patch changes the SHL algorithm to allow getting a usable range even in this case. Differential Revision: https://reviews.llvm.org/D57983 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357854 91177308-0d34-0410-b5e6-96231b3b80d8 Marcello Maggioni 6 months ago
2 changed file(s) with 11 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
10051005 APInt max = getUnsignedMax();
10061006 APInt Other_umax = Other.getUnsignedMax();
10071007
1008 // If we are shifting by maximum amount of
1009 // zero return return the original range.
1010 if (Other_umax.isNullValue())
1011 return *this;
10081012 // there's overflow!
1009 if (Other_umax.uge(max.countLeadingZeros()))
1013 if (Other_umax.ugt(max.countLeadingZeros()))
10101014 return getFull();
10111015
10121016 // FIXME: implement the other tricky cases
703703 }
704704
705705 TEST_F(ConstantRangeTest, Shl) {
706 ConstantRange Some2(APInt(16, 0xfff), APInt(16, 0x8000));
707 ConstantRange WrapNullMax(APInt(16, 0x1), APInt(16, 0x0));
706708 EXPECT_EQ(Full.shl(Full), Full);
707709 EXPECT_EQ(Full.shl(Empty), Empty);
708710 EXPECT_EQ(Full.shl(One), Full); // TODO: [0, (-1 << 0xa) + 1)
719721 EXPECT_EQ(Some.shl(Some), Full); // TODO: [0xa << 0xa, 0xfc01)
720722 EXPECT_EQ(Some.shl(Wrap), Full); // TODO: [0xa, 0x7ff << 0x5 + 1)
721723 EXPECT_EQ(Wrap.shl(Wrap), Full);
724 EXPECT_EQ(
725 Some2.shl(ConstantRange(APInt(16, 0x1))),
726 ConstantRange(APInt(16, 0xfff << 0x1), APInt(16, 0x7fff << 0x1) + 1));
727 EXPECT_EQ(One.shl(WrapNullMax), Full);
722728 }
723729
724730 TEST_F(ConstantRangeTest, Lshr) {