[PATCH] D129653: isInductionPHI - Add some safety checks
Zaara Syeda via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 13 08:46:16 PDT 2022
syzaara created this revision.
syzaara added reviewers: nickdesaulniers, Meinersbur, LoopOptWG.
Herald added a subscriber: hiraditya.
Herald added a project: All.
syzaara requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This adds some safety checks into isInductionPHI so that users calling isInductionPHI do not need to do their own checks before calling the function.
https://reviews.llvm.org/D129653
Files:
llvm/lib/Analysis/IVDescriptors.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
Index: llvm/lib/Transforms/Utils/LoopUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1243,20 +1243,6 @@
return true;
}
-/// Checks if it is safe to call InductionDescriptor::isInductionPHI for \p Phi,
-/// and returns true if this Phi is an induction phi in the loop. When
-/// isInductionPHI returns true, \p ID will be also be set by isInductionPHI.
-static bool checkIsIndPhi(PHINode *Phi, Loop *L, ScalarEvolution *SE,
- InductionDescriptor &ID) {
- if (!Phi)
- return false;
- if (!L->getLoopPreheader())
- return false;
- if (Phi->getParent() != L->getHeader())
- return false;
- return InductionDescriptor::isInductionPHI(Phi, L, SE, ID);
-}
-
int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI,
ScalarEvolution *SE,
const TargetTransformInfo *TTI,
@@ -1317,7 +1303,7 @@
InductionDescriptor ID;
PHINode *IndPhi = dyn_cast<PHINode>(Inst);
if (IndPhi) {
- if (!checkIsIndPhi(IndPhi, L, SE, ID))
+ if (!InductionDescriptor::isInductionPHI(IndPhi, L, SE, ID))
continue;
// This is an induction PHI. Check that the only users are PHI
// nodes, and induction variable update binary operators.
@@ -1338,7 +1324,7 @@
continue;
if (llvm::any_of(Inst->users(), [&](User *U) {
PHINode *Phi = dyn_cast<PHINode>(U);
- if (Phi != PN && !checkIsIndPhi(Phi, L, SE, ID))
+ if (Phi != PN && !InductionDescriptor::isInductionPHI(Phi, L, SE, ID))
return true;
return false;
}))
Index: llvm/lib/Analysis/IVDescriptors.cpp
===================================================================
--- llvm/lib/Analysis/IVDescriptors.cpp
+++ llvm/lib/Analysis/IVDescriptors.cpp
@@ -1505,6 +1505,13 @@
PHINode *Phi, const Loop *TheLoop, ScalarEvolution *SE,
InductionDescriptor &D, const SCEV *Expr,
SmallVectorImpl<Instruction *> *CastsToIgnore) {
+
+ if (!Phi)
+ return false;
+
+ if (TheLoop->getHeader() != Phi->getParent())
+ return false;
+
Type *PhiTy = Phi->getType();
// We only handle integer and pointer inductions variables.
if (!PhiTy->isIntegerTy() && !PhiTy->isPointerTy())
@@ -1527,6 +1534,8 @@
return false;
}
+ if (!(AR->getLoop()->getLoopPreheader()))
+ return false;
Value *StartValue =
Phi->getIncomingValueForBlock(AR->getLoop()->getLoopPreheader());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129653.444282.patch
Type: text/x-patch
Size: 2704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220713/0b27c8ad/attachment.bin>
More information about the llvm-commits
mailing list