From 7c047d9b7b11b8609a2f15ef0e32498fa8346abd Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Wed, 5 Nov 2025 17:08:33 +0800 Subject: [PATCH 1/2] [VPlan] Remove VPWidenRecipe constructor with no underlying instruction. NFCI My understanding is that a VPWidenRecipe should be used for recipes with an exact underlying scalar instruction, and VPInstruction should be used elsewhere e.g. for instructions generated as a part of the vectorization process. The only user of the VPWidenRecipe constructor that doesn't take an underlying instruction is in adjustRecipesForReductions, but we can just use VPInstruction there. --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 6 +++--- llvm/lib/Transforms/Vectorize/VPlan.h | 11 ++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index e5c3f17860103..c19d348ff1205 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8641,9 +8641,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions( CurrentLinkI->getOpcode() == Instruction::Sub) { Type *PhiTy = PhiR->getUnderlyingValue()->getType(); auto *Zero = Plan->getConstantInt(PhiTy, 0); - VPWidenRecipe *Sub = new VPWidenRecipe( - Instruction::Sub, {Zero, CurrentLink->getOperand(1)}, {}, - VPIRMetadata(), CurrentLinkI->getDebugLoc()); + auto *Sub = new VPInstruction(Instruction::Sub, + {Zero, CurrentLink->getOperand(1)}, + CurrentLinkI->getDebugLoc()); Sub->setUnderlyingValue(CurrentLinkI); LinkVPBB->insert(Sub, CurrentLink->getIterator()); VecOp = Sub; diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index cfe1f1e9d7528..0d51ea412acd1 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1447,12 +1447,6 @@ class LLVM_ABI_FOR_TEST VPWidenRecipe : public VPRecipeWithIRFlags, unsigned Opcode; public: - VPWidenRecipe(unsigned Opcode, ArrayRef Operands, - const VPIRFlags &Flags, const VPIRMetadata &Metadata, - DebugLoc DL) - : VPRecipeWithIRFlags(VPDef::VPWidenSC, Operands, Flags, DL), - VPIRMetadata(Metadata), Opcode(Opcode) {} - VPWidenRecipe(Instruction &I, ArrayRef Operands) : VPRecipeWithIRFlags(VPDef::VPWidenSC, Operands, I), VPIRMetadata(I), Opcode(I.getOpcode()) {} @@ -1460,9 +1454,8 @@ class LLVM_ABI_FOR_TEST VPWidenRecipe : public VPRecipeWithIRFlags, ~VPWidenRecipe() override = default; VPWidenRecipe *clone() override { - auto *R = - new VPWidenRecipe(getOpcode(), operands(), *this, *this, getDebugLoc()); - R->setUnderlyingValue(getUnderlyingValue()); + auto *R = new VPWidenRecipe(*getUnderlyingInstr(), operands()); + R->transferFlags(*this); return R; } From 1a6bec903279f06ac682dbb7df74519ebd7d4c19 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Thu, 6 Nov 2025 10:18:36 +0800 Subject: [PATCH 2/2] Add transferMetadata --- llvm/lib/Transforms/Vectorize/VPlan.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 0d51ea412acd1..7eead3ab2cb19 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -962,9 +962,12 @@ class VPIRMetadata { Metadata.emplace_back(Kind, Node); } - /// Intersect this VPIRMetada object with \p MD, keeping only metadata + /// Intersect this VPIRMetadata object with \p MD, keeping only metadata /// nodes that are common to both. void intersect(const VPIRMetadata &MD); + + /// Replace all metadata with \p MD. + void transferMetadata(const VPIRMetadata &MD) { Metadata = MD.Metadata; } }; /// This is a concrete Recipe that models a single VPlan-level instruction. @@ -1456,6 +1459,7 @@ class LLVM_ABI_FOR_TEST VPWidenRecipe : public VPRecipeWithIRFlags, VPWidenRecipe *clone() override { auto *R = new VPWidenRecipe(*getUnderlyingInstr(), operands()); R->transferFlags(*this); + R->transferMetadata(*this); return R; }