Skip to content

Commit 2499249

Browse files
committed
!fixup address latest comments, thanks
1 parent 5b064b1 commit 2499249

File tree

6 files changed

+43
-45
lines changed

6 files changed

+43
-45
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8448,14 +8448,14 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
84488448
Builder.insert(VectorPtr);
84498449
Ptr = VectorPtr;
84508450
}
8451-
auto Metadata = getRecipeMetadata(I);
84528451
if (LoadInst *Load = dyn_cast<LoadInst>(I))
84538452
return new VPWidenLoadRecipe(*Load, Ptr, Mask, Consecutive, Reverse,
8454-
Metadata, I->getDebugLoc());
8453+
VPIRMetadata(*Load, LVer), I->getDebugLoc());
84558454

84568455
StoreInst *Store = cast<StoreInst>(I);
84578456
return new VPWidenStoreRecipe(*Store, Ptr, Operands[0], Mask, Consecutive,
8458-
Reverse, Metadata, I->getDebugLoc());
8457+
Reverse, VPIRMetadata(*Store, LVer),
8458+
I->getDebugLoc());
84598459
}
84608460

84618461
/// Creates a VPWidenIntOrFpInductionRecpipe for \p Phi. If needed, it will also
@@ -8829,7 +8829,7 @@ VPRecipeBuilder::handleReplication(Instruction *I, ArrayRef<VPValue *> Operands,
88298829
(Range.Start.isScalable() && isa<IntrinsicInst>(I))) &&
88308830
"Should not predicate a uniform recipe");
88318831
auto *Recipe = new VPReplicateRecipe(I, Operands, IsUniform, BlockInMask,
8832-
getRecipeMetadata(I));
8832+
VPIRMetadata(*I, LVer));
88338833
return Recipe;
88348834
}
88358835

@@ -8950,20 +8950,6 @@ bool VPRecipeBuilder::getScaledReductions(
89508950
return false;
89518951
}
89528952

8953-
VPIRMetadata VPRecipeBuilder::getRecipeMetadata(Instruction *I) const {
8954-
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
8955-
::getMetadataToPropagate(I, Metadata);
8956-
if (!LVer || !isa<LoadInst, StoreInst>(I))
8957-
return {};
8958-
8959-
const auto &[AliasScopeMD, NoAliasMD] = LVer->getNoAliasMetadataFor(I);
8960-
if (AliasScopeMD)
8961-
Metadata.emplace_back(LLVMContext::MD_alias_scope, AliasScopeMD);
8962-
if (NoAliasMD)
8963-
Metadata.emplace_back(LLVMContext::MD_noalias, NoAliasMD);
8964-
return {Metadata};
8965-
}
8966-
89678953
VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(
89688954
Instruction *Instr, ArrayRef<VPValue *> Operands, VFRange &Range) {
89698955
// First, check for specific widening recipes that deal with inductions, Phi
@@ -9528,9 +9514,9 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
95289514
Legal->isInvariantAddressOfReduction(SI->getPointerOperand())) {
95299515
// Only create recipe for the final invariant store of the reduction.
95309516
if (Legal->isInvariantStoreOfReduction(SI)) {
9531-
auto *Recipe = new VPReplicateRecipe(
9532-
SI, R.operands(), true /* IsUniform */, nullptr /*Mask*/,
9533-
RecipeBuilder.getRecipeMetadata(SI));
9517+
auto *Recipe =
9518+
new VPReplicateRecipe(SI, R.operands(), true /* IsUniform */,
9519+
nullptr /*Mask*/, VPIRMetadata(*SI, LVer));
95349520
Recipe->insertBefore(*MiddleVPBB, MBIP);
95359521
}
95369522
R.eraseFromParent();
@@ -9712,7 +9698,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
97129698
// Collect mapping of IR header phis to header phi recipes, to be used in
97139699
// addScalarResumePhis.
97149700
VPRecipeBuilder RecipeBuilder(*Plan, OrigLoop, TLI, &TTI, Legal, CM, PSE,
9715-
Builder);
9701+
Builder, nullptr);
97169702
for (auto &R : Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
97179703
if (isa<VPCanonicalIVPHIRecipe>(&R))
97189704
continue;

llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class VPRecipeBuilder {
160160
LoopVectorizationLegality *Legal,
161161
LoopVectorizationCostModel &CM,
162162
PredicatedScalarEvolution &PSE, VPBuilder &Builder,
163-
LoopVersioning *LVer = nullptr)
163+
LoopVersioning *LVer)
164164
: Plan(Plan), OrigLoop(OrigLoop), TLI(TLI), TTI(TTI), Legal(Legal),
165165
CM(CM), PSE(PSE), Builder(Builder), LVer(LVer) {}
166166

@@ -238,10 +238,6 @@ class VPRecipeBuilder {
238238
}
239239
return Plan.getOrAddLiveIn(V);
240240
}
241-
242-
/// Returns the metatadata that can be preserved from the original instruction
243-
/// \p I, including noalias metadata guaranteed by runtime checks.
244-
VPIRMetadata getRecipeMetadata(Instruction *I) const;
245241
};
246242
} // end namespace llvm
247243

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ VPTransformState::VPTransformState(const TargetTransformInfo *TTI,
219219
DominatorTree *DT, AssumptionCache *AC,
220220
IRBuilderBase &Builder, VPlan *Plan,
221221
Loop *CurrentParentLoop, Type *CanonicalIVTy)
222-
: TTI(TTI), VF(VF), CFG(DT), LI(LI), Builder(Builder), ILV(ILV), Plan(Plan),
223-
CurrentParentLoop(CurrentParentLoop), LVer(nullptr), TypeAnalysis(CanonicalIVTy),
222+
: TTI(TTI), VF(VF), CFG(DT), LI(LI), Builder(Builder), Plan(Plan),
223+
CurrentParentLoop(CurrentParentLoop), TypeAnalysis(CanonicalIVTy),
224224
VPDT(*Plan) {}
225225

226226
Value *VPTransformState::get(const VPValue *Def, const VPLane &Lane) {

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class VPReplicateRecipe;
6565
class VPlanSlp;
6666
class Value;
6767
class LoopVectorizationCostModel;
68+
class LoopVersioning;
6869

6970
struct VPCostContext;
7071

@@ -1236,13 +1237,17 @@ struct VPIRPhi : public VPIRInstruction {
12361237
class VPIRMetadata {
12371238
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
12381239

1239-
protected:
1240-
VPIRMetadata(Instruction &I) { getMetadataToPropagate(&I, Metadata); }
1241-
12421240
public:
12431241
VPIRMetadata() {}
1244-
VPIRMetadata(ArrayRef<std::pair<unsigned, MDNode *>> Metadata)
1245-
: Metadata(Metadata) {}
1242+
1243+
/// Adds metatadata that can be preserved from the original instruction
1244+
/// \p I.
1245+
VPIRMetadata(Instruction &I) { getMetadataToPropagate(&I, Metadata); }
1246+
1247+
/// Adds metatadata that can be preserved from the original instruction
1248+
/// \p I and noalias metadata guaranteed by runtime checks using \p LVer.
1249+
VPIRMetadata(Instruction &I, LoopVersioning *LVer);
1250+
12461251
VPIRMetadata(const VPIRMetadata &Other) : Metadata(Other.Metadata) {}
12471252

12481253
/// Add all metadata to \p I.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/Support/raw_ostream.h"
3838
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
3939
#include "llvm/Transforms/Utils/LoopUtils.h"
40+
#include "llvm/Transforms/Utils/LoopVersioning.h"
4041
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
4142
#include <cassert>
4243

@@ -1229,6 +1230,17 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
12291230
}
12301231
#endif
12311232

1233+
VPIRMetadata::VPIRMetadata(Instruction &I, LoopVersioning *LVer)
1234+
: VPIRMetadata(I) {
1235+
if (!LVer || !isa<LoadInst, StoreInst>(&I))
1236+
return;
1237+
const auto &[AliasScopeMD, NoAliasMD] = LVer->getNoAliasMetadataFor(&I);
1238+
if (AliasScopeMD)
1239+
Metadata.emplace_back(LLVMContext::MD_alias_scope, AliasScopeMD);
1240+
if (NoAliasMD)
1241+
Metadata.emplace_back(LLVMContext::MD_noalias, NoAliasMD);
1242+
}
1243+
12321244
void VPIRMetadata::applyMetadata(Instruction &I) const {
12331245
for (const auto &[Kind, Node] : Metadata)
12341246
I.setMetadata(Kind, Node);
@@ -2590,6 +2602,7 @@ static void scalarizeInstruction(const Instruction *Instr,
25902602
}
25912603

25922604
RepRecipe->applyFlags(*Cloned);
2605+
RepRecipe->applyMetadata(*Cloned);
25932606

25942607
if (auto DL = RepRecipe->getDebugLoc())
25952608
State.setDebugLocFrom(DL);
@@ -2603,7 +2616,6 @@ static void scalarizeInstruction(const Instruction *Instr,
26032616
InputLane = VPLane::getFirstLane();
26042617
Cloned->setOperand(I.index(), State.get(Operand, InputLane));
26052618
}
2606-
State.addNewMetadata(Cloned, Instr);
26072619

26082620
// Place the cloned scalar in the new loop.
26092621
State.Builder.Insert(Cloned);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,13 @@ 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*/, VPIRMetadata(*Load),
8686
Ingredient.getDebugLoc());
8787
} else if (StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
88-
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
89-
::getMetadataToPropagate(Inst, Metadata);
9088
NewRecipe = new VPWidenStoreRecipe(
9189
*Store, Ingredient.getOperand(1), Ingredient.getOperand(0),
9290
nullptr /*Mask*/, false /*Consecutive*/, false /*Reverse*/,
93-
{Metadata}, Ingredient.getDebugLoc());
91+
VPIRMetadata(*Store), Ingredient.getDebugLoc());
9492
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
9593
NewRecipe = new VPWidenGEPRecipe(GEP, Ingredient.operands());
9694
} else if (CallInst *CI = dyn_cast<CallInst>(Inst)) {
@@ -183,13 +181,13 @@ static bool sinkScalarOperands(VPlan &Plan) {
183181
if (ScalarVFOnly)
184182
continue;
185183
VPSingleDefRecipe *Clone;
186-
if (isa<VPReplicateRecipe>(SinkCandidate)) {
184+
if (auto *SinkCandidateRepR =
185+
dyn_cast<VPReplicateRecipe>(SinkCandidate)) {
187186
// TODO: Handle converting to uniform recipes as separate transform,
188187
// then cloning should be sufficient here.
189188
Instruction *I = SinkCandidate->getUnderlyingInstr();
190189
Clone = new VPReplicateRecipe(I, SinkCandidate->operands(), true,
191-
/*Mask*/ nullptr,
192-
*cast<VPReplicateRecipe>(SinkCandidate));
190+
/*Mask*/ nullptr, *SinkCandidateRepR);
193191
// TODO: add ".cloned" suffix to name of Clone's VPValue.
194192
} else {
195193
Clone = SinkCandidate->clone();
@@ -2787,10 +2785,11 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
27872785
if (auto *LoadGroup = dyn_cast<VPInterleaveRecipe>(R)) {
27882786
// Narrow interleave group to wide load, as transformed VPlan will only
27892787
// process one original iteration.
2788+
auto &LI =
2789+
*cast<LoadInst>(LoadGroup->getInterleaveGroup()->getInsertPos());
27902790
auto *L = new VPWidenLoadRecipe(
2791-
*cast<LoadInst>(LoadGroup->getInterleaveGroup()->getInsertPos()),
2792-
LoadGroup->getAddr(), LoadGroup->getMask(), /*Consecutive=*/true,
2793-
/*Reverse=*/false, {}, LoadGroup->getDebugLoc());
2791+
LI, LoadGroup->getAddr(), LoadGroup->getMask(), /*Consecutive=*/true,
2792+
/*Reverse=*/false, VPIRMetadata(LI), LoadGroup->getDebugLoc());
27942793
L->insertBefore(LoadGroup);
27952794
return L;
27962795
}

0 commit comments

Comments
 (0)