Skip to content

Commit 2a20107

Browse files
committed
!fixup address latest comments, thanks
1 parent 71c1077 commit 2a20107

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8492,7 +8492,7 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
84928492
Builder.insert(VectorPtr);
84938493
Ptr = VectorPtr;
84948494
}
8495-
auto Metadata = getMetadataToPropagate(I);
8495+
auto Metadata = getRecipeMetadata(I);
84968496
if (LoadInst *Load = dyn_cast<LoadInst>(I))
84978497
return new VPWidenLoadRecipe(*Load, Ptr, Mask, Consecutive, Reverse,
84988498
Metadata, I->getDebugLoc());
@@ -8872,7 +8872,8 @@ VPRecipeBuilder::handleReplication(Instruction *I, ArrayRef<VPValue *> Operands,
88728872
assert((Range.Start.isScalar() || !IsUniform || !IsPredicated ||
88738873
(Range.Start.isScalable() && isa<IntrinsicInst>(I))) &&
88748874
"Should not predicate a uniform recipe");
8875-
auto *Recipe = new VPReplicateRecipe(I, Operands, IsUniform, BlockInMask, getMetadataToPropagate(I));
8875+
auto *Recipe = new VPReplicateRecipe(I, Operands, IsUniform, BlockInMask,
8876+
getRecipeMetadata(I));
88768877
return Recipe;
88778878
}
88788879

@@ -8993,18 +8994,18 @@ bool VPRecipeBuilder::getScaledReductions(
89938994
return false;
89948995
}
89958996

8996-
SmallVector<std::pair<unsigned, MDNode *>>
8997-
VPRecipeBuilder::getMetadataToPropagate(Instruction *I) const {
8997+
VPIRMetadata VPRecipeBuilder::getRecipeMetadata(Instruction *I) const {
89988998
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
89998999
::getMetadataToPropagate(I, Metadata);
9000-
if (LVer && isa<LoadInst, StoreInst>(I)) {
9001-
const auto &[AliasScopeMD, NoAliasMD] = LVer->getNoAliasMetadataFor(I);
9002-
if (AliasScopeMD)
9003-
Metadata.emplace_back(LLVMContext::MD_alias_scope, AliasScopeMD);
9004-
if (NoAliasMD)
9005-
Metadata.emplace_back(LLVMContext::MD_noalias, NoAliasMD);
9006-
}
9007-
return Metadata;
9000+
if (!LVer || !isa<LoadInst, StoreInst>(I))
9001+
return {};
9002+
9003+
const auto &[AliasScopeMD, NoAliasMD] = LVer->getNoAliasMetadataFor(I);
9004+
if (AliasScopeMD)
9005+
Metadata.emplace_back(LLVMContext::MD_alias_scope, AliasScopeMD);
9006+
if (NoAliasMD)
9007+
Metadata.emplace_back(LLVMContext::MD_noalias, NoAliasMD);
9008+
return {Metadata};
90089009
}
90099010

90109011
VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(
@@ -9576,7 +9577,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
95769577
if (Legal->isInvariantStoreOfReduction(SI)) {
95779578
auto *Recipe = new VPReplicateRecipe(
95789579
SI, R.operands(), true /* IsUniform */, nullptr /*Mask*/,
9579-
RecipeBuilder.getMetadataToPropagate(SI));
9580+
RecipeBuilder.getRecipeMetadata(SI));
95809581
Recipe->insertBefore(*MiddleVPBB, MBIP);
95819582
}
95829583
R.eraseFromParent();

llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ class VPRecipeBuilder {
241241

242242
/// Returns the metatadata that can be preserved from the original instruction
243243
/// \p I, including noalias metadata guaranteed by runtime checks.
244-
SmallVector<std::pair<unsigned, MDNode *>>
245-
getMetadataToPropagate(Instruction *I) const;
244+
VPIRMetadata getRecipeMetadata(Instruction *I) const;
246245
};
247246
} // end namespace llvm
248247

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,24 +1194,22 @@ struct VPIRPhi : public VPIRInstruction {
11941194
#endif
11951195
};
11961196

1197-
using MDArrayRef = ArrayRef<std::pair<unsigned, MDNode *>>;
1198-
11991197
/// Helper to manage IR metadata for recipes. It filters out metadata that
12001198
/// cannot be propagated.
12011199
class VPIRMetadata {
12021200
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
12031201

12041202
protected:
1205-
VPIRMetadata() {}
12061203
VPIRMetadata(Instruction &I) { getMetadataToPropagate(&I, Metadata); }
1207-
VPIRMetadata(MDArrayRef Metadata) : Metadata(Metadata) {}
12081204

12091205
public:
1206+
VPIRMetadata() {}
1207+
VPIRMetadata(ArrayRef<std::pair<unsigned, MDNode *>> Metadata)
1208+
: Metadata(Metadata) {}
1209+
VPIRMetadata(const VPIRMetadata &Other) : Metadata(Other.Metadata) {}
1210+
12101211
/// Add all metadata to \p I.
12111212
void applyMetadata(Instruction &I) const;
1212-
1213-
/// Return the IR metadata.
1214-
MDArrayRef getMetadata() const { return Metadata; }
12151213
};
12161214

12171215
/// VPWidenRecipe is a recipe for producing a widened instruction using the
@@ -2482,7 +2480,8 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
24822480

24832481
public:
24842482
VPReplicateRecipe(Instruction *I, ArrayRef<VPValue *> Operands,
2485-
bool IsUniform, VPValue *Mask = nullptr, ArrayRef<std::pair<unsigned, MDNode *>> Metadata = {})
2483+
bool IsUniform, VPValue *Mask = nullptr,
2484+
VPIRMetadata Metadata = {})
24862485
: VPRecipeWithIRFlags(VPDef::VPReplicateSC, Operands, *I),
24872486
VPIRMetadata(Metadata), IsUniform(IsUniform), IsPredicated(Mask) {
24882487
if (Mask)
@@ -2492,9 +2491,9 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
24922491
~VPReplicateRecipe() override = default;
24932492

24942493
VPReplicateRecipe *clone() override {
2495-
auto *Copy = new VPReplicateRecipe(
2496-
getUnderlyingInstr(), operands(), IsUniform,
2497-
isPredicated() ? getMask() : nullptr, getMetadata());
2494+
auto *Copy =
2495+
new VPReplicateRecipe(getUnderlyingInstr(), operands(), IsUniform,
2496+
isPredicated() ? getMask() : nullptr, *this);
24982497
Copy->transferFlags(*this);
24992498
return Copy;
25002499
}
@@ -2654,8 +2653,8 @@ class VPWidenMemoryRecipe : public VPRecipeBase, public VPIRMetadata {
26542653

26552654
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I,
26562655
std::initializer_list<VPValue *> Operands,
2657-
bool Consecutive, bool Reverse, MDArrayRef Metadata,
2658-
DebugLoc DL)
2656+
bool Consecutive, bool Reverse,
2657+
const VPIRMetadata &Metadata, DebugLoc DL)
26592658
: VPRecipeBase(SC, Operands, DL), VPIRMetadata(Metadata), Ingredient(I),
26602659
Consecutive(Consecutive), Reverse(Reverse) {
26612660
assert((Consecutive || !Reverse) && "Reverse implies consecutive");
@@ -2714,8 +2713,8 @@ class VPWidenMemoryRecipe : public VPRecipeBase, public VPIRMetadata {
27142713
/// optional mask.
27152714
struct VPWidenLoadRecipe final : public VPWidenMemoryRecipe, public VPValue {
27162715
VPWidenLoadRecipe(LoadInst &Load, VPValue *Addr, VPValue *Mask,
2717-
bool Consecutive, bool Reverse, MDArrayRef Metadata,
2718-
DebugLoc DL)
2716+
bool Consecutive, bool Reverse,
2717+
const VPIRMetadata &Metadata, DebugLoc DL)
27192718
: VPWidenMemoryRecipe(VPDef::VPWidenLoadSC, Load, {Addr}, Consecutive,
27202719
Reverse, Metadata, DL),
27212720
VPValue(this, &Load) {
@@ -2724,7 +2723,7 @@ struct VPWidenLoadRecipe final : public VPWidenMemoryRecipe, public VPValue {
27242723

27252724
VPWidenLoadRecipe *clone() override {
27262725
return new VPWidenLoadRecipe(cast<LoadInst>(Ingredient), getAddr(),
2727-
getMask(), Consecutive, Reverse, getMetadata(),
2726+
getMask(), Consecutive, Reverse, *this,
27282727
getDebugLoc());
27292728
}
27302729

@@ -2756,7 +2755,7 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
27562755
VPWidenLoadEVLRecipe(VPWidenLoadRecipe &L, VPValue &EVL, VPValue *Mask)
27572756
: VPWidenMemoryRecipe(VPDef::VPWidenLoadEVLSC, L.getIngredient(),
27582757
{L.getAddr(), &EVL}, L.isConsecutive(),
2759-
L.isReverse(), L.getMetadata(), L.getDebugLoc()),
2758+
L.isReverse(), L, L.getDebugLoc()),
27602759
VPValue(this, &getIngredient()) {
27612760
setMask(Mask);
27622761
}
@@ -2794,7 +2793,7 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
27942793
struct VPWidenStoreRecipe final : public VPWidenMemoryRecipe {
27952794
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal,
27962795
VPValue *Mask, bool Consecutive, bool Reverse,
2797-
MDArrayRef Metadata, DebugLoc DL)
2796+
const VPIRMetadata &Metadata, DebugLoc DL)
27982797
: VPWidenMemoryRecipe(VPDef::VPWidenStoreSC, Store, {Addr, StoredVal},
27992798
Consecutive, Reverse, Metadata, DL) {
28002799
setMask(Mask);
@@ -2803,7 +2802,7 @@ struct VPWidenStoreRecipe final : public VPWidenMemoryRecipe {
28032802
VPWidenStoreRecipe *clone() override {
28042803
return new VPWidenStoreRecipe(cast<StoreInst>(Ingredient), getAddr(),
28052804
getStoredValue(), getMask(), Consecutive,
2806-
Reverse, getMetadata(), getDebugLoc());
2805+
Reverse, *this, getDebugLoc());
28072806
}
28082807

28092808
VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC);
@@ -2837,7 +2836,7 @@ struct VPWidenStoreEVLRecipe final : public VPWidenMemoryRecipe {
28372836
VPWidenStoreEVLRecipe(VPWidenStoreRecipe &S, VPValue &EVL, VPValue *Mask)
28382837
: VPWidenMemoryRecipe(VPDef::VPWidenStoreEVLSC, S.getIngredient(),
28392838
{S.getAddr(), S.getStoredValue(), &EVL},
2840-
S.isConsecutive(), S.isReverse(), S.getMetadata(),
2839+
S.isConsecutive(), S.isReverse(), S,
28412840
S.getDebugLoc()) {
28422841
setMask(Mask);
28432842
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2751,7 +2751,6 @@ void VPWidenLoadRecipe::execute(VPTransformState &State) {
27512751
} else {
27522752
NewLI = Builder.CreateAlignedLoad(DataTy, Addr, Alignment, "wide.load");
27532753
}
2754-
// Add metadata to the load, but setVectorValue to the reverse shuffle.
27552754
applyMetadata(*cast<Instruction>(NewLI));
27562755
if (Reverse)
27572756
NewLI = Builder.CreateVectorReverse(NewLI, "reverse");

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
8282
::getMetadataToPropagate(Inst, Metadata);
8383
NewRecipe = new VPWidenLoadRecipe(
8484
*Load, Ingredient.getOperand(0), nullptr /*Mask*/,
85-
false /*Consecutive*/, false /*Reverse*/, Metadata,
85+
false /*Consecutive*/, false /*Reverse*/, {Metadata},
8686
Ingredient.getDebugLoc());
8787
} else if (StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
8888
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
8989
::getMetadataToPropagate(Inst, Metadata);
9090
NewRecipe = new VPWidenStoreRecipe(
9191
*Store, Ingredient.getOperand(1), Ingredient.getOperand(0),
9292
nullptr /*Mask*/, false /*Consecutive*/, false /*Reverse*/,
93-
Metadata, Ingredient.getDebugLoc());
93+
{Metadata}, Ingredient.getDebugLoc());
9494
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
9595
NewRecipe = new VPWidenGEPRecipe(GEP, Ingredient.operands());
9696
} else if (CallInst *CI = dyn_cast<CallInst>(Inst)) {
@@ -187,9 +187,9 @@ static bool sinkScalarOperands(VPlan &Plan) {
187187
// TODO: Handle converting to uniform recipes as separate transform,
188188
// then cloning should be sufficient here.
189189
Instruction *I = SinkCandidate->getUnderlyingInstr();
190-
Clone = new VPReplicateRecipe(
191-
I, SinkCandidate->operands(), true, /*Mask*/ nullptr,
192-
cast<VPReplicateRecipe>(SinkCandidate)->getMetadata());
190+
Clone = new VPReplicateRecipe(I, SinkCandidate->operands(), true,
191+
/*Mask*/ nullptr,
192+
*cast<VPReplicateRecipe>(SinkCandidate));
193193
// TODO: add ".cloned" suffix to name of Clone's VPValue.
194194
} else {
195195
Clone = SinkCandidate->clone();
@@ -351,7 +351,7 @@ static VPRegionBlock *createReplicateRegion(VPReplicateRecipe *PredRecipe,
351351
auto *RecipeWithoutMask = new VPReplicateRecipe(
352352
PredRecipe->getUnderlyingInstr(),
353353
make_range(PredRecipe->op_begin(), std::prev(PredRecipe->op_end())),
354-
PredRecipe->isUniform(), /*Mask*/ nullptr, PredRecipe->getMetadata());
354+
PredRecipe->isUniform(), /*Mask*/ nullptr, *PredRecipe);
355355
auto *Pred =
356356
Plan.createVPBasicBlock(Twine(RegionName) + ".if", RecipeWithoutMask);
357357

@@ -2810,7 +2810,7 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
28102810
// process one original iteration.
28112811
auto *N = new VPReplicateRecipe(&WideLoad->getIngredient(),
28122812
WideLoad->operands(), /*IsUniform*/ true,
2813-
/*Mask*/ nullptr, WideLoad->getMetadata());
2813+
/*Mask*/ nullptr, *WideLoad);
28142814
N->insertBefore(WideLoad);
28152815
return N;
28162816
};

0 commit comments

Comments
 (0)