[llvm] [VPlan] Explicitly unroll replicate-regions without live-outs by VF. (PR #170212)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 25 16:48:18 PDT 2026
================
@@ -543,6 +543,42 @@ void VPlanTransforms::unrollByUF(VPlan &Plan, unsigned UF) {
VPlanTransforms::removeDeadRecipes(Plan);
}
+/// Add a lane offset to the start index of \p Steps.
+static void addLaneToStartIndex(VPScalarIVStepsRecipe *Steps, unsigned Lane,
+ VPlan &Plan, VPRecipeBase *InsertPt) {
+ assert(Lane > 0 && "Zero lane adds no offset to start index");
+ VPTypeAnalysis TypeInfo(Plan);
+ Type *BaseIVTy = TypeInfo.inferScalarType(Steps->getOperand(0));
+
+ VPValue *OldStartIndex = Steps->getStartIndex();
+ VPValue *LaneOffset;
+ unsigned AddOpcode;
+ // TODO: Retrieve the flags from Steps unconditionally.
+ VPIRFlags Flags;
+ if (BaseIVTy->isFloatingPointTy()) {
+ int SignedLane = static_cast<int>(Lane);
+ if (!OldStartIndex && Steps->getInductionOpcode() == Instruction::FSub)
+ SignedLane = -SignedLane;
+ LaneOffset = Plan.getOrAddLiveIn(ConstantFP::get(BaseIVTy, SignedLane));
+ AddOpcode = Steps->getInductionOpcode();
+ Flags = VPIRFlags(FastMathFlags());
+ } else {
+ unsigned BaseIVBits = BaseIVTy->getScalarSizeInBits();
+ LaneOffset = Plan.getConstantInt(
+ APInt(BaseIVBits, Lane, /*isSigned*/ false, /*implicitTrunc*/ true));
+ AddOpcode = Instruction::Add;
+ Flags = VPIRFlags(VPIRFlags::WrapFlagsTy(false, false));
+ }
+
+ VPValue *NewStartIndex = LaneOffset;
+ if (OldStartIndex) {
+ VPBuilder Builder(InsertPt);
----------------
ayalz wrote:
Ahh, understand now why Steps was inserted before calling - so it could be used here as the insertion point. It would good if `addLaneToStartIndex()` folded the constant Lane with the constant start index (Part * FixedVF), w/o having to introduce any additional recipe.
https://github.com/llvm/llvm-project/pull/170212
More information about the llvm-commits
mailing list