Skip to content

Commit 26d2add

Browse files
committed
!fixup address latest comments, thanks
1 parent 2f90433 commit 26d2add

File tree

8 files changed

+34
-31
lines changed

8 files changed

+34
-31
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7192,7 +7192,7 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
71927192
// TODO: Move to VPlan transform stage once the transition to the VPlan-based
71937193
// cost model is complete for better cost estimates.
71947194
VPlanTransforms::runPass(VPlanTransforms::unrollByUF, BestVPlan, BestUF);
7195-
VPlanTransforms::runPass(VPlanTransforms::materializeBuildAndUnpackVectors,
7195+
VPlanTransforms::runPass(VPlanTransforms::materializePacksAndUnpacks,
71967196
BestVPlan);
71977197
VPlanTransforms::runPass(VPlanTransforms::materializeBroadcasts, BestVPlan);
71987198
VPlanTransforms::runPass(VPlanTransforms::replicateByVF, BestVPlan, BestVF);

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,11 @@ class LLVM_ABI_FOR_TEST VPInstruction : public VPRecipeWithIRFlags,
10641064
ResumeForEpilogue,
10651065
/// Returns the value for vscale.
10661066
VScale,
1067-
/// Extracts all lanes from its (non-scalable) vector operand.
1068-
UnpackVector,
1067+
/// Extracts all lanes from its (non-scalable) vector operand. This is an
1068+
/// abstract VPInstruction whose single defined VPValue represents VF
1069+
/// scalars extracted from a vector, to be replaced by VF ExtractElement
1070+
/// VPInstructions?
1071+
Unpack,
10691072
};
10701073

10711074
/// Returns true if this VPInstruction generates scalar values for all lanes.

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
110110
case VPInstruction::AnyOf:
111111
case VPInstruction::BuildStructVector:
112112
case VPInstruction::BuildVector:
113-
case VPInstruction::UnpackVector:
113+
case VPInstruction::Unpack:
114114
return SetResultTyFromOp();
115115
case VPInstruction::ExtractLane:
116116
return inferScalarType(R->getOperand(1));

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ unsigned VPInstruction::getNumOperandsForOpcode(unsigned Opcode) {
514514
case VPInstruction::ExtractPenultimateElement:
515515
case VPInstruction::FirstActiveLane:
516516
case VPInstruction::Not:
517-
case VPInstruction::UnpackVector:
517+
case VPInstruction::Unpack:
518518
return 1;
519519
case Instruction::ICmp:
520520
case Instruction::FCmp:
@@ -1241,7 +1241,7 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
12411241
case VPInstruction::StepVector:
12421242
case VPInstruction::ReductionStartVector:
12431243
case VPInstruction::VScale:
1244-
case VPInstruction::UnpackVector:
1244+
case VPInstruction::Unpack:
12451245
return false;
12461246
default:
12471247
return true;
@@ -1408,8 +1408,8 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
14081408
case VPInstruction::ResumeForEpilogue:
14091409
O << "resume-for-epilogue";
14101410
break;
1411-
case VPInstruction::UnpackVector:
1412-
O << "unpack-into-scalars";
1411+
case VPInstruction::Unpack:
1412+
O << "unpack";
14131413
break;
14141414
default:
14151415
O << Instruction::getOpcodeName(getOpcode());

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,7 +3747,7 @@ void VPlanTransforms::materializeBackedgeTakenCount(VPlan &Plan,
37473747
BTC->replaceAllUsesWith(TCMO);
37483748
}
37493749

3750-
void VPlanTransforms::materializeBuildAndUnpackVectors(VPlan &Plan) {
3750+
void VPlanTransforms::materializePacksAndUnpacks(VPlan &Plan) {
37513751
if (Plan.hasScalarVFOnly())
37523752
return;
37533753

@@ -3811,20 +3811,22 @@ void VPlanTransforms::materializeBuildAndUnpackVectors(VPlan &Plan) {
38113811
cast<VPRecipeBase>(U)->getParent()->getParent();
38123812
return ParentRegion && ParentRegion != LoopRegion;
38133813
};
3814-
3814+
// At the moment, we only create unpacks for scalar users outside
3815+
// replicate regions. Recipes inside replicate regions still manually
3816+
// extract the required lanes. TODO: Remove once replicate regions are
3817+
// unrolled explicitly.
38153818
if (none_of(Def->users(), [Def, &IsInsideReplicateRegion](VPUser *U) {
38163819
return !IsInsideReplicateRegion(U) && U->usesScalars(Def);
38173820
}))
38183821
continue;
38193822

3820-
auto *UnpackVector =
3821-
new VPInstruction(VPInstruction::UnpackVector, {Def});
3823+
auto *Unpack = new VPInstruction(VPInstruction::Unpack, {Def});
38223824
if (R.isPhi())
3823-
UnpackVector->insertBefore(*VPBB, VPBB->getFirstNonPhi());
3825+
Unpack->insertBefore(*VPBB, VPBB->getFirstNonPhi());
38243826
else
3825-
UnpackVector->insertAfter(&R);
3827+
Unpack->insertAfter(&R);
38263828
Def->replaceUsesWithIf(
3827-
UnpackVector, [Def, &IsInsideReplicateRegion](VPUser &U, unsigned) {
3829+
Unpack, [Def, &IsInsideReplicateRegion](VPUser &U, unsigned) {
38283830
return !IsInsideReplicateRegion(&U) && U.usesScalars(Def);
38293831
});
38303832
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ struct VPlanTransforms {
328328
/// Add explicit Build[Struct]Vector recipes that combine multiple scalar
329329
/// values into single vectors and UnpackVector to extract scalars from a
330330
/// vector as needed.
331-
static void materializeBuildAndUnpackVectors(VPlan &Plan);
331+
static void materializePacksAndUnpacks(VPlan &Plan);
332332

333333
/// Materialize VF and VFxUF to be computed explicitly using VPInstructions.
334334
static void materializeVFAndVFxUF(VPlan &Plan, VPBasicBlock *VectorPH,

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,8 @@ static VPValue *
470470
cloneForLane(VPlan &Plan, VPBuilder &Builder, Type *IdxTy,
471471
VPRecipeWithIRFlags *DefR, VPLane Lane,
472472
const DenseMap<VPValue *, SmallVector<VPValue *>> &Def2LaneDefs) {
473-
474473
VPValue *Op;
475-
if (match(DefR,
476-
m_VPInstruction<VPInstruction::UnpackVector>(m_VPValue(Op)))) {
474+
if (match(DefR, m_VPInstruction<VPInstruction::Unpack>(m_VPValue(Op)))) {
477475
auto LaneDefs = Def2LaneDefs.find(Op);
478476
if (LaneDefs != Def2LaneDefs.end())
479477
return LaneDefs->second[Lane.getKnownLane()];
@@ -486,20 +484,22 @@ cloneForLane(VPlan &Plan, VPBuilder &Builder, Type *IdxTy,
486484
// Collect the operands at Lane, creating extracts as needed.
487485
SmallVector<VPValue *> NewOps;
488486
for (VPValue *Op : DefR->operands()) {
489-
if (Lane.getKind() == VPLane::Kind::ScalableLast) {
490-
match(Op, m_VPInstruction<VPInstruction::UnpackVector>(m_VPValue(Op)));
491-
NewOps.push_back(
492-
Builder.createNaryOp(VPInstruction::ExtractLastElement, {Op}));
493-
continue;
494-
}
495-
496487
// If Op is a definition that has been unrolled, directly use the clone for
497488
// the corresponding lane.
498489
auto LaneDefs = Def2LaneDefs.find(Op);
499490
if (LaneDefs != Def2LaneDefs.end()) {
500491
NewOps.push_back(LaneDefs->second[Lane.getKnownLane()]);
501492
continue;
502493
}
494+
if (Lane.getKind() == VPLane::Kind::ScalableLast) {
495+
// Look through mandatory Unpack.
496+
[[maybe_unused]] bool Matched =
497+
match(Op, m_VPInstruction<VPInstruction::Unpack>(m_VPValue(Op)));
498+
assert(Matched && "original op must have been Unpack");
499+
NewOps.push_back(
500+
Builder.createNaryOp(VPInstruction::ExtractLastElement, {Op}));
501+
continue;
502+
}
503503
if (vputils::isSingleScalar(Op)) {
504504
NewOps.push_back(Op);
505505
continue;
@@ -513,8 +513,8 @@ cloneForLane(VPlan &Plan, VPBuilder &Builder, Type *IdxTy,
513513
}
514514
VPValue *Idx =
515515
Plan.getOrAddLiveIn(ConstantInt::get(IdxTy, Lane.getKnownLane()));
516-
NewOps.push_back(
517-
Builder.createNaryOp(Instruction::ExtractElement, {Op, Idx}));
516+
VPValue *Ext = Builder.createNaryOp(Instruction::ExtractElement, {Op, Idx});
517+
NewOps.push_back(Ext);
518518
}
519519

520520
VPRecipeWithIRFlags *New;
@@ -564,7 +564,7 @@ void VPlanTransforms::replicateByVF(VPlan &Plan, ElementCount VF) {
564564
cast<VPReplicateRecipe>(&R)->isSingleScalar()) ||
565565
(isa<VPInstruction>(&R) &&
566566
!cast<VPInstruction>(&R)->doesGeneratePerAllLanes() &&
567-
cast<VPInstruction>(&R)->getOpcode() != VPInstruction::UnpackVector))
567+
cast<VPInstruction>(&R)->getOpcode() != VPInstruction::Unpack))
568568
continue;
569569

570570
auto *DefR = cast<VPRecipeWithIRFlags>(&R);

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ inline bool isSingleScalar(const VPValue *VPV) {
8484
return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
8585
(PreservesUniformity(VPI->getOpcode()) &&
8686
all_of(VPI->operands(), isSingleScalar));
87-
if (auto *Reduce = dyn_cast<VPReductionRecipe>(VPV))
88-
return true;
8987

9088
// VPExpandSCEVRecipes must be placed in the entry and are alway uniform.
9189
return isa<VPExpandSCEVRecipe>(VPV);

0 commit comments

Comments
 (0)