[llvm] [LV] Support argmin/argmax with strict predicates. (PR #170223)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 24 05:47:13 PST 2026
================
@@ -1473,33 +1603,50 @@ bool VPlanTransforms::handleMultiUseReductions(VPlan &Plan) {
FindIVPhiR->getRecurrenceKind()))
return false;
+ assert(!FindIVPhiR->isInLoop() && !FindIVPhiR->isOrdered() &&
+ "cannot handle inloop/ordered reductions yet");
+
// TODO: Support cases where IVOp is the IV increment.
if (!match(IVOp, m_TruncOrSelf(m_VPValue(IVOp))) ||
!isa<VPWidenIntOrFpInductionRecipe>(IVOp))
return false;
- CmpInst::Predicate RdxPredicate = [RdxKind]() {
+ // Check if the predicate is compatible with the reduction kind.
+ bool IsValidKindPred = [RdxKind, Pred]() {
switch (RdxKind) {
case RecurKind::UMin:
- return CmpInst::ICMP_UGE;
+ return Pred == CmpInst::ICMP_UGE || Pred == CmpInst::ICMP_UGT;
case RecurKind::UMax:
- return CmpInst::ICMP_ULE;
+ return Pred == CmpInst::ICMP_ULE || Pred == CmpInst::ICMP_ULT;
case RecurKind::SMax:
- return CmpInst::ICMP_SLE;
+ return Pred == CmpInst::ICMP_SLE || Pred == CmpInst::ICMP_SLT;
case RecurKind::SMin:
- return CmpInst::ICMP_SGE;
+ return Pred == CmpInst::ICMP_SGE || Pred == CmpInst::ICMP_SGT;
default:
llvm_unreachable("unhandled recurrence kind");
}
}();
-
- // TODO: Strict predicates need to find the first IV value for which the
- // predicate holds, not the last.
- if (Pred != RdxPredicate)
+ if (!IsValidKindPred) {
+ ORE->emit([&]() {
+ return OptimizationRemarkMissed(
+ DEBUG_TYPE, "VectorizationMultiUseReductionPredicate",
+ TheLoop->getStartLoc(), TheLoop->getHeader())
+ << "Multi-use reduction with predicate "
+ << CmpInst::getPredicateName(Pred)
+ << " incompatible with reduction kind";
+ });
return false;
+ }
----------------
ayalz wrote:
Just noting this is tested in select-index-remarks.ll
https://github.com/llvm/llvm-project/pull/170223
More information about the llvm-commits
mailing list