[PATCH] D57983: [ConstantRange] Shl of ConstantRanges considers full-set shifting to last bit position
Marcello Maggioni via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 4 19:21:21 PDT 2019
kariddi updated this revision to Diff 193827.
kariddi added a comment.
Hi Nikita, thanks for the review. I updated the patch based on your comment.
Let me know if that's ok for you now.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57983/new/
https://reviews.llvm.org/D57983
Files:
lib/IR/ConstantRange.cpp
unittests/IR/ConstantRangeTest.cpp
Index: unittests/IR/ConstantRangeTest.cpp
===================================================================
--- unittests/IR/ConstantRangeTest.cpp
+++ unittests/IR/ConstantRangeTest.cpp
@@ -704,6 +704,7 @@
}
TEST_F(ConstantRangeTest, Shl) {
+ ConstantRange Some2(APInt(16, 0xfff), APInt(16, 0x8000));
EXPECT_EQ(Full.shl(Full), Full);
EXPECT_EQ(Full.shl(Empty), Empty);
EXPECT_EQ(Full.shl(One), Full); // TODO: [0, (-1 << 0xa) + 1)
@@ -720,6 +721,9 @@
EXPECT_EQ(Some.shl(Some), Full); // TODO: [0xa << 0xa, 0xfc01)
EXPECT_EQ(Some.shl(Wrap), Full); // TODO: [0xa, 0x7ff << 0x5 + 1)
EXPECT_EQ(Wrap.shl(Wrap), Full);
+ EXPECT_EQ(
+ Some2.shl(ConstantRange(APInt(16, 0x1))),
+ ConstantRange(APInt(16, 0xfff << 0x1), APInt(16, 0x7fff << 0x1) + 1));
}
TEST_F(ConstantRangeTest, Lshr) {
Index: lib/IR/ConstantRange.cpp
===================================================================
--- lib/IR/ConstantRange.cpp
+++ lib/IR/ConstantRange.cpp
@@ -1006,8 +1006,12 @@
APInt max = getUnsignedMax();
APInt Other_umax = Other.getUnsignedMax();
+ // If we are shifting by maximum amount of
+ // zero return return the original range.
+ if (Other_umax.isNullValue())
+ return *this;
// there's overflow!
- if (Other_umax.uge(max.countLeadingZeros()))
+ if (Other_umax.ugt(max.countLeadingZeros()))
return getFull();
// FIXME: implement the other tricky cases
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57983.193827.patch
Type: text/x-patch
Size: 1422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190405/f207a44f/attachment.bin>
More information about the llvm-commits
mailing list