diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h index 0845ec5c682c75..2e9a9fe0640ea8 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h @@ -45,8 +45,9 @@ class VPBuilder { VPBasicBlock::iterator InsertPt = VPBasicBlock::iterator(); VPInstruction *createInstruction(unsigned Opcode, - ArrayRef Operands, DebugLoc DL) { - VPInstruction *Instr = new VPInstruction(Opcode, Operands, DL); + ArrayRef Operands, DebugLoc DL, + const Twine &Name = "") { + VPInstruction *Instr = new VPInstruction(Opcode, Operands, DL, Name); if (BB) BB->insert(Instr, InsertPt); return Instr; @@ -54,8 +55,8 @@ class VPBuilder { VPInstruction *createInstruction(unsigned Opcode, std::initializer_list Operands, - DebugLoc DL) { - return createInstruction(Opcode, ArrayRef(Operands), DL); + DebugLoc DL, const Twine &Name = "") { + return createInstruction(Opcode, ArrayRef(Operands), DL, Name); } public: @@ -123,34 +124,37 @@ class VPBuilder { /// Create an N-ary operation with \p Opcode, \p Operands and set \p Inst as /// its underlying Instruction. VPValue *createNaryOp(unsigned Opcode, ArrayRef Operands, - Instruction *Inst = nullptr) { + Instruction *Inst = nullptr, const Twine &Name = "") { DebugLoc DL; if (Inst) DL = Inst->getDebugLoc(); - VPInstruction *NewVPInst = createInstruction(Opcode, Operands, DL); + VPInstruction *NewVPInst = createInstruction(Opcode, Operands, DL, Name); NewVPInst->setUnderlyingValue(Inst); return NewVPInst; } VPValue *createNaryOp(unsigned Opcode, ArrayRef Operands, - DebugLoc DL) { - return createInstruction(Opcode, Operands, DL); + DebugLoc DL, const Twine &Name = "") { + return createInstruction(Opcode, Operands, DL, Name); } - VPValue *createNot(VPValue *Operand, DebugLoc DL) { - return createInstruction(VPInstruction::Not, {Operand}, DL); + VPValue *createNot(VPValue *Operand, DebugLoc DL, const Twine &Name = "") { + return createInstruction(VPInstruction::Not, {Operand}, DL, Name); } - VPValue *createAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL) { - return createInstruction(Instruction::BinaryOps::And, {LHS, RHS}, DL); + VPValue *createAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL, + const Twine &Name = "") { + return createInstruction(Instruction::BinaryOps::And, {LHS, RHS}, DL, Name); } - VPValue *createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL) { - return createInstruction(Instruction::BinaryOps::Or, {LHS, RHS}, DL); + VPValue *createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL, + const Twine &Name = "") { + return createInstruction(Instruction::BinaryOps::Or, {LHS, RHS}, DL, Name); } VPValue *createSelect(VPValue *Cond, VPValue *TrueVal, VPValue *FalseVal, - DebugLoc DL) { - return createNaryOp(Instruction::Select, {Cond, TrueVal, FalseVal}, DL); + DebugLoc DL, const Twine &Name = "") { + return createNaryOp(Instruction::Select, {Cond, TrueVal, FalseVal}, DL, + Name); } //===--------------------------------------------------------------------===// diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 9593c26a826ce2..b7ef4fc30bb61f 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8031,7 +8031,8 @@ VPValue *VPRecipeBuilder::createBlockInMask(BasicBlock *BB, VPlanPtr &Plan) { Builder.setInsertPoint(HeaderVPBB, NewInsertionPoint); if (CM.TTI.emitGetActiveLaneMask()) { VPValue *TC = Plan->getOrCreateTripCount(); - BlockMask = Builder.createNaryOp(VPInstruction::ActiveLaneMask, {IV, TC}); + BlockMask = Builder.createNaryOp(VPInstruction::ActiveLaneMask, {IV, TC}, + nullptr, "active.lane.mask"); } else { VPValue *BTC = Plan->getOrCreateBackedgeTakenCount(); BlockMask = Builder.createNaryOp(VPInstruction::ICmpULE, {IV, BTC}); @@ -8588,7 +8589,7 @@ static void addCanonicalIVRecipes(VPlan &Plan, Type *IdxTy, DebugLoc DL, auto *CanonicalIVIncrement = new VPInstruction(HasNUW ? VPInstruction::CanonicalIVIncrementNUW : VPInstruction::CanonicalIVIncrement, - {CanonicalIVPHI}, DL); + {CanonicalIVPHI}, DL, "index.next"); CanonicalIVPHI->addOperand(CanonicalIVIncrement); VPBasicBlock *EB = TopRegion->getExitingBasicBlock(); diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 09da4a545d0dbd..f5f780d10def8e 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -794,6 +794,9 @@ class VPInstruction : public VPRecipeBase, public VPValue { FastMathFlags FMF; DebugLoc DL; + /// An optional name that can be used for the generated IR instruction. + const std::string Name; + /// Utility method serving execute(): generates a single instance of the /// modeled instruction. void generateInstruction(VPTransformState &State, unsigned Part); @@ -802,14 +805,15 @@ class VPInstruction : public VPRecipeBase, public VPValue { void setUnderlyingInstr(Instruction *I) { setUnderlyingValue(I); } public: - VPInstruction(unsigned Opcode, ArrayRef Operands, DebugLoc DL) + VPInstruction(unsigned Opcode, ArrayRef Operands, DebugLoc DL, + const Twine &Name = "") : VPRecipeBase(VPRecipeBase::VPInstructionSC, Operands), VPValue(VPValue::VPVInstructionSC, nullptr, this), Opcode(Opcode), - DL(DL) {} + DL(DL), Name(Name.str()) {} VPInstruction(unsigned Opcode, std::initializer_list Operands, - DebugLoc DL = {}) - : VPInstruction(Opcode, ArrayRef(Operands), DL) {} + DebugLoc DL = {}, const Twine &Name = "") + : VPInstruction(Opcode, ArrayRef(Operands), DL, Name) {} /// Method to support type inquiry through isa, cast, and dyn_cast. static inline bool classof(const VPValue *V) { @@ -818,7 +822,7 @@ class VPInstruction : public VPRecipeBase, public VPValue { VPInstruction *clone() const { SmallVector Operands(operands()); - return new VPInstruction(Opcode, Operands, DL); + return new VPInstruction(Opcode, Operands, DL, Name); } /// Method to support type inquiry through isa, cast, and dyn_cast. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index c1b1e261cf9b60..907e3cb4e62da0 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -189,7 +189,8 @@ void VPInstruction::generateInstruction(VPTransformState &State, if (Instruction::isBinaryOp(getOpcode())) { Value *A = State.get(getOperand(0), Part); Value *B = State.get(getOperand(1), Part); - Value *V = Builder.CreateBinOp((Instruction::BinaryOps)getOpcode(), A, B); + Value *V = + Builder.CreateBinOp((Instruction::BinaryOps)getOpcode(), A, B, Name); State.set(this, V, Part); return; } @@ -197,14 +198,14 @@ void VPInstruction::generateInstruction(VPTransformState &State, switch (getOpcode()) { case VPInstruction::Not: { Value *A = State.get(getOperand(0), Part); - Value *V = Builder.CreateNot(A); + Value *V = Builder.CreateNot(A, Name); State.set(this, V, Part); break; } case VPInstruction::ICmpULE: { Value *IV = State.get(getOperand(0), Part); Value *TC = State.get(getOperand(1), Part); - Value *V = Builder.CreateICmpULE(IV, TC); + Value *V = Builder.CreateICmpULE(IV, TC, Name); State.set(this, V, Part); break; } @@ -212,7 +213,7 @@ void VPInstruction::generateInstruction(VPTransformState &State, Value *Cond = State.get(getOperand(0), Part); Value *Op1 = State.get(getOperand(1), Part); Value *Op2 = State.get(getOperand(2), Part); - Value *V = Builder.CreateSelect(Cond, Op1, Op2); + Value *V = Builder.CreateSelect(Cond, Op1, Op2, Name); State.set(this, V, Part); break; } @@ -226,7 +227,7 @@ void VPInstruction::generateInstruction(VPTransformState &State, auto *PredTy = VectorType::get(Int1Ty, State.VF); Instruction *Call = Builder.CreateIntrinsic( Intrinsic::get_active_lane_mask, {PredTy, ScalarTC->getType()}, - {VIVElem0, ScalarTC}, nullptr, "active.lane.mask"); + {VIVElem0, ScalarTC}, nullptr, Name); State.set(this, Call, Part); break; } @@ -250,7 +251,8 @@ void VPInstruction::generateInstruction(VPTransformState &State, State.set(this, PartMinus1, Part); } else { Value *V2 = State.get(getOperand(1), Part); - State.set(this, Builder.CreateVectorSplice(PartMinus1, V2, -1), Part); + State.set(this, Builder.CreateVectorSplice(PartMinus1, V2, -1, Name), + Part); } break; } @@ -264,7 +266,7 @@ void VPInstruction::generateInstruction(VPTransformState &State, // elements) times the unroll factor (num of SIMD instructions). Value *Step = createStepForVF(Builder, Phi->getType(), State.VF, State.UF); - Next = Builder.CreateAdd(Phi, Step, "index.next", IsNUW, false); + Next = Builder.CreateAdd(Phi, Step, Name, IsNUW, false); } else { Next = State.get(this, 0); }