[PATCH] D88934: [unittests] Add a few tests for computeKnownBits with ranges
Quentin Colombet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 8 11:35:25 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf1f31eb2daab: [unittests] Add a few tests for computeKnownBits with ranges (authored by qcolombet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88934/new/
https://reviews.llvm.org/D88934
Files:
llvm/unittests/Analysis/ValueTrackingTest.cpp
Index: llvm/unittests/Analysis/ValueTrackingTest.cpp
===================================================================
--- llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -1111,6 +1111,60 @@
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 *>> {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88934.297023.patch
Type: text/x-patch
Size: 3237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201008/70822669/attachment.bin>
More information about the llvm-commits
mailing list