[llvm] r368618 - [GISel]: Fix a bug in KnownBits where we should have been using SizeInBits

Aditya Nandakumar via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 12 14:28:12 PDT 2019


Author: aditya_nandakumar
Date: Mon Aug 12 14:28:12 2019
New Revision: 368618

URL: http://llvm.org/viewvc/llvm-project?rev=368618&view=rev
Log:
[GISel]: Fix a bug in KnownBits where we should have been using SizeInBits

https://reviews.llvm.org/D66039

We were using getIndexSize instead of getIndexSizeInBits().
Added test case for G_PTRTOINT and G_INTTOPTR.

Modified:
    llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
    llvm/trunk/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp

Modified: llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp?rev=368618&r1=368617&r2=368618&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/GISelKnownBits.cpp Mon Aug 12 14:28:12 2019
@@ -297,7 +297,7 @@ void GISelKnownBits::computeKnownBitsImp
     Register SrcReg = MI.getOperand(1).getReg();
     LLT SrcTy = MRI.getType(SrcReg);
     unsigned SrcBitWidth = SrcTy.isPointer()
-                               ? DL.getIndexSize(SrcTy.getAddressSpace())
+                               ? DL.getIndexSizeInBits(SrcTy.getAddressSpace())
                                : SrcTy.getSizeInBits();
     assert(SrcBitWidth && "SrcBitWidth can't be zero");
     Known = Known.zextOrTrunc(SrcBitWidth, true);

Modified: llvm/trunk/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp?rev=368618&r1=368617&r2=368618&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp Mon Aug 12 14:28:12 2019
@@ -24,6 +24,22 @@ TEST_F(GISelMITest, TestKnownBitsCst) {
   EXPECT_EQ((uint64_t)1, Res.One.getZExtValue());
   EXPECT_EQ((uint64_t)0xfe, Res.Zero.getZExtValue());
 }
+TEST_F(GISelMITest, TestKnownBitsPtrToIntViceVersa) {
+  StringRef MIRString = "  %3:_(s16) = G_CONSTANT i16 256\n"
+                        "  %4:_(p0) = G_INTTOPTR %3\n"
+                        "  %5:_(s32) = G_PTRTOINT %4\n"
+                        "  %6:_(s32) = COPY %5\n";
+  setUp(MIRString);
+  if (!TM)
+    return;
+  unsigned CopyReg = Copies[Copies.size() - 1];
+  MachineInstr *FinalCopy = MRI->getVRegDef(CopyReg);
+  unsigned SrcReg = FinalCopy->getOperand(1).getReg();
+  GISelKnownBits Info(*MF);
+  KnownBits Res = Info.getKnownBits(SrcReg);
+  EXPECT_EQ(256u, Res.One.getZExtValue());
+  EXPECT_EQ(0xfffffeffu, Res.Zero.getZExtValue());
+}
 
 TEST_F(GISelMITest, TestKnownBits) {
 




More information about the llvm-commits mailing list