[llvm] [VPlan] Expand SCEV min/max via scalar intrinsic VPInstructions. (PR #207842)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 06:54:47 PDT 2026
================
@@ -842,6 +842,44 @@ VPValue *VPSCEVExpander::tryToExpand(const SCEV *S) {
}
return Builder.createScalarCast(Opcode, Op, S->getType(), DL);
}
+ case scUMaxExpr:
+ case scSMaxExpr:
+ case scUMinExpr:
+ case scSMinExpr: {
+ auto *MinMax = cast<SCEVMinMaxExpr>(S);
+ Intrinsic::ID IntrinsicID;
+ switch (S->getSCEVType()) {
+ case scUMaxExpr:
+ IntrinsicID = Intrinsic::umax;
+ break;
+ case scSMaxExpr:
+ IntrinsicID = Intrinsic::smax;
+ break;
+ case scUMinExpr:
+ IntrinsicID = Intrinsic::umin;
+ break;
+ case scSMinExpr:
+ IntrinsicID = Intrinsic::smin;
+ break;
+ default:
+ llvm_unreachable("not a min/max SCEV");
+ }
+ // Chain operands in reverse order matching SCEVExpander's expansion of
+ // min/max expressions.
+ VPValue *Result =
+ tryToExpand(MinMax->getOperand(MinMax->getNumOperands() - 1));
+ if (!Result)
+ return nullptr;
+ Type *Ty = MinMax->getType();
+ for (const SCEVUse &Op : drop_begin(reverse(MinMax->operands()))) {
+ VPValue *RHS = tryToExpand(Op);
+ if (!RHS)
+ return nullptr;
+ Result =
+ Builder.createScalarIntrinsic(IntrinsicID, {Result, RHS}, Ty, DL);
+ }
----------------
artagnon wrote:
Hm, seems wrong, considering that we could bail in between? Shouldn't we collect all the VPValues from tryToExpand (with the bailout) first, before creating scalar intrinsics?
https://github.com/llvm/llvm-project/pull/207842
More information about the llvm-commits
mailing list