[PATCH] D66039: [GlobalISel]: Fix a bug in KnownBits where we should have been using SizeInBits
Aditya Nandakumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 16:25:51 PDT 2019
aditya_nandakumar created this revision.
aditya_nandakumar added reviewers: arsenm, volkan, dsanders, aemerson, paquette.
Herald added subscribers: Petar.Avramovic, hiraditya, rovka, wdng.
Herald added a project: LLVM.
We were using getIndexSize instead of getIndexSizeInBits().
Added test case for G_PTRTOINT and G_INTTOPTR.
Repository:
rL LLVM
https://reviews.llvm.org/D66039
Files:
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
Index: llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
===================================================================
--- llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
+++ llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
@@ -24,6 +24,22 @@
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) {
Index: llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
+++ llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
@@ -297,7 +297,7 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66039.214478.patch
Type: text/x-patch
Size: 1770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190809/8eab2c48/attachment.bin>
More information about the llvm-commits
mailing list