aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/ValueTrackingTest.cpp
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2020-10-06 14:34:47 -0700
committerQuentin Colombet <qcolombet@apple.com>2020-10-08 11:33:06 -0700
commitf1f31eb2daab3bfc1e6e290f33eb7aea472f0ce5 (patch)
tree9b729cf3713ed864d6dcab800a7f7d463038d775 /llvm/unittests/Analysis/ValueTrackingTest.cpp
parent504bc07d1afc7bad7b980a977141696ec8298e7e (diff)
downloadllvm-f1f31eb2daab3bfc1e6e290f33eb7aea472f0ce5.zip
llvm-f1f31eb2daab3bfc1e6e290f33eb7aea472f0ce5.tar.gz
llvm-f1f31eb2daab3bfc1e6e290f33eb7aea472f0ce5.tar.bz2
[unittests] Add a few tests for computeKnownBits with ranges
These tests make sure that the range information is properly understood during computeKnownBits analysis. NFC Differential Revision: https://reviews.llvm.org/D88934
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r--llvm/unittests/Analysis/ValueTrackingTest.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 43600ce..5a55928 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -1111,6 +1111,60 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsFreeze) {
EXPECT_EQ(Known.One.getZExtValue(), 0u);
}
+TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAddWithRange) {
+ parseAssembly("define void @test(i64* %p) {\n"
+ " %A = load i64, i64* %p, !range !{i64 64, i64 65536}\n"
+ " %APlus512 = add i64 %A, 512\n"
+ " %c = icmp ugt i64 %APlus512, 523\n"
+ " call void @llvm.assume(i1 %c)\n"
+ " ret void\n"
+ "}\n"
+ "declare void @llvm.assume(i1)\n");
+ AssumptionCache AC(*F);
+ KnownBits Known = computeKnownBits(A, M->getDataLayout(), /* Depth */ 0, &AC,
+ F->front().getTerminator());
+ EXPECT_EQ(Known.Zero.getZExtValue(), ~(65536llu - 1));
+ EXPECT_EQ(Known.One.getZExtValue(), 0u);
+ Instruction &APlus512 = findInstructionByName(F, "APlus512");
+ Known = computeKnownBits(&APlus512, M->getDataLayout(), /* Depth */ 0, &AC,
+ F->front().getTerminator());
+ // We know of one less zero because 512 may have produced a 1 that
+ // got carried all the way to the first trailing zero.
+ EXPECT_EQ(Known.Zero.getZExtValue(), (~(65536llu - 1)) << 1);
+ EXPECT_EQ(Known.One.getZExtValue(), 0u);
+ // The known range is not precise given computeKnownBits works
+ // with the masks of zeros and ones, not the ranges.
+ EXPECT_EQ(Known.getMinValue(), 0u);
+ EXPECT_EQ(Known.getMaxValue(), 131071);
+}
+
+// 512 + [32, 64) doesn't produce overlapping bits.
+// Make sure we get all the individual bits properly.
+TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAddWithRangeNoOverlap) {
+ parseAssembly("define void @test(i64* %p) {\n"
+ " %A = load i64, i64* %p, !range !{i64 32, i64 64}\n"
+ " %APlus512 = add i64 %A, 512\n"
+ " %c = icmp ugt i64 %APlus512, 523\n"
+ " call void @llvm.assume(i1 %c)\n"
+ " ret void\n"
+ "}\n"
+ "declare void @llvm.assume(i1)\n");
+ AssumptionCache AC(*F);
+ KnownBits Known = computeKnownBits(A, M->getDataLayout(), /* Depth */ 0, &AC,
+ F->front().getTerminator());
+ EXPECT_EQ(Known.Zero.getZExtValue(), ~(64llu - 1));
+ EXPECT_EQ(Known.One.getZExtValue(), 32u);
+ Instruction &APlus512 = findInstructionByName(F, "APlus512");
+ Known = computeKnownBits(&APlus512, M->getDataLayout(), /* Depth */ 0, &AC,
+ F->front().getTerminator());
+ EXPECT_EQ(Known.Zero.getZExtValue(), ~512llu & ~(64llu - 1));
+ EXPECT_EQ(Known.One.getZExtValue(), 512u | 32u);
+ // The known range is not precise given computeKnownBits works
+ // with the masks of zeros and ones, not the ranges.
+ EXPECT_EQ(Known.getMinValue(), 544);
+ EXPECT_EQ(Known.getMaxValue(), 575);
+}
+
class IsBytewiseValueTest : public ValueTrackingTest,
public ::testing::WithParamInterface<
std::pair<const char *, const char *>> {