Skip to content

Commit cd8ed3c

Browse files
Addressed comments
1 parent f224b3a commit cd8ed3c

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.
@@ -2645,11 +2651,6 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
26452651
setMask(Mask);
26462652
}
26472653

2648-
VPWidenLoadEVLRecipe *clone() override {
2649-
llvm_unreachable("VPWidenLoadEVLRecipe cannot be cloned");
2650-
return nullptr;
2651-
}
2652-
26532654
VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
26542655

26552656
/// Return the EVL operand.
@@ -2725,11 +2726,6 @@ struct VPWidenStoreEVLRecipe final : public VPWidenMemoryRecipe {
27252726
setMask(Mask);
27262727
}
27272728

2728-
VPWidenStoreEVLRecipe *clone() override {
2729-
llvm_unreachable("VPWidenStoreEVLRecipe cannot be cloned");
2730-
return nullptr;
2731-
}
2732-
27332729
VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)
27342730

27352731
/// 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
@@ -1212,12 +1212,6 @@ InstructionCost VPWidenRecipe::computeCost(ElementCount VF,
12121212
}
12131213
}
12141214

1215-
VPWidenEVLRecipe *VPWidenEVLRecipe::create(VPWidenRecipe *W, VPValue &EVL) {
1216-
auto *R = new VPWidenEVLRecipe(*W->getUnderlyingInstr(), W->operands(), EVL);
1217-
R->transferFlags(*W);
1218-
return R;
1219-
}
1220-
12211215
void VPWidenEVLRecipe::execute(VPTransformState &State) {
12221216
State.setDebugLocFrom(getDebugLoc());
12231217
assert(State.UF == 1 && "Expected only UF == 1 when vectorizing with "
@@ -1259,13 +1253,6 @@ void VPWidenEVLRecipe::execute(VPTransformState &State) {
12591253
State.addMetadata(VPInst, I);
12601254
}
12611255

1262-
bool VPWidenEVLRecipe::onlyFirstLaneUsed(const VPValue *Op) const {
1263-
assert(is_contained(operands(), Op) && "Op must be an operand of the recipe");
1264-
// EVL in that recipe is always the last operand, thus any use before means
1265-
// the VPValue should be vectorized.
1266-
return getEVL() == Op;
1267-
}
1268-
12691256
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
12701257
void VPWidenRecipe::print(raw_ostream &O, const Twine &Indent,
12711258
VPSlotTracker &SlotTracker) const {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,29 +1373,30 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
13731373
if (!Instruction::isBinaryOp(Opcode) &&
13741374
!Instruction::isUnaryOp(Opcode))
13751375
return nullptr;
1376-
return new VPWidenEVLRecipe(W, EVL);
1376+
return new VPWidenEVLRecipe(*W, EVL);
13771377
})
13781378
.Case<VPReductionRecipe>([&](VPReductionRecipe *Red) {
1379-
return new VPReductionEVLRecipe(*Red, EVL,
1380-
GetNewMask(Red->getCondOp()));
1379+
VPValue *NewMask = GetNewMask(Red->getCondOp());
1380+
return new VPReductionEVLRecipe(*Red, EVL, NewMask);
13811381
})
13821382
.Default([&](VPRecipeBase *R) { return nullptr; });
13831383

1384-
if (NewRecipe) {
1385-
[[maybe_unused]] unsigned NumDefVal = NewRecipe->getNumDefinedValues();
1386-
assert(NumDefVal == CurRecipe->getNumDefinedValues() &&
1387-
"New recipe must define the same number of values as the "
1388-
"original.");
1389-
assert(
1390-
NumDefVal <= 1 &&
1391-
"Only supports recipes with a single definition or without users.");
1392-
NewRecipe->insertBefore(CurRecipe);
1393-
if (isa<VPSingleDefRecipe, VPWidenLoadEVLRecipe>(NewRecipe)) {
1394-
VPValue *CurVPV = CurRecipe->getVPSingleValue();
1395-
CurVPV->replaceAllUsesWith(NewRecipe->getVPSingleValue());
1396-
}
1397-
CurRecipe->eraseFromParent();
1384+
if (!NewRecipe)
1385+
continue;
1386+
1387+
[[maybe_unused]] unsigned NumDefVal = NewRecipe->getNumDefinedValues();
1388+
assert(NumDefVal == CurRecipe->getNumDefinedValues() &&
1389+
"New recipe must define the same number of values as the "
1390+
"original.");
1391+
assert(
1392+
NumDefVal <= 1 &&
1393+
"Only supports recipes with a single definition or without users.");
1394+
NewRecipe->insertBefore(CurRecipe);
1395+
if (isa<VPSingleDefRecipe, VPWidenLoadEVLRecipe>(NewRecipe)) {
1396+
VPValue *CurVPV = CurRecipe->getVPSingleValue();
1397+
CurVPV->replaceAllUsesWith(NewRecipe->getVPSingleValue());
13981398
}
1399+
CurRecipe->eraseFromParent();
13991400
}
14001401
recursivelyDeleteDeadRecipes(HeaderMask);
14011402
}

0 commit comments

Comments
 (0)