Skip to content

Commit 55fcbcd

Browse files
committed
Rebase and Revert the implement of castEVLRecipe
1 parent 74b7651 commit 55fcbcd

File tree

7 files changed

+351
-312
lines changed

7 files changed

+351
-312
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4455,7 +4455,6 @@ static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
44554455
case VPDef::VPWidenCallSC:
44564456
case VPDef::VPWidenCanonicalIVSC:
44574457
case VPDef::VPWidenCastSC:
4458-
case VPDef::VPWidenCastEVLSC:
44594458
case VPDef::VPWidenGEPSC:
44604459
case VPDef::VPWidenIntrinsicSC:
44614460
case VPDef::VPWidenSC:

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
905905
case VPRecipeBase::VPWidenCallSC:
906906
case VPRecipeBase::VPWidenCanonicalIVSC:
907907
case VPRecipeBase::VPWidenCastSC:
908-
case VPRecipeBase::VPWidenCastEVLSC:
909908
case VPRecipeBase::VPWidenGEPSC:
910909
case VPRecipeBase::VPWidenIntrinsicSC:
911910
case VPRecipeBase::VPWidenSC:
@@ -1107,7 +1106,6 @@ class VPRecipeWithIRFlags : public VPSingleDefRecipe {
11071106
R->getVPDefID() == VPRecipeBase::VPWidenEVLSC ||
11081107
R->getVPDefID() == VPRecipeBase::VPWidenGEPSC ||
11091108
R->getVPDefID() == VPRecipeBase::VPWidenCastSC ||
1110-
R->getVPDefID() == VPRecipeBase::VPWidenCastEVLSC ||
11111109
R->getVPDefID() == VPRecipeBase::VPReplicateSC ||
11121110
R->getVPDefID() == VPRecipeBase::VPVectorPointerSC;
11131111
}
@@ -1573,28 +1571,19 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags {
15731571
/// Result type for the cast.
15741572
Type *ResultTy;
15751573

1576-
protected:
1577-
VPWidenCastRecipe(unsigned VPDefOpcode, Instruction::CastOps Opcode,
1578-
VPValue *Op, Type *ResultTy, CastInst &UI)
1574+
public:
1575+
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
1576+
CastInst &UI)
15791577
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI), Opcode(Opcode),
15801578
ResultTy(ResultTy) {
15811579
assert(UI.getOpcode() == Opcode &&
15821580
"opcode of underlying cast doesn't match");
15831581
}
15841582

1585-
VPWidenCastRecipe(unsigned VPDefOpcode, Instruction::CastOps Opcode,
1586-
VPValue *Op, Type *ResultTy)
1583+
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy)
15871584
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op), Opcode(Opcode),
15881585
ResultTy(ResultTy) {}
15891586

1590-
public:
1591-
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
1592-
CastInst &UI)
1593-
: VPWidenCastRecipe(VPDef::VPWidenCastSC, Opcode, Op, ResultTy, UI) {}
1594-
1595-
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy)
1596-
: VPWidenCastRecipe(VPDef::VPWidenCastSC, Opcode, Op, ResultTy) {}
1597-
15981587
~VPWidenCastRecipe() override = default;
15991588

16001589
VPWidenCastRecipe *clone() override {
@@ -1605,15 +1594,7 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags {
16051594
return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy);
16061595
}
16071596

1608-
static inline bool classof(const VPRecipeBase *R) {
1609-
return R->getVPDefID() == VPRecipeBase::VPWidenCastSC ||
1610-
R->getVPDefID() == VPRecipeBase::VPWidenCastEVLSC;
1611-
}
1612-
1613-
static inline bool classof(const VPUser *U) {
1614-
auto *R = dyn_cast<VPRecipeBase>(U);
1615-
return R && classof(R);
1616-
}
1597+
VP_CLASSOF_IMPL(VPDef::VPWidenCastSC)
16171598

16181599
/// Produce widened copies of the cast.
16191600
void execute(VPTransformState &State) override;
@@ -1630,54 +1611,6 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags {
16301611
Type *getResultType() const { return ResultTy; }
16311612
};
16321613

1633-
// A recipe for widening cast operation with vector-predication intrinsics with
1634-
/// explicit vector length (EVL).
1635-
class VPWidenCastEVLRecipe : public VPWidenCastRecipe {
1636-
using VPRecipeWithIRFlags::transferFlags;
1637-
1638-
public:
1639-
VPWidenCastEVLRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
1640-
VPValue &EVL)
1641-
: VPWidenCastRecipe(VPDef::VPWidenCastEVLSC, Opcode, Op, ResultTy) {
1642-
addOperand(&EVL);
1643-
}
1644-
VPWidenCastEVLRecipe(VPWidenCastRecipe &W, VPValue &EVL)
1645-
: VPWidenCastEVLRecipe(W.getOpcode(), W.getOperand(0), W.getResultType(),
1646-
EVL) {
1647-
transferFlags(W);
1648-
}
1649-
1650-
~VPWidenCastEVLRecipe() override = default;
1651-
1652-
VPWidenCastEVLRecipe *clone() final {
1653-
llvm_unreachable("VPWidenEVLRecipe cannot be cloned");
1654-
return nullptr;
1655-
}
1656-
1657-
VP_CLASSOF_IMPL(VPDef::VPWidenCastEVLSC)
1658-
1659-
VPValue *getEVL() { return getOperand(getNumOperands() - 1); }
1660-
const VPValue *getEVL() const { return getOperand(getNumOperands() - 1); }
1661-
1662-
/// Produce a vp-intrinsic copies of the cast.
1663-
void execute(VPTransformState &State) final;
1664-
1665-
/// Returns true if the recipe only uses the first lane of operand \p Op.
1666-
bool onlyFirstLaneUsed(const VPValue *Op) const override {
1667-
assert(is_contained(operands(), Op) &&
1668-
"Op must be an operand of the recipe");
1669-
// EVL in that recipe is always the last operand, thus any use before means
1670-
// the VPValue should be vectorized.
1671-
return getEVL() == Op;
1672-
}
1673-
1674-
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1675-
/// Print the recipe.
1676-
void print(raw_ostream &O, const Twine &Indent,
1677-
VPSlotTracker &SlotTracker) const final;
1678-
#endif
1679-
};
1680-
16811614
/// VPScalarCastRecipe is a recipe to create scalar cast instructions.
16821615
class VPScalarCastRecipe : public VPSingleDefRecipe {
16831616
Instruction::CastOps Opcode;

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ bool VPRecipeBase::mayWriteToMemory() const {
9090
case VPVectorPointerSC:
9191
case VPWidenCanonicalIVSC:
9292
case VPWidenCastSC:
93-
case VPWidenCastEVLSC:
9493
case VPWidenGEPSC:
9594
case VPWidenIntOrFpInductionSC:
9695
case VPWidenLoadEVLSC:
@@ -137,7 +136,6 @@ bool VPRecipeBase::mayReadFromMemory() const {
137136
case VPVectorPointerSC:
138137
case VPWidenCanonicalIVSC:
139138
case VPWidenCastSC:
140-
case VPWidenCastEVLSC:
141139
case VPWidenGEPSC:
142140
case VPWidenIntOrFpInductionSC:
143141
case VPWidenPHISC:
@@ -177,7 +175,6 @@ bool VPRecipeBase::mayHaveSideEffects() const {
177175
case VPVectorPointerSC:
178176
case VPWidenCanonicalIVSC:
179177
case VPWidenCastSC:
180-
case VPWidenCastEVLSC:
181178
case VPWidenGEPSC:
182179
case VPWidenIntOrFpInductionSC:
183180
case VPWidenPHISC:
@@ -1479,40 +1476,6 @@ void VPWidenCastRecipe::execute(VPTransformState &State) {
14791476
State.addMetadata(Cast, cast_or_null<Instruction>(getUnderlyingValue()));
14801477
}
14811478

1482-
void VPWidenCastEVLRecipe::execute(VPTransformState &State) {
1483-
unsigned Opcode = getOpcode();
1484-
State.setDebugLocFrom(getDebugLoc());
1485-
assert(State.UF == 1 && "Expected only UF == 1 when vectorizing with "
1486-
"explicit vector length.");
1487-
1488-
assert(State.get(getOperand(0), 0)->getType()->isVectorTy() &&
1489-
"VPWidenCastEVLRecipe should not be used for scalars");
1490-
1491-
// TODO: add more cast instruction, eg: fptoint/inttofp/inttoptr/fptofp
1492-
if (Opcode == Instruction::SExt || Opcode == Instruction::ZExt ||
1493-
Opcode == Instruction::Trunc) {
1494-
Value *SrcVal = State.get(getOperand(0), 0);
1495-
VectorType *SrcTy = cast<VectorType>(SrcVal->getType());
1496-
VectorType *DsType =
1497-
VectorType::get(getResultType(), SrcTy->getElementCount());
1498-
1499-
IRBuilderBase &BuilderIR = State.Builder;
1500-
VectorBuilder Builder(BuilderIR);
1501-
Value *Mask = BuilderIR.CreateVectorSplat(State.VF, BuilderIR.getTrue());
1502-
1503-
Builder.setMask(Mask).setEVL(State.get(getEVL(), 0, /*NeedsScalar=*/true));
1504-
Value *VPInst =
1505-
Builder.createVectorInstruction(Opcode, DsType, {SrcVal}, "vp.cast");
1506-
if (VPInst) {
1507-
if (auto *VecOp = dyn_cast<CastInst>(VPInst))
1508-
VecOp->copyIRFlags(getUnderlyingInstr());
1509-
}
1510-
State.set(this, VPInst, 0);
1511-
State.addMetadata(VPInst,
1512-
dyn_cast_or_null<Instruction>(getUnderlyingValue()));
1513-
}
1514-
}
1515-
15161479
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
15171480
void VPWidenCastRecipe::print(raw_ostream &O, const Twine &Indent,
15181481
VPSlotTracker &SlotTracker) const {
@@ -1523,16 +1486,6 @@ void VPWidenCastRecipe::print(raw_ostream &O, const Twine &Indent,
15231486
printOperands(O, SlotTracker);
15241487
O << " to " << *getResultType();
15251488
}
1526-
1527-
void VPWidenCastEVLRecipe::print(raw_ostream &O, const Twine &Indent,
1528-
VPSlotTracker &SlotTracker) const {
1529-
O << Indent << "WIDEN-VP ";
1530-
printAsOperand(O, SlotTracker);
1531-
O << " = vp." << Instruction::getOpcodeName(getOpcode()) << " ";
1532-
printFlags(O);
1533-
printOperands(O, SlotTracker);
1534-
O << " to " << *getResultType();
1535-
}
15361489
#endif
15371490

15381491
/// This function adds

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,15 +1381,6 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
13811381
return nullptr;
13821382
return new VPWidenEVLRecipe(*W, EVL);
13831383
})
1384-
.Case<VPWidenCastRecipe>(
1385-
[&](VPWidenCastRecipe *W) -> VPRecipeBase * {
1386-
unsigned Opcode = W->getOpcode();
1387-
if (Opcode != Instruction::SExt &&
1388-
Opcode != Instruction::ZExt &&
1389-
Opcode != Instruction::Trunc)
1390-
return nullptr;
1391-
return new VPWidenCastEVLRecipe(*W, EVL);
1392-
})
13931384
.Case<VPReductionRecipe>([&](VPReductionRecipe *Red) {
13941385
VPValue *NewMask = GetNewMask(Red->getCondOp());
13951386
return new VPReductionEVLRecipe(*Red, EVL, NewMask);

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ class VPDef {
349349
VPWidenCallSC,
350350
VPWidenCanonicalIVSC,
351351
VPWidenCastSC,
352-
VPWidenCastEVLSC,
353352
VPWidenGEPSC,
354353
VPWidenIntrinsicSC,
355354
VPWidenLoadEVLSC,

llvm/test/Transforms/LoopVectorize/RISCV/inloop-reduction.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ define i32 @add_i16_i32(ptr nocapture readonly %x, i32 %n) {
166166
; IF-EVL-INLOOP-NEXT: [[TMP8:%.*]] = getelementptr inbounds i16, ptr [[X:%.*]], i32 [[TMP7]]
167167
; IF-EVL-INLOOP-NEXT: [[TMP9:%.*]] = getelementptr inbounds i16, ptr [[TMP8]], i32 0
168168
; IF-EVL-INLOOP-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 8 x i16> @llvm.vp.load.nxv8i16.p0(ptr align 2 [[TMP9]], <vscale x 8 x i1> shufflevector (<vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0), <vscale x 8 x i1> poison, <vscale x 8 x i32> zeroinitializer), i32 [[TMP6]])
169-
; IF-EVL-INLOOP-NEXT: [[VP_CAST:%.*]] = call <vscale x 8 x i32> @llvm.vp.sext.nxv8i32.nxv8i16(<vscale x 8 x i16> [[VP_OP_LOAD]], <vscale x 8 x i1> shufflevector (<vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0), <vscale x 8 x i1> poison, <vscale x 8 x i32> zeroinitializer), i32 [[TMP6]])
169+
; IF-EVL-INLOOP-NEXT: [[VP_CAST:%.*]] = sext <vscale x 8 x i16> [[VP_OP_LOAD]] to <vscale x 8 x i32>
170170
; IF-EVL-INLOOP-NEXT: [[TMP10:%.*]] = call i32 @llvm.vp.reduce.add.nxv8i32(i32 0, <vscale x 8 x i32> [[VP_CAST]], <vscale x 8 x i1> shufflevector (<vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0), <vscale x 8 x i1> poison, <vscale x 8 x i32> zeroinitializer), i32 [[TMP6]])
171171
; IF-EVL-INLOOP-NEXT: [[TMP11]] = add i32 [[TMP10]], [[VEC_PHI]]
172172
; IF-EVL-INLOOP-NEXT: [[INDEX_EVL_NEXT]] = add i32 [[TMP6]], [[EVL_BASED_IV]]

0 commit comments

Comments
 (0)