[llvm] [VPlan] Unroll VPReplicateRecipe by VF. (PR #142433)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 02:50:03 PDT 2025
================
@@ -430,3 +431,83 @@ void VPlanTransforms::unrollByUF(VPlan &Plan, unsigned UF, LLVMContext &Ctx) {
VPlanTransforms::removeDeadRecipes(Plan);
}
+
+/// Create a single-scalar clone of RepR for lane \p Lane.
+static VPReplicateRecipe *cloneForLane(VPlan &Plan, VPBuilder &Builder,
+ Type *IdxTy, VPReplicateRecipe *RepR,
+ VPLane Lane) {
+ // Collect the operands at Lane, creating extracts as needed.
+ SmallVector<VPValue *> NewOps;
+ for (VPValue *Op : RepR->operands()) {
+ if (vputils::isSingleScalar(Op)) {
+ NewOps.push_back(Op);
+ continue;
+ }
+ VPValue *Ext;
+ if (Lane.getKind() == VPLane::Kind::ScalableLast) {
+ Ext = Builder.createNaryOp(VPInstruction::ExtractLastElement, {Op});
+ } else {
+ // Look through buildvector to avoid unnecessary extracts.
+ auto *BV = dyn_cast<VPInstruction>(Op);
+ if (BV && BV->getOpcode() == VPInstruction::BuildVector) {
+ NewOps.push_back(BV->getOperand(Lane.getKnownLane()));
+ continue;
+ }
+ VPValue *Idx =
+ Plan.getOrAddLiveIn(ConstantInt::get(IdxTy, Lane.getKnownLane()));
+ Ext = Builder.createNaryOp(Instruction::ExtractElement, {Op, Idx});
+ }
+ NewOps.push_back(Ext);
+ }
+
+ auto *New =
+ new VPReplicateRecipe(RepR->getUnderlyingInstr(), NewOps,
----------------
fhahn wrote:
Eventually yes, but more work is needed separately to use VPInstruction for single-scalar VPReplicateRecipes: https://github.com/llvm/llvm-project/pull/141429, https://github.com/llvm/llvm-project/pull/140623
https://github.com/llvm/llvm-project/pull/142433
More information about the llvm-commits
mailing list