Skip to content

Commit c8afdb5

Browse files
Addressed comments
1 parent 0fbee10 commit c8afdb5

File tree

4 files changed

+102
-118
lines changed

4 files changed

+102
-118
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ class VPWidenRecipe : public VPRecipeWithIRFlags {
14581458
#endif
14591459
};
14601460

1461-
/// A recipe for widening operations with vector-predication intrinsics.with
1461+
/// A recipe for widening operations with vector-predication intrinsics with
14621462
/// explicit vector length (EVL).
14631463
class VPWidenEVLRecipe : public VPWidenRecipe {
14641464
using VPRecipeWithIRFlags::transferFlags;
@@ -1469,9 +1469,9 @@ class VPWidenEVLRecipe : public VPWidenRecipe {
14691469
: VPWidenRecipe(VPDef::VPWidenEVLSC, I, Operands) {
14701470
addOperand(&EVL);
14711471
}
1472-
VPWidenEVLRecipe(VPWidenRecipe *W, VPValue &EVL)
1473-
: VPWidenEVLRecipe(*W->getUnderlyingInstr(), W->operands(), EVL) {
1474-
this->transferFlags(*W);
1472+
VPWidenEVLRecipe(VPWidenRecipe &W, VPValue &EVL)
1473+
: VPWidenEVLRecipe(*W.getUnderlyingInstr(), W.operands(), EVL) {
1474+
transferFlags(W);
14751475
}
14761476

14771477
~VPWidenEVLRecipe() override = default;
@@ -1491,7 +1491,13 @@ class VPWidenEVLRecipe : public VPWidenRecipe {
14911491
void execute(VPTransformState &State) override final;
14921492

14931493
/// Returns true if the recipe only uses the first lane of operand \p Op.
1494-
bool onlyFirstLaneUsed(const VPValue *Op) const override;
1494+
bool onlyFirstLaneUsed(const VPValue *Op) const override {
1495+
assert(is_contained(operands(), Op) &&
1496+
"Op must be an operand of the recipe");
1497+
// EVL in that recipe is always the last operand, thus any use before means
1498+
// the VPValue should be vectorized.
1499+
return getEVL() == Op;
1500+
}
14951501

14961502
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
14971503
/// Print the recipe.
@@ -2639,11 +2645,6 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
26392645
setMask(Mask);
26402646
}
26412647

2642-
VPWidenLoadEVLRecipe *clone() override {
2643-
llvm_unreachable("VPWidenLoadEVLRecipe cannot be cloned");
2644-
return nullptr;
2645-
}
2646-
26472648
VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
26482649

26492650
/// Return the EVL operand.
@@ -2719,11 +2720,6 @@ struct VPWidenStoreEVLRecipe final : public VPWidenMemoryRecipe {
27192720
setMask(Mask);
27202721
}
27212722

2722-
VPWidenStoreEVLRecipe *clone() override {
2723-
llvm_unreachable("VPWidenStoreEVLRecipe cannot be cloned");
2724-
return nullptr;
2725-
}
2726-
27272723
VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)
27282724

27292725
/// Return the address accessed by this recipe.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,12 +1218,6 @@ InstructionCost VPWidenRecipe::computeCost(ElementCount VF,
12181218
}
12191219
}
12201220

1221-
VPWidenEVLRecipe *VPWidenEVLRecipe::create(VPWidenRecipe *W, VPValue &EVL) {
1222-
auto *R = new VPWidenEVLRecipe(*W->getUnderlyingInstr(), W->operands(), EVL);
1223-
R->transferFlags(*W);
1224-
return R;
1225-
}
1226-
12271221
void VPWidenEVLRecipe::execute(VPTransformState &State) {
12281222
State.setDebugLocFrom(getDebugLoc());
12291223
assert(State.UF == 1 && "Expected only UF == 1 when vectorizing with "
@@ -1265,13 +1259,6 @@ void VPWidenEVLRecipe::execute(VPTransformState &State) {
12651259
State.addMetadata(VPInst, I);
12661260
}
12671261

1268-
bool VPWidenEVLRecipe::onlyFirstLaneUsed(const VPValue *Op) const {
1269-
assert(is_contained(operands(), Op) && "Op must be an operand of the recipe");
1270-
// EVL in that recipe is always the last operand, thus any use before means
1271-
// the VPValue should be vectorized.
1272-
return getEVL() == Op;
1273-
}
1274-
12751262
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
12761263
void VPWidenRecipe::print(raw_ostream &O, const Twine &Indent,
12771264
VPSlotTracker &SlotTracker) const {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,29 +1435,30 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
14351435
if (!Instruction::isBinaryOp(Opcode) &&
14361436
!Instruction::isUnaryOp(Opcode))
14371437
return nullptr;
1438-
return new VPWidenEVLRecipe(W, EVL);
1438+
return new VPWidenEVLRecipe(*W, EVL);
14391439
})
14401440
.Case<VPReductionRecipe>([&](VPReductionRecipe *Red) {
1441-
return new VPReductionEVLRecipe(*Red, EVL,
1442-
GetNewMask(Red->getCondOp()));
1441+
VPValue *NewMask = GetNewMask(Red->getCondOp());
1442+
return new VPReductionEVLRecipe(*Red, EVL, NewMask);
14431443
})
14441444
.Default([&](VPRecipeBase *R) { return nullptr; });
14451445

1446-
if (NewRecipe) {
1447-
[[maybe_unused]] unsigned NumDefVal = NewRecipe->getNumDefinedValues();
1448-
assert(NumDefVal == CurRecipe->getNumDefinedValues() &&
1449-
"New recipe must define the same number of values as the "
1450-
"original.");
1451-
assert(
1452-
NumDefVal <= 1 &&
1453-
"Only supports recipes with a single definition or without users.");
1454-
NewRecipe->insertBefore(CurRecipe);
1455-
if (isa<VPSingleDefRecipe, VPWidenLoadEVLRecipe>(NewRecipe)) {
1456-
VPValue *CurVPV = CurRecipe->getVPSingleValue();
1457-
CurVPV->replaceAllUsesWith(NewRecipe->getVPSingleValue());
1446+
if (!NewRecipe)
1447+
continue;
1448+
1449+
[[maybe_unused]] unsigned NumDefVal = NewRecipe->getNumDefinedValues();
1450+
assert(NumDefVal == CurRecipe->getNumDefinedValues() &&
1451+
"New recipe must define the same number of values as the "
1452+
"original.");
1453+
assert(
1454+
NumDefVal <= 1 &&
1455+
"Only supports recipes with a single definition or without users.");
1456+
NewRecipe->insertBefore(CurRecipe);
1457+
if (isa<VPSingleDefRecipe, VPWidenLoadEVLRecipe>(NewRecipe)) {
1458+
VPValue *CurVPV = CurRecipe->getVPSingleValue();
1459+
CurVPV->replaceAllUsesWith(NewRecipe->getVPSingleValue());
14581460
}
14591461
CurRecipe->eraseFromParent();
1460-
}
14611462
}
14621463
recursivelyDeleteDeadRecipes(HeaderMask);
14631464
}

0 commit comments

Comments
 (0)