[PATCH] D89232: [GlobalISel][KnownBits] Early return on out of bound shift amounts
Konstantin Schwarz via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 12 08:39:17 PDT 2020
kschwarz updated this revision to Diff 297603.
kschwarz edited the summary of this revision.
kschwarz added a comment.
Address review comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89232/new/
https://reviews.llvm.org/D89232
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
@@ -725,3 +725,38 @@
EXPECT_EQ(0xffu, KnownUmax.Zero.getZExtValue());
EXPECT_EQ(0xffffffffffffff00, KnownUmax.One.getZExtValue());
}
+
+TEST_F(AArch64GISelMITest, TestInvalidQueries) {
+ StringRef MIRString = R"(
+ %src:_(s32) = COPY $w0
+ %thirty2:_(s32) = G_CONSTANT i32 32
+ %equalSized:_(s32) = G_SHL %src, %thirty2
+ %copy1:_(s32) = COPY %equalSized
+ %thirty3:_(s32) = G_CONSTANT i32 33
+ %biggerSized:_(s32) = G_SHL %src, %thirty3
+ %copy2:_(s32) = COPY %biggerSized
+)";
+ setUp(MIRString);
+ if (!TM)
+ return;
+
+ Register EqSizedCopyReg = Copies[Copies.size() - 2];
+ MachineInstr *EqSizedCopy = MRI->getVRegDef(EqSizedCopyReg);
+ Register EqSizedShl = EqSizedCopy->getOperand(1).getReg();
+
+ Register BiggerSizedCopyReg = Copies[Copies.size() - 1];
+ MachineInstr *BiggerSizedCopy = MRI->getVRegDef(BiggerSizedCopyReg);
+ Register BiggerSizedShl = BiggerSizedCopy->getOperand(1).getReg();
+
+ GISelKnownBits Info(*MF);
+ KnownBits EqSizeRes = Info.getKnownBits(EqSizedShl);
+ KnownBits BiggerSizeRes = Info.getKnownBits(BiggerSizedShl);
+
+
+ // We don't know what the result of the shift is, but we should not crash
+ EXPECT_TRUE(EqSizeRes.One.isNullValue());
+ EXPECT_TRUE(EqSizeRes.Zero.isNullValue());
+
+ EXPECT_TRUE(BiggerSizeRes.One.isNullValue());
+ EXPECT_TRUE(BiggerSizeRes.Zero.isNullValue());
+}
Index: llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
+++ llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
@@ -397,6 +397,10 @@
uint64_t Shift = RHSKnown.getConstant().getZExtValue();
LLVM_DEBUG(dbgs() << '[' << Depth << "] Shift is " << Shift << '\n');
+ // Guard against oversized shift amounts
+ if (Shift >= MRI.getType(MI.getOperand(1).getReg()).getScalarSizeInBits())
+ break;
+
computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
Depth + 1);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89232.297603.patch
Type: text/x-patch
Size: 2240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201012/a1e007c7/attachment.bin>
More information about the llvm-commits
mailing list