Skip to content

Commit 906c430

Browse files
Addressed comments
1 parent 73a7df3 commit 906c430

File tree

4 files changed

+103
-119
lines changed

4 files changed

+103
-119
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.
@@ -2653,11 +2659,6 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
26532659
setMask(Mask);
26542660
}
26552661

2656-
VPWidenLoadEVLRecipe *clone() override {
2657-
llvm_unreachable("VPWidenLoadEVLRecipe cannot be cloned");
2658-
return nullptr;
2659-
}
2660-
26612662
VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
26622663

26632664
/// Return the EVL operand.
@@ -2733,11 +2734,6 @@ struct VPWidenStoreEVLRecipe final : public VPWidenMemoryRecipe {
27332734
setMask(Mask);
27342735
}
27352736

2736-
VPWidenStoreEVLRecipe *clone() override {
2737-
llvm_unreachable("VPWidenStoreEVLRecipe cannot be cloned");
2738-
return nullptr;
2739-
}
2740-
27412737
VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)
27422738

27432739
/// 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
@@ -1266,12 +1266,6 @@ InstructionCost VPWidenRecipe::computeCost(ElementCount VF,
12661266
}
12671267
}
12681268

1269-
VPWidenEVLRecipe *VPWidenEVLRecipe::create(VPWidenRecipe *W, VPValue &EVL) {
1270-
auto *R = new VPWidenEVLRecipe(*W->getUnderlyingInstr(), W->operands(), EVL);
1271-
R->transferFlags(*W);
1272-
return R;
1273-
}
1274-
12751269
void VPWidenEVLRecipe::execute(VPTransformState &State) {
12761270
State.setDebugLocFrom(getDebugLoc());
12771271
assert(State.UF == 1 && "Expected only UF == 1 when vectorizing with "
@@ -1313,13 +1307,6 @@ void VPWidenEVLRecipe::execute(VPTransformState &State) {
13131307
State.addMetadata(VPInst, I);
13141308
}
13151309

1316-
bool VPWidenEVLRecipe::onlyFirstLaneUsed(const VPValue *Op) const {
1317-
assert(is_contained(operands(), Op) && "Op must be an operand of the recipe");
1318-
// EVL in that recipe is always the last operand, thus any use before means
1319-
// the VPValue should be vectorized.
1320-
return getEVL() == Op;
1321-
}
1322-
13231310
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
13241311
void VPWidenRecipe::print(raw_ostream &O, const Twine &Indent,
13251312
VPSlotTracker &SlotTracker) const {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,29 +1345,30 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
13451345
if (!Instruction::isBinaryOp(Opcode) &&
13461346
!Instruction::isUnaryOp(Opcode))
13471347
return nullptr;
1348-
return new VPWidenEVLRecipe(W, EVL);
1348+
return new VPWidenEVLRecipe(*W, EVL);
13491349
})
13501350
.Case<VPReductionRecipe>([&](VPReductionRecipe *Red) {
1351-
return new VPReductionEVLRecipe(*Red, EVL,
1352-
GetNewMask(Red->getCondOp()));
1351+
VPValue *NewMask = GetNewMask(Red->getCondOp());
1352+
return new VPReductionEVLRecipe(*Red, EVL, NewMask);
13531353
})
13541354
.Default([&](VPRecipeBase *R) { return nullptr; });
13551355

1356-
if (NewRecipe) {
1357-
[[maybe_unused]] unsigned NumDefVal = NewRecipe->getNumDefinedValues();
1358-
assert(NumDefVal == CurRecipe->getNumDefinedValues() &&
1359-
"New recipe must define the same number of values as the "
1360-
"original.");
1361-
assert(
1362-
NumDefVal <= 1 &&
1363-
"Only supports recipes with a single definition or without users.");
1364-
NewRecipe->insertBefore(CurRecipe);
1365-
if (isa<VPSingleDefRecipe, VPWidenLoadEVLRecipe>(NewRecipe)) {
1366-
VPValue *CurVPV = CurRecipe->getVPSingleValue();
1367-
CurVPV->replaceAllUsesWith(NewRecipe->getVPSingleValue());
1368-
}
1369-
CurRecipe->eraseFromParent();
1356+
if (!NewRecipe)
1357+
continue;
1358+
1359+
[[maybe_unused]] unsigned NumDefVal = NewRecipe->getNumDefinedValues();
1360+
assert(NumDefVal == CurRecipe->getNumDefinedValues() &&
1361+
"New recipe must define the same number of values as the "
1362+
"original.");
1363+
assert(
1364+
NumDefVal <= 1 &&
1365+
"Only supports recipes with a single definition or without users.");
1366+
NewRecipe->insertBefore(CurRecipe);
1367+
if (isa<VPSingleDefRecipe, VPWidenLoadEVLRecipe>(NewRecipe)) {
1368+
VPValue *CurVPV = CurRecipe->getVPSingleValue();
1369+
CurVPV->replaceAllUsesWith(NewRecipe->getVPSingleValue());
13701370
}
1371+
CurRecipe->eraseFromParent();
13711372
}
13721373
recursivelyDeleteDeadRecipes(HeaderMask);
13731374
}

0 commit comments

Comments
 (0)