[PATCH] D112980: [LoopInfo] Fix a bug in the function getInductionVariable
duanbo via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 1 19:46:48 PDT 2021
duan.db created this revision.
duan.db added reviewers: kiranchandramohan, fhahn, Whitney.
Herald added a subscriber: hiraditya.
duan.db requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
There is a bug in getInductionVariable. From code, the way this function gets the induction variable is by judging whether StepInst or IndVar in the phi statement is one of the operands of CMP. It will perform dyn_cast operations. But if the LatchCmpOp0/LatchCmpOp1 is a constant, it will be cast to null. The same situation exists when getting the Stepinst, the subsequent comparison may result in null == null, which is meaningless. The induction variable will be the first phi of the loop, and this does not match the logic of this function.
https://reviews.llvm.org/D112980
Files:
llvm/lib/Analysis/LoopInfo.cpp
Index: llvm/lib/Analysis/LoopInfo.cpp
===================================================================
--- llvm/lib/Analysis/LoopInfo.cpp
+++ llvm/lib/Analysis/LoopInfo.cpp
@@ -301,15 +301,16 @@
if (!CmpInst)
return nullptr;
- Instruction *LatchCmpOp0 = dyn_cast<Instruction>(CmpInst->getOperand(0));
- Instruction *LatchCmpOp1 = dyn_cast<Instruction>(CmpInst->getOperand(1));
+ Value *LatchCmpOp0 = CmpInst->getOperand(0);
+ Value *LatchCmpOp0 = CmpInst->getOperand(1);
for (PHINode &IndVar : Header->phis()) {
InductionDescriptor IndDesc;
if (!InductionDescriptor::isInductionPHI(&IndVar, this, &SE, IndDesc))
continue;
- Instruction *StepInst = IndDesc.getInductionBinOp();
+ BasicBlock *Latch = this->getLoopLatch();
+ Value *StepInst = IndVar.getIncomingValueForBlock(Latch);
// case 1:
// IndVar = phi[{InitialValue, preheader}, {StepInst, latch}]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112980.383948.patch
Type: text/x-patch
Size: 916 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211102/f7aa35aa/attachment-0001.bin>
More information about the llvm-commits
mailing list