Skip to content

Commit c0cb8e7

Browse files
committed
!fixup address latest comments, thanks
1 parent 67caa7d commit c0cb8e7

File tree

6 files changed

+42
-44
lines changed

6 files changed

+42
-44
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8485,14 +8485,14 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
84858485
Builder.insert(VectorPtr);
84868486
Ptr = VectorPtr;
84878487
}
8488-
auto Metadata = getRecipeMetadata(I);
84898488
if (LoadInst *Load = dyn_cast<LoadInst>(I))
84908489
return new VPWidenLoadRecipe(*Load, Ptr, Mask, Consecutive, Reverse,
8491-
Metadata, I->getDebugLoc());
8490+
VPIRMetadata(*Load, LVer), I->getDebugLoc());
84928491

84938492
StoreInst *Store = cast<StoreInst>(I);
84948493
return new VPWidenStoreRecipe(*Store, Ptr, Operands[0], Mask, Consecutive,
8495-
Reverse, Metadata, I->getDebugLoc());
8494+
Reverse, VPIRMetadata(*Store, LVer),
8495+
I->getDebugLoc());
84968496
}
84978497

84988498
/// Creates a VPWidenIntOrFpInductionRecpipe for \p Phi. If needed, it will also
@@ -8866,7 +8866,7 @@ VPRecipeBuilder::handleReplication(Instruction *I, ArrayRef<VPValue *> Operands,
88668866
(Range.Start.isScalable() && isa<IntrinsicInst>(I))) &&
88678867
"Should not predicate a uniform recipe");
88688868
auto *Recipe = new VPReplicateRecipe(I, Operands, IsUniform, BlockInMask,
8869-
getRecipeMetadata(I));
8869+
VPIRMetadata(*I, LVer));
88708870
return Recipe;
88718871
}
88728872

@@ -8987,20 +8987,6 @@ bool VPRecipeBuilder::getScaledReductions(
89878987
return false;
89888988
}
89898989

8990-
VPIRMetadata VPRecipeBuilder::getRecipeMetadata(Instruction *I) const {
8991-
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
8992-
::getMetadataToPropagate(I, Metadata);
8993-
if (!LVer || !isa<LoadInst, StoreInst>(I))
8994-
return {};
8995-
8996-
const auto &[AliasScopeMD, NoAliasMD] = LVer->getNoAliasMetadataFor(I);
8997-
if (AliasScopeMD)
8998-
Metadata.emplace_back(LLVMContext::MD_alias_scope, AliasScopeMD);
8999-
if (NoAliasMD)
9000-
Metadata.emplace_back(LLVMContext::MD_noalias, NoAliasMD);
9001-
return {Metadata};
9002-
}
9003-
90048990
VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(
90058991
Instruction *Instr, ArrayRef<VPValue *> Operands, VFRange &Range) {
90068992
// First, check for specific widening recipes that deal with inductions, Phi
@@ -9568,9 +9554,9 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range,
95689554
Legal->isInvariantAddressOfReduction(SI->getPointerOperand())) {
95699555
// Only create recipe for the final invariant store of the reduction.
95709556
if (Legal->isInvariantStoreOfReduction(SI)) {
9571-
auto *Recipe = new VPReplicateRecipe(
9572-
SI, R.operands(), true /* IsUniform */, nullptr /*Mask*/,
9573-
RecipeBuilder.getRecipeMetadata(SI));
9557+
auto *Recipe =
9558+
new VPReplicateRecipe(SI, R.operands(), true /* IsUniform */,
9559+
nullptr /*Mask*/, VPIRMetadata(*SI, LVer));
95749560
Recipe->insertBefore(*MiddleVPBB, MBIP);
95759561
}
95769562
R.eraseFromParent();
@@ -9752,7 +9738,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
97529738
// Collect mapping of IR header phis to header phi recipes, to be used in
97539739
// addScalarResumePhis.
97549740
VPRecipeBuilder RecipeBuilder(*Plan, OrigLoop, TLI, &TTI, Legal, CM, PSE,
9755-
Builder);
9741+
Builder, nullptr);
97569742
for (auto &R : Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
97579743
if (isa<VPCanonicalIVPHIRecipe>(&R))
97589744
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

@@ -1199,13 +1200,17 @@ struct VPIRPhi : public VPIRInstruction {
11991200
class VPIRMetadata {
12001201
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
12011202

1202-
protected:
1203-
VPIRMetadata(Instruction &I) { getMetadataToPropagate(&I, Metadata); }
1204-
12051203
public:
12061204
VPIRMetadata() {}
1207-
VPIRMetadata(ArrayRef<std::pair<unsigned, MDNode *>> Metadata)
1208-
: Metadata(Metadata) {}
1205+
1206+
/// Adds metatadata that can be preserved from the original instruction
1207+
/// \p I.
1208+
VPIRMetadata(Instruction &I) { getMetadataToPropagate(&I, Metadata); }
1209+
1210+
/// Adds metatadata that can be preserved from the original instruction
1211+
/// \p I and noalias metadata guaranteed by runtime checks using \p LVer.
1212+
VPIRMetadata(Instruction &I, LoopVersioning *LVer);
1213+
12091214
VPIRMetadata(const VPIRMetadata &Other) : Metadata(Other.Metadata) {}
12101215

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

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "llvm/Support/raw_ostream.h"
3737
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
3838
#include "llvm/Transforms/Utils/LoopUtils.h"
39+
#include "llvm/Transforms/Utils/LoopVersioning.h"
3940
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
4041
#include <cassert>
4142

@@ -1205,6 +1206,17 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
12051206
}
12061207
#endif
12071208

1209+
VPIRMetadata::VPIRMetadata(Instruction &I, LoopVersioning *LVer)
1210+
: VPIRMetadata(I) {
1211+
if (!LVer || !isa<LoadInst, StoreInst>(&I))
1212+
return;
1213+
const auto &[AliasScopeMD, NoAliasMD] = LVer->getNoAliasMetadataFor(&I);
1214+
if (AliasScopeMD)
1215+
Metadata.emplace_back(LLVMContext::MD_alias_scope, AliasScopeMD);
1216+
if (NoAliasMD)
1217+
Metadata.emplace_back(LLVMContext::MD_noalias, NoAliasMD);
1218+
}
1219+
12081220
void VPIRMetadata::applyMetadata(Instruction &I) const {
12091221
for (const auto &[Kind, Node] : Metadata)
12101222
I.setMetadata(Kind, Node);

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();
@@ -2796,10 +2794,11 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
27962794
if (auto *LoadGroup = dyn_cast<VPInterleaveRecipe>(R)) {
27972795
// Narrow interleave group to wide load, as transformed VPlan will only
27982796
// process one original iteration.
2797+
auto &LI =
2798+
*cast<LoadInst>(LoadGroup->getInterleaveGroup()->getInsertPos());
27992799
auto *L = new VPWidenLoadRecipe(
2800-
*cast<LoadInst>(LoadGroup->getInterleaveGroup()->getInsertPos()),
2801-
LoadGroup->getAddr(), LoadGroup->getMask(), /*Consecutive=*/true,
2802-
/*Reverse=*/false, {}, LoadGroup->getDebugLoc());
2800+
LI, LoadGroup->getAddr(), LoadGroup->getMask(), /*Consecutive=*/true,
2801+
/*Reverse=*/false, VPIRMetadata(LI), LoadGroup->getDebugLoc());
28032802
L->insertBefore(LoadGroup);
28042803
return L;
28052804
}

0 commit comments

Comments
 (0)