Skip to content

Commit d183c91

Browse files
committed
Remove VPStepVectorRecipe, replace with VPInstruction
1 parent 5ad4cc1 commit d183c91

File tree

5 files changed

+19
-58
lines changed

5 files changed

+19
-58
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,10 @@ class VPBuilder {
265265
FPBinOp ? FPBinOp->getFastMathFlags() : FastMathFlags()));
266266
}
267267

268-
VPStepVectorRecipe *createStepVector(Type *Ty) {
269-
return tryInsertInstruction(new VPStepVectorRecipe(Ty));
268+
VPInstruction *createStepVector(Type *Ty) {
269+
VPValue *TyVal = BB->getPlan()->getOrAddLiveIn(Constant::getNullValue(Ty));
270+
return tryInsertInstruction(
271+
new VPInstruction(VPInstruction::StepVector, {TyVal}));
270272
}
271273

272274
//===--------------------------------------------------------------------===//

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ class VPInstruction : public VPRecipeWithIRFlags,
880880
// Extracts the first active lane of a vector, where the first operand is
881881
// the predicate, and the second operand is the vector to extract.
882882
ExtractFirstActive,
883+
// Creates a step vector starting from 0 with a step of 1. The first operand
884+
// is a dummy constant that should be used to specify the element type.
885+
StepVector,
883886
};
884887

885888
private:
@@ -1236,41 +1239,6 @@ class VPScalarCastRecipe : public VPSingleDefRecipe {
12361239
}
12371240
};
12381241

1239-
/// A recipe for generating a step vector.
1240-
class VPStepVectorRecipe : public VPSingleDefRecipe {
1241-
/// Scalar return type of the intrinsic.
1242-
Type *ScalarTy;
1243-
1244-
public:
1245-
VPStepVectorRecipe(Type *Ty)
1246-
: VPSingleDefRecipe(VPDef::VPStepVectorSC, {}), ScalarTy(Ty) {}
1247-
1248-
~VPStepVectorRecipe() override = default;
1249-
1250-
VPStepVectorRecipe *clone() override {
1251-
return new VPStepVectorRecipe(ScalarTy);
1252-
}
1253-
1254-
VP_CLASSOF_IMPL(VPDef::VPStepVectorSC)
1255-
1256-
void execute(VPTransformState &State) override;
1257-
1258-
/// Return the cost of this VPStepVectorRecipe.
1259-
InstructionCost computeCost(ElementCount VF,
1260-
VPCostContext &Ctx) const override {
1261-
// TODO: Compute accurate cost after retiring the legacy cost model.
1262-
return 0;
1263-
}
1264-
1265-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1266-
void print(raw_ostream &O, const Twine &Indent,
1267-
VPSlotTracker &SlotTracker) const override;
1268-
#endif
1269-
1270-
/// Return the scalar return type of the intrinsic.
1271-
Type *getScalarType() const { return ScalarTy; }
1272-
};
1273-
12741242
/// A recipe for widening vector intrinsics.
12751243
class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags {
12761244
/// ID of the vector intrinsic to widen.

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
7777
case VPInstruction::CalculateTripCountMinusVF:
7878
case VPInstruction::CanonicalIVIncrementForPart:
7979
case VPInstruction::AnyOf:
80+
case VPInstruction::StepVector:
8081
return SetResultTyFromOp();
8182
case VPInstruction::ExtractFirstActive:
8283
case VPInstruction::ExtractFromEnd: {
@@ -243,8 +244,7 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
243244
// backedge value, here and in cases below.
244245
return inferScalarType(R->getStartValue());
245246
})
246-
.Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe,
247-
VPStepVectorRecipe>(
247+
.Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe>(
248248
[](const auto *R) { return R->getScalarType(); })
249249
.Case<VPReductionRecipe, VPPredInstPHIRecipe, VPWidenPHIRecipe,
250250
VPScalarIVStepsRecipe, VPWidenGEPRecipe, VPVectorPointerRecipe,

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ bool VPRecipeBase::mayWriteToMemory() const {
7373
case VPBranchOnMaskSC:
7474
case VPScalarIVStepsSC:
7575
case VPPredInstPHISC:
76-
case VPStepVectorSC:
7776
return false;
7877
case VPBlendSC:
7978
case VPReductionEVLSC:
@@ -121,7 +120,6 @@ bool VPRecipeBase::mayReadFromMemory() const {
121120
case VPScalarIVStepsSC:
122121
case VPWidenStoreEVLSC:
123122
case VPWidenStoreSC:
124-
case VPStepVectorSC:
125123
return false;
126124
case VPBlendSC:
127125
case VPReductionEVLSC:
@@ -152,7 +150,6 @@ bool VPRecipeBase::mayHaveSideEffects() const {
152150
case VPPredInstPHISC:
153151
case VPScalarCastSC:
154152
case VPReverseVectorPointerSC:
155-
case VPStepVectorSC:
156153
return false;
157154
case VPInstructionSC:
158155
return mayWriteToMemory();
@@ -712,6 +709,10 @@ Value *VPInstruction::generate(VPTransformState &State) {
712709
Builder.getInt64Ty(), Mask, true, "first.active.lane");
713710
return Builder.CreateExtractElement(Vec, Ctz, "early.exit.value");
714711
}
712+
case VPInstruction::StepVector: {
713+
Type *EltTy = State.get(getOperand(0), true)->getType();
714+
return State.Builder.CreateStepVector(VectorType::get(EltTy, State.VF));
715+
}
715716

716717
default:
717718
llvm_unreachable("Unsupported opcode for instruction");
@@ -824,6 +825,7 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
824825
case VPInstruction::LogicalAnd:
825826
case VPInstruction::Not:
826827
case VPInstruction::PtrAdd:
828+
case VPInstruction::StepVector:
827829
return false;
828830
default:
829831
return true;
@@ -851,6 +853,7 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
851853
case VPInstruction::BranchOnCount:
852854
case VPInstruction::BranchOnCond:
853855
case VPInstruction::ResumePhi:
856+
case VPInstruction::StepVector:
854857
return true;
855858
};
856859
llvm_unreachable("switch should return");
@@ -942,6 +945,9 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
942945
case VPInstruction::ExtractFirstActive:
943946
O << "extract-first-active";
944947
break;
948+
case VPInstruction::StepVector:
949+
O << "step-vector";
950+
break;
945951
default:
946952
O << Instruction::getOpcodeName(getOpcode());
947953
}
@@ -2291,7 +2297,7 @@ Value *VPScalarCastRecipe ::generate(VPTransformState &State) {
22912297
case Instruction::ZExt:
22922298
case Instruction::Trunc:
22932299
case Instruction::UIToFP: {
2294-
// Note: SExt not used yet.
2300+
// Note: SExt/ZExt not used yet.
22952301
Value *Op = State.get(getOperand(0), VPLane(0));
22962302
return State.Builder.CreateCast(Instruction::CastOps(Opcode), Op, ResultTy);
22972303
}
@@ -2315,20 +2321,6 @@ void VPScalarCastRecipe ::print(raw_ostream &O, const Twine &Indent,
23152321
}
23162322
#endif
23172323

2318-
void VPStepVectorRecipe::execute(VPTransformState &State) {
2319-
VectorType *Ty = VectorType::get(ScalarTy, State.VF);
2320-
State.set(this, State.Builder.CreateStepVector(Ty));
2321-
}
2322-
2323-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2324-
void VPStepVectorRecipe::print(raw_ostream &O, const Twine &Indent,
2325-
VPSlotTracker &SlotTracker) const {
2326-
O << Indent;
2327-
printAsOperand(O, SlotTracker);
2328-
O << " = STEP-VECTOR";
2329-
}
2330-
#endif
2331-
23322324
void VPBranchOnMaskRecipe::execute(VPTransformState &State) {
23332325
assert(State.Lane && "Branch on Mask works only on single instance.");
23342326

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ class VPDef {
354354
VPWidenSelectSC,
355355
VPBlendSC,
356356
VPHistogramSC,
357-
VPStepVectorSC,
358357
// START: Phi-like recipes. Need to be kept together.
359358
VPWidenPHISC,
360359
VPPredInstPHISC,

0 commit comments

Comments
 (0)