[llvm] f1f31eb - [unittests] Add a few tests for computeKnownBits with ranges
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 8 11:35:11 PDT 2020
Author: Quentin Colombet
Date: 2020-10-08T11:33:06-07:00
New Revision: f1f31eb2daab3bfc1e6e290f33eb7aea472f0ce5
URL: https://github.com/llvm/llvm-project/commit/f1f31eb2daab3bfc1e6e290f33eb7aea472f0ce5
DIFF: https://github.com/llvm/llvm-project/commit/f1f31eb2daab3bfc1e6e290f33eb7aea472f0ce5.diff
LOG: [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
Added:
Modified:
llvm/unittests/Analysis/ValueTrackingTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 43600ce18575..5a55928ba8e0 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 *>> {
More information about the llvm-commits
mailing list