From: Vedant Paranjape Date: Mon, 24 Apr 2023 06:20:12 +0000 (+0000) Subject: [IVDescriptors] Add assert to isInductionPhi to check for invalid Phis X-Git-Tag: upstream/17.0.6~10111 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf9b3e55a21368cc10b4db7a83b188ee86430f87;p=platform%2Fupstream%2Fllvm.git [IVDescriptors] Add assert to isInductionPhi to check for invalid Phis Phis that are present inside loop headers can only be Induction Phis legally. This patch adds an assertion to isInductionPhi which checks for the said legality and it also updates the docs of the said function to reflect the given legality. Differential Revision: https://reviews.llvm.org/D149041 --- diff --git a/llvm/include/llvm/Analysis/IVDescriptors.h b/llvm/include/llvm/Analysis/IVDescriptors.h index ad936d2..d8da0b8 100644 --- a/llvm/include/llvm/Analysis/IVDescriptors.h +++ b/llvm/include/llvm/Analysis/IVDescriptors.h @@ -322,7 +322,9 @@ public: /// Returns true if \p Phi is an induction in the loop \p L. If \p Phi is an /// induction, the induction descriptor \p D will contain the data describing - /// this induction. If by some other means the caller has a better SCEV + /// this induction. Since Induction Phis can only be present inside loop + /// headers, the function will assert if it is passed a Phi whose parent is + /// not the loop header. If by some other means the caller has a better SCEV /// expression for \p Phi than the one returned by the ScalarEvolution /// analysis, it can be passed through \p Expr. If the def-use chain /// associated with the phi includes casts (that we know we can ignore diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp index 30cb3ad..3216fad 100644 --- a/llvm/lib/Analysis/IVDescriptors.cpp +++ b/llvm/lib/Analysis/IVDescriptors.cpp @@ -1484,6 +1484,12 @@ bool InductionDescriptor::isInductionPHI( return false; } + // This function assumes that InductionPhi is called only on Phi nodes + // present inside loop headers. Check for the same, and throw an assert if + // the current Phi is not present inside the loop header. + assert(Phi->getParent() == AR->getLoop()->getHeader() + && "Invalid Phi node, not present in loop header"); + Value *StartValue = Phi->getIncomingValueForBlock(AR->getLoop()->getLoopPreheader());