Skip to content

Commit 7935e7c

Browse files
committed
!fixup address latest comments, thanks
1 parent da24714 commit 7935e7c

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
@@ -8447,14 +8447,14 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
84478447
Builder.insert(VectorPtr);
84488448
Ptr = VectorPtr;
84498449
}
8450-
auto Metadata = getRecipeMetadata(I);
84518450
if (LoadInst *Load = dyn_cast<LoadInst>(I))
84528451
return new VPWidenLoadRecipe(*Load, Ptr, Mask, Consecutive, Reverse,
8453-
Metadata, I->getDebugLoc());
8452+
VPIRMetadata(*Load, LVer), I->getDebugLoc());
84548453

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

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

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

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

@@ -1221,13 +1222,17 @@ struct VPIRPhi : public VPIRInstruction {
12211222
class VPIRMetadata {
12221223
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
12231224

1224-
protected:
1225-
VPIRMetadata(Instruction &I) { getMetadataToPropagate(&I, Metadata); }
1226-
12271225
public:
12281226
VPIRMetadata() {}
1229-
VPIRMetadata(ArrayRef<std::pair<unsigned, MDNode *>> Metadata)
1230-
: Metadata(Metadata) {}
1227+
1228+
/// Adds metatadata that can be preserved from the original instruction
1229+
/// \p I.
1230+
VPIRMetadata(Instruction &I) { getMetadataToPropagate(&I, Metadata); }
1231+
1232+
/// Adds metatadata that can be preserved from the original instruction
1233+
/// \p I and noalias metadata guaranteed by runtime checks using \p LVer.
1234+
VPIRMetadata(Instruction &I, LoopVersioning *LVer);
1235+
12311236
VPIRMetadata(const VPIRMetadata &Other) : Metadata(Other.Metadata) {}
12321237

12331238
/// 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

@@ -1207,6 +1208,17 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
12071208
}
12081209
#endif
12091210

1211+
VPIRMetadata::VPIRMetadata(Instruction &I, LoopVersioning *LVer)
1212+
: VPIRMetadata(I) {
1213+
if (!LVer || !isa<LoadInst, StoreInst>(&I))
1214+
return;
1215+
const auto &[AliasScopeMD, NoAliasMD] = LVer->getNoAliasMetadataFor(&I);
1216+
if (AliasScopeMD)
1217+
Metadata.emplace_back(LLVMContext::MD_alias_scope, AliasScopeMD);
1218+
if (NoAliasMD)
1219+
Metadata.emplace_back(LLVMContext::MD_noalias, NoAliasMD);
1220+
}
1221+
12101222
void VPIRMetadata::applyMetadata(Instruction &I) const {
12111223
for (const auto &[Kind, Node] : Metadata)
12121224
I.setMetadata(Kind, Node);
@@ -2575,6 +2587,7 @@ static void scalarizeInstruction(const Instruction *Instr,
25752587
}
25762588

25772589
RepRecipe->applyFlags(*Cloned);
2590+
RepRecipe->applyMetadata(*Cloned);
25782591

25792592
if (auto DL = RepRecipe->getDebugLoc())
25802593
State.setDebugLocFrom(DL);
@@ -2588,7 +2601,6 @@ static void scalarizeInstruction(const Instruction *Instr,
25882601
InputLane = VPLane::getFirstLane();
25892602
Cloned->setOperand(I.index(), State.get(Operand, InputLane));
25902603
}
2591-
State.addNewMetadata(Cloned, Instr);
25922604

25932605
// Place the cloned scalar in the new loop.
25942606
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();
@@ -2795,10 +2793,11 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
27952793
if (auto *LoadGroup = dyn_cast<VPInterleaveRecipe>(R)) {
27962794
// Narrow interleave group to wide load, as transformed VPlan will only
27972795
// process one original iteration.
2796+
auto &LI =
2797+
*cast<LoadInst>(LoadGroup->getInterleaveGroup()->getInsertPos());
27982798
auto *L = new VPWidenLoadRecipe(
2799-
*cast<LoadInst>(LoadGroup->getInterleaveGroup()->getInsertPos()),
2800-
LoadGroup->getAddr(), LoadGroup->getMask(), /*Consecutive=*/true,
2801-
/*Reverse=*/false, {}, LoadGroup->getDebugLoc());
2799+
LI, LoadGroup->getAddr(), LoadGroup->getMask(), /*Consecutive=*/true,
2800+
/*Reverse=*/false, VPIRMetadata(LI), LoadGroup->getDebugLoc());
28022801
L->insertBefore(LoadGroup);
28032802
return L;
28042803
}

0 commit comments

Comments
 (0)