Skip to content

Commit b4a34f9

Browse files
committed
!fixup address latest comments, thanks
1 parent f617993 commit b4a34f9

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ class LLVM_ABI_FOR_TEST VPInstruction : public VPRecipeWithIRFlags,
10671067
/// Extracts all lanes from its (non-scalable) vector operand. This is an
10681068
/// abstract VPInstruction whose single defined VPValue represents VF
10691069
/// scalars extracted from a vector, to be replaced by VF ExtractElement
1070-
/// VPInstructions?
1070+
/// VPInstructions.
10711071
Unpack,
10721072
};
10731073

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,9 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const {
12851285
return getNumOperands() > 1;
12861286
case VPInstruction::PtrAdd:
12871287
return Op == getOperand(0) || vputils::onlyFirstLaneUsed(this);
1288+
case VPInstruction::WidePtrAdd:
1289+
// WidePtrAdd supports scalar and vector base addresses.
1290+
return false;
12881291
case VPInstruction::ComputeAnyOfResult:
12891292
case VPInstruction::ComputeFindIVResult:
12901293
return Op == getOperand(1);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,35 +3800,41 @@ void VPlanTransforms::materializePacksAndUnpacks(VPlan &Plan) {
38003800
// Create explicit VPInstructions to convert vectors to scalars.
38013801
for (VPBasicBlock *VPBB : VPBBsInsideLoopRegion) {
38023802
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
3803-
if (isa<VPReplicateRecipe, VPInstruction, VPScalarIVStepsRecipe>(&R))
3803+
if (isa<VPReplicateRecipe, VPInstruction, VPScalarIVStepsRecipe,
3804+
VPDerivedIVRecipe, VPCanonicalIVPHIRecipe>(&R))
38043805
continue;
38053806
for (VPValue *Def : R.definedValues()) {
3807+
// Skip recipes that are single-scalar or only have their first lane
3808+
// used.
3809+
// TODO: The Defs skipped here may or may not be vector values.
3810+
// Introduce Unpacks, and remove them later, if they are guaranteed to
3811+
// produce scalar values.
38063812
if (vputils::isSingleScalar(Def) || vputils::onlyFirstLaneUsed(Def))
38073813
continue;
38083814

3809-
auto IsInsideReplicateRegion = [LoopRegion](VPUser *U) {
3815+
// At the moment, we only create unpacks for scalar users outside
3816+
// replicate regions. Recipes inside replicate regions still manually
3817+
// extract the required lanes.
3818+
// TODO: Remove once replicate regions are
3819+
// unrolled completely.
3820+
auto IsCandidateUnpackUser = [Def](VPUser *U) {
38103821
VPRegionBlock *ParentRegion =
38113822
cast<VPRecipeBase>(U)->getParent()->getParent();
3812-
return ParentRegion && ParentRegion != LoopRegion;
3823+
return U->usesScalars(Def) &&
3824+
(!ParentRegion || !ParentRegion->isReplicator());
38133825
};
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.
3818-
if (none_of(Def->users(), [Def, &IsInsideReplicateRegion](VPUser *U) {
3819-
return !IsInsideReplicateRegion(U) && U->usesScalars(Def);
3820-
}))
3826+
if (none_of(Def->users(), IsCandidateUnpackUser))
38213827
continue;
38223828

38233829
auto *Unpack = new VPInstruction(VPInstruction::Unpack, {Def});
38243830
if (R.isPhi())
38253831
Unpack->insertBefore(*VPBB, VPBB->getFirstNonPhi());
38263832
else
38273833
Unpack->insertAfter(&R);
3828-
Def->replaceUsesWithIf(
3829-
Unpack, [Def, &IsInsideReplicateRegion](VPUser &U, unsigned) {
3830-
return !IsInsideReplicateRegion(&U) && U.usesScalars(Def);
3831-
});
3834+
Def->replaceUsesWithIf(Unpack,
3835+
[&IsCandidateUnpackUser](VPUser &U, unsigned) {
3836+
return IsCandidateUnpackUser(&U);
3837+
});
38323838
}
38333839
}
38343840
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ struct VPlanTransforms {
326326
VPBasicBlock *VectorPH);
327327

328328
/// Add explicit Build[Struct]Vector recipes that combine multiple scalar
329-
/// values into single vectors and UnpackVector to extract scalars from a
329+
/// values into single vectors and Unpack recipes to extract scalars from a
330330
/// vector as needed.
331331
static void materializePacksAndUnpacks(VPlan &Plan);
332332

0 commit comments

Comments
 (0)