[llvm] [VPlan] Materialize VF and VFxUF using VPInstructions. (PR #152879)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 10 22:05:34 PDT 2025
================
@@ -3339,6 +3339,50 @@ void VPlanTransforms::materializeVectorTripCount(VPlan &Plan,
VectorTC.replaceAllUsesWith(Res);
}
+void VPlanTransforms::materializeVFAndVFxUF(VPlan &Plan, VPBasicBlock *VectorPH,
+ ElementCount VFEC) {
+ VPBuilder Builder(VectorPH, VectorPH->begin());
+ auto *TCTy = VPTypeAnalysis(Plan).inferScalarType(Plan.getTripCount());
+ VPValue &VF = Plan.getVF();
+ VPValue &VFxUF = Plan.getVFxUF();
+ if (VF.getNumUsers()) {
+ VPValue *RuntimeVF =
+ Plan.getOrAddLiveIn(ConstantInt::get(TCTy, VFEC.getKnownMinValue()));
+ if (VFEC.isScalable())
+ RuntimeVF = Builder.createNaryOp(
+ Instruction::Mul,
+ {Builder.createNaryOp(VPInstruction::VScale, {}, TCTy), RuntimeVF},
+ VPIRFlags::WrapFlagsTy(true, false));
+ if (any_of(VF.users(), [&VF](VPUser *U) { return !U->usesScalars(&VF); })) {
+ auto *BC = Builder.createNaryOp(VPInstruction::Broadcast, {RuntimeVF});
+ VF.replaceUsesWithIf(
+ BC, [&VF](VPUser &U, unsigned) { return !U.usesScalars(&VF); });
+ }
+ VF.replaceAllUsesWith(RuntimeVF);
+
+ VPValue *UF = Plan.getOrAddLiveIn(ConstantInt::get(TCTy, Plan.getUF()));
+ auto *MulByUF = Plan.getUF() == 1 ? RuntimeVF
+ : Builder.createNaryOp(Instruction::Mul,
+ {RuntimeVF, UF});
+ VFxUF.replaceAllUsesWith(MulByUF);
+ return;
+ }
+
+ unsigned VFMulUF = VFEC.getKnownMinValue() * Plan.getUF();
+ VPValue *RuntimeVFxUF = Plan.getOrAddLiveIn(ConstantInt::get(TCTy, VFMulUF));
+ if (VFEC.isScalable()) {
+ RuntimeVFxUF =
+ VFMulUF == 1
+ ? RuntimeVFxUF
+ : Builder.createNaryOp(
+ Instruction::Mul,
----------------
lukel97 wrote:
If VFEC is scalable then do we not need to still multiply `RuntimeVFxUF` by vscale even if it's 1?
https://github.com/llvm/llvm-project/pull/152879
More information about the llvm-commits
mailing list