Author: Benjamin Maxwell Date: 2026-09-14T10:36:55+01:00 New Revision: 4de15cd926f2497fb2d5eb7271d7099df19dcb52
URL: https://github.com/llvm/llvm-project/commit/4de15cd926f2497fb2d5eb7271d7099df19dcb52 DIFF: https://github.com/llvm/llvm-project/commit/4de15cd926f2497fb2d5eb7271d7099df19dcb52.diff LOG: Revert "[IVDescriptors] Address MonotonicDescriptor post-commit comments (NFC…" This reverts commit 860d945db8787845349096521157eabf09be81cb. Added: Modified: llvm/include/llvm/Analysis/IVDescriptors.h llvm/lib/Analysis/IVDescriptors.cpp llvm/unittests/Analysis/IVDescriptorsTest.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/Analysis/IVDescriptors.h b/llvm/include/llvm/Analysis/IVDescriptors.h index 16e955ddf1cd6..7748917ae1868 100644 --- a/llvm/include/llvm/Analysis/IVDescriptors.h +++ b/llvm/include/llvm/Analysis/IVDescriptors.h @@ -30,7 +30,6 @@ class ScalarEvolution; class SCEV; class SCEVPredicate; class StoreInst; -enum class SCEVNoWrapFlags; /// These are the kinds of recurrences that we support. enum class RecurKind { @@ -492,7 +491,7 @@ class MonotonicDescriptor { MonotonicDescriptor() = default; /// Returns true if \p PN is a monotonic variable in the loop \p L. If \p PN - /// is monotonic, the monotonic descriptor \p Desc will contain the data + /// is monotonic, the monotonic descriptor \p D will contain the data /// describing the PHI. LLVM_ABI static bool isMonotonicPHI(PHINode *PN, const Loop *L, MonotonicDescriptor &Desc, @@ -516,12 +515,12 @@ class MonotonicDescriptor { const SCEV *getStepSCEV() const { return StepSCEV; } /// Returns the SCEV no-wrap flags that apply to StepInst. - SCEVNoWrapFlags getSCEVNoWrapFlags() const { return SCEVNoWrapFlags; } + unsigned getSCEVNoWrapFlags() const { return SCEVNoWrapFlags; } private: MonotonicDescriptor(PHINode *HeaderPHI, PHINode *BackedgePHI, Instruction *StepInst, const SCEV *StartSCEV, - const SCEV *StepSCEV, SCEVNoWrapFlags SCEVNoWrapFlags) + const SCEV *StepSCEV, unsigned SCEVNoWrapFlags) : HeaderPHI(HeaderPHI), BackedgePHI(BackedgePHI), StepInst(StepInst), StartSCEV(StartSCEV), StepSCEV(StepSCEV), SCEVNoWrapFlags(SCEVNoWrapFlags) {} @@ -542,7 +541,7 @@ class MonotonicDescriptor { const SCEV *StepSCEV = nullptr; /// The SCEV no-wrap flags that apply to StepInst. - SCEVNoWrapFlags SCEVNoWrapFlags{}; + unsigned SCEVNoWrapFlags = 0; }; } // end namespace llvm diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp index d9e9fabcebb77..040cabd58a53f 100644 --- a/llvm/lib/Analysis/IVDescriptors.cpp +++ b/llvm/lib/Analysis/IVDescriptors.cpp @@ -1709,7 +1709,7 @@ bool InductionDescriptor::isInductionPHI( // latch: // %latch_phi = phi [ %monotonic_phi, %loop_header ], [ %step, %step_bb ] // br label %loop_header -bool MonotonicDescriptor::isMonotonicPHI(PHINode *PN, const Loop *L, +bool MonotonicDescriptor::isMonotonicPHI(PHINode *HeaderPHI, const Loop *L, MonotonicDescriptor &Desc, ScalarEvolution &SE) { BasicBlock *Preheader = L->getLoopPreheader(); @@ -1717,29 +1717,30 @@ bool MonotonicDescriptor::isMonotonicPHI(PHINode *PN, const Loop *L, return false; BasicBlock *Latch = L->getLoopLatch(); - if (!Latch || !PN->getType()->isIntOrPtrTy() || - PN->getParent() != L->getHeader()) + if (!Latch || !HeaderPHI->getType()->isIntOrPtrTy() || + HeaderPHI->getParent() != L->getHeader()) return false; - auto *BackedgePHI = dyn_cast<PHINode>(PN->getIncomingValueForBlock(Latch)); + auto *BackedgePHI = + dyn_cast<PHINode>(HeaderPHI->getIncomingValueForBlock(Latch)); if (!BackedgePHI) return false; // Ensure the only users of the backedge PHI are outside the loop or the - // header PHI (PN). + // header PHI. for (User *U : BackedgePHI->users()) { auto *UI = cast<Instruction>(U); - if (UI != PN && L->contains(UI)) + if (UI != HeaderPHI && L->contains(UI)) return false; } // Find the step operation used to increment the value of the monotonic PHI. // TODO: Support chains of PHIs. - Value *StepOp = - find_singleton<Value>(BackedgePHI->incoming_values(), - [&](Use &Incoming, bool /*AllowRepeats*/) { - return Incoming != PN ? Incoming.get() : nullptr; - }); + Value *StepOp = find_singleton<Value>( + BackedgePHI->incoming_values(), + [&](Use &Incoming, bool /*AllowRepeats*/) { + return Incoming != HeaderPHI ? Incoming.get() : nullptr; + }); if (!StepOp || !StepOp->hasOneUse()) return false; @@ -1749,20 +1750,20 @@ bool MonotonicDescriptor::isMonotonicPHI(PHINode *PN, const Loop *L, Value *Step = nullptr; bool StepMatch = - PN->getType()->isPointerTy() - ? match(StepInst, m_PtrAdd(m_Specific(PN), m_Value(Step))) - : match(StepInst, m_c_Add(m_Specific(PN), m_Value(Step))); + HeaderPHI->getType()->isPointerTy() + ? match(StepInst, m_PtrAdd(m_Specific(HeaderPHI), m_Value(Step))) + : match(StepInst, m_c_Add(m_Specific(HeaderPHI), m_Value(Step))); if (!StepMatch || !L->isLoopInvariant(Step)) return false; // Ensure GEP offsets are extended to the size of the PHI. const SCEV *StepSCEV = SE.getTruncateOrSignExtend( - SE.getSCEV(Step), SE.getEffectiveSCEVType(PN->getType())); + SE.getSCEV(Step), SE.getEffectiveSCEVType(HeaderPHI->getType())); if (StepSCEV->isZero()) return false; - Value *Start = PN->getIncomingValueForBlock(Preheader); + Value *Start = HeaderPHI->getIncomingValueForBlock(Preheader); const SCEV *StartSCEV = SE.getSCEV(Start); SCEV::NoWrapFlags NoWrapFlags = SCEV::FlagAnyWrap; @@ -1779,10 +1780,10 @@ bool MonotonicDescriptor::isMonotonicPHI(PHINode *PN, const Loop *L, NoWrapFlags = ScalarEvolution::setFlags(NoWrapFlags, SCEV::FlagNSW); } - LLVM_DEBUG(dbgs() << "LV: Found a monotonic phi: HeaderPHI: " << *PN + LLVM_DEBUG(dbgs() << "LV: Found a monotonic phi: HeaderPHI: " << *HeaderPHI << ", StepInst: " << *StepInst << "\n"); - Desc = MonotonicDescriptor(PN, BackedgePHI, StepInst, StartSCEV, StepSCEV, - NoWrapFlags); + Desc = MonotonicDescriptor(HeaderPHI, BackedgePHI, StepInst, StartSCEV, + StepSCEV, to_underlying(NoWrapFlags)); return true; } diff --git a/llvm/unittests/Analysis/IVDescriptorsTest.cpp b/llvm/unittests/Analysis/IVDescriptorsTest.cpp index 6b09354df8ced..07677ee49c677 100644 --- a/llvm/unittests/Analysis/IVDescriptorsTest.cpp +++ b/llvm/unittests/Analysis/IVDescriptorsTest.cpp @@ -500,7 +500,7 @@ for.end: auto *AR = cast<SCEVAddRecExpr>(OrigInSCEV); EXPECT_EQ(AR->getNoWrapFlags(), SCEV::FlagNUW | SCEV::FlagNW); // Check the expressions and wrap flags for the monotonic induction. - EXPECT_EQ(Desc.getSCEVNoWrapFlags(), SCEV::FlagNSW); + EXPECT_EQ(SCEV::NoWrapFlags(Desc.getSCEVNoWrapFlags()), SCEV::FlagNSW); EXPECT_EQ(Desc.getStartSCEV(), AR->getStart()); EXPECT_EQ(Desc.getStepSCEV(), AR->getStepRecurrence(SE)); }); @@ -560,7 +560,7 @@ for.end: auto *StepSCEV = SE.getConstant(StartSCEV->getType(), 4); EXPECT_EQ(Desc.getStartSCEV(), StartSCEV); EXPECT_EQ(Desc.getStepSCEV(), StepSCEV); - EXPECT_EQ(Desc.getSCEVNoWrapFlags(), SCEV::FlagNUW); + EXPECT_EQ(SCEV::NoWrapFlags(Desc.getSCEVNoWrapFlags()), SCEV::FlagNUW); }); } @@ -673,6 +673,7 @@ for.end: EXPECT_EQ(Desc.getStepSCEV(), StepSCEV); // Check we don't add `nuw` when we have a negative GEP step. - EXPECT_EQ(Desc.getSCEVNoWrapFlags(), SCEV::FlagAnyWrap); + EXPECT_EQ(SCEV::NoWrapFlags(Desc.getSCEVNoWrapFlags()), + SCEV::FlagAnyWrap); }); } _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
