Skip to content

Commit dcc6640

Browse files
committed
Remove VPSplatRecipe, replace with VPInstruction::Splat
1 parent 1cd6c81 commit dcc6640

File tree

5 files changed

+15
-55
lines changed

5 files changed

+15
-55
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

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

268-
VPSplatRecipe *createSplat(VPValue *Val) {
269-
return tryInsertInstruction(new VPSplatRecipe(Val));
268+
VPInstruction *createSplat(VPValue *Val) {
269+
return tryInsertInstruction(new VPInstruction(VPInstruction::Splat, {Val}));
270270
}
271271

272272
VPStepVectorRecipe *createStepVector(Type *Ty) {

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,8 @@ 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+
// Splats a scalar value across all lanes.
884+
Splat,
883885
};
884886

885887
private:
@@ -1236,39 +1238,6 @@ class VPScalarCastRecipe : public VPSingleDefRecipe {
12361238
}
12371239
};
12381240

1239-
/// A for splatting a scalar value to a vector.
1240-
class VPSplatRecipe : public VPSingleDefRecipe {
1241-
public:
1242-
VPSplatRecipe(VPValue *Op) : VPSingleDefRecipe(VPDef::VPSplatSC, {Op}) {}
1243-
1244-
~VPSplatRecipe() override = default;
1245-
1246-
VPSplatRecipe *clone() override { return new VPSplatRecipe(getOperand(0)); }
1247-
1248-
VP_CLASSOF_IMPL(VPDef::VPSplatSC)
1249-
1250-
void execute(VPTransformState &State) override;
1251-
1252-
/// Return the cost of this VPSplatRecipe.
1253-
InstructionCost computeCost(ElementCount VF,
1254-
VPCostContext &Ctx) const override {
1255-
// TODO: Compute accurate cost after retiring the legacy cost model.
1256-
return 0;
1257-
}
1258-
1259-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1260-
void print(raw_ostream &O, const Twine &Indent,
1261-
VPSlotTracker &SlotTracker) const override;
1262-
#endif
1263-
1264-
/// Returns true if the recipe only uses the first lane of operand \p Op.
1265-
bool onlyFirstLaneUsed(const VPValue *Op) const override {
1266-
assert(is_contained(operands(), Op) &&
1267-
"Op must be an operand of the recipe");
1268-
return true;
1269-
}
1270-
};
1271-
12721241
/// A recipe for generating a step vector.
12731242
class VPStepVectorRecipe : public VPSingleDefRecipe {
12741243
/// Scalar return type of the intrinsic.

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
9696
case VPInstruction::BranchOnCond:
9797
case VPInstruction::BranchOnCount:
9898
return Type::getVoidTy(Ctx);
99+
case VPInstruction::Splat:
100+
return inferScalarType(R->getOperand(0));
99101
default:
100102
break;
101103
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 9 additions & 19 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 VPSplatSC:
7776
case VPStepVectorSC:
7877
return false;
7978
case VPBlendSC:
@@ -122,7 +121,6 @@ bool VPRecipeBase::mayReadFromMemory() const {
122121
case VPScalarIVStepsSC:
123122
case VPWidenStoreEVLSC:
124123
case VPWidenStoreSC:
125-
case VPSplatSC:
126124
case VPStepVectorSC:
127125
return false;
128126
case VPBlendSC:
@@ -154,7 +152,6 @@ bool VPRecipeBase::mayHaveSideEffects() const {
154152
case VPPredInstPHISC:
155153
case VPScalarCastSC:
156154
case VPReverseVectorPointerSC:
157-
case VPSplatSC:
158155
case VPStepVectorSC:
159156
return false;
160157
case VPInstructionSC:
@@ -715,6 +712,10 @@ Value *VPInstruction::generate(VPTransformState &State) {
715712
Builder.getInt64Ty(), Mask, true, "first.active.lane");
716713
return Builder.CreateExtractElement(Vec, Ctz, "early.exit.value");
717714
}
715+
case VPInstruction::Splat:
716+
return State.Builder.CreateVectorSplat(State.VF,
717+
State.get(getOperand(0), true));
718+
718719
default:
719720
llvm_unreachable("Unsupported opcode for instruction");
720721
}
@@ -826,6 +827,7 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
826827
case VPInstruction::LogicalAnd:
827828
case VPInstruction::Not:
828829
case VPInstruction::PtrAdd:
830+
case VPInstruction::Splat:
829831
return false;
830832
default:
831833
return true;
@@ -853,6 +855,7 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
853855
case VPInstruction::BranchOnCount:
854856
case VPInstruction::BranchOnCond:
855857
case VPInstruction::ResumePhi:
858+
case VPInstruction::Splat:
856859
return true;
857860
};
858861
llvm_unreachable("switch should return");
@@ -944,6 +947,9 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
944947
case VPInstruction::ExtractFirstActive:
945948
O << "extract-first-active";
946949
break;
950+
case VPInstruction::Splat:
951+
O << "splat";
952+
break;
947953
default:
948954
O << Instruction::getOpcodeName(getOpcode());
949955
}
@@ -2319,22 +2325,6 @@ void VPScalarCastRecipe ::print(raw_ostream &O, const Twine &Indent,
23192325
}
23202326
#endif
23212327

2322-
void VPSplatRecipe::execute(VPTransformState &State) {
2323-
Value *Splat =
2324-
State.Builder.CreateVectorSplat(State.VF, State.get(getOperand(0), true));
2325-
State.set(this, Splat);
2326-
}
2327-
2328-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2329-
void VPSplatRecipe::print(raw_ostream &O, const Twine &Indent,
2330-
VPSlotTracker &SlotTracker) const {
2331-
O << Indent;
2332-
printAsOperand(O, SlotTracker);
2333-
O << " = SPLAT ";
2334-
printOperands(O, SlotTracker);
2335-
}
2336-
#endif
2337-
23382328
void VPStepVectorRecipe::execute(VPTransformState &State) {
23392329
VectorType *Ty = VectorType::get(ScalarTy, State.VF);
23402330
State.set(this, State.Builder.CreateStepVector(Ty));

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-
VPSplatSC,
358357
VPStepVectorSC,
359358
// START: Phi-like recipes. Need to be kept together.
360359
VPWidenPHISC,

0 commit comments

Comments
 (0)