[PATCH] D88934: [unittests] Add a few tests for computeKnownBits with ranges

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 16:11:14 PDT 2020


qcolombet created this revision.
qcolombet added reviewers: nikic, fhahn, aqjune, spatel, lebedev.ri, RKSimon, efriedma.
Herald added a project: LLVM.
qcolombet requested review of this revision.

These tests make sure that the range information is properly
understood during computeKnownBits analysis.

NFC


Repository:
  rG LLVM Github Monorepo

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,52 @@
   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);
+}
+
+// 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);
+}
+
 class IsBytewiseValueTest : public ValueTrackingTest,
                             public ::testing::WithParamInterface<
                                 std::pair<const char *, const char *>> {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88934.296560.patch
Type: text/x-patch
Size: 2831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201006/9b70adae/attachment.bin>


More information about the llvm-commits mailing list