[llvm] [LV] Vectorize selecting last IV of min/max element. (PR #141431)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 18 06:16:53 PST 2025
================
@@ -214,6 +214,40 @@ static bool checkOrderedReduction(RecurKind Kind, Instruction *ExactFPMathInst,
return true;
}
+static std::optional<RecurrenceDescriptor>
+getMultiUseMinMax(PHINode *Phi, RecurKind Kind, Loop *TheLoop) {
+ BasicBlock *Latch = TheLoop->getLoopLatch();
+ if (!Latch)
+ return std::nullopt;
+ Value *Inc = Phi->getIncomingValueForBlock(Latch);
+ RecurKind RK;
+ if (Phi->hasOneUse() ||
+ !RecurrenceDescriptor::isIntMinMaxRecurrenceKind(Kind))
+ return std::nullopt;
+
+ Value *A, *B;
+ if (match(Inc, m_OneUse(m_UMin(m_Value(A), m_Value(B)))))
+ RK = RecurKind::UMin;
+ else if (match(Inc, m_OneUse(m_UMax(m_Value(A), m_Value(B)))))
+ RK = RecurKind::UMax;
+ else if (match(Inc, m_OneUse(m_SMax(m_Value(A), m_Value(B)))))
+ RK = RecurKind::SMax;
+ else if (match(Inc, m_OneUse(m_SMin(m_Value(A), m_Value(B)))))
+ RK = RecurKind::SMin;
+ else
+ return std::nullopt;
+
+ if (A == B || (A != Phi && B != Phi))
+ return std::nullopt;
+
+ SmallPtrSet<Instruction *, 4> CastInsts;
+ Value *RdxStart = Phi->getIncomingValueForBlock(TheLoop->getLoopPreheader());
+ RecurrenceDescriptor RD(RdxStart, nullptr, nullptr, RK, FastMathFlags(),
+ nullptr, Phi->getType(), false, false, CastInsts, -1U,
+ true);
----------------
Mel-Chen wrote:
Could add /* arg name*/ for each nullptr and false?
https://github.com/llvm/llvm-project/pull/141431
More information about the llvm-commits
mailing list