Skip to content

Commit a26efd3

Browse files
fhahnYilin Li
authored and
Yilin Li
committed
[VPlan] Remove no-op addMetadata for VPWidenGEP/VPWidenIntOrFPInd (NFC).
GEPs and truncates should not have any metadata that can be propgated at the moment, so addMetadata is a no-op. Remove the calls. This patch also adds assertions to the recipes' constructors, to ensure no metadata is accidentially dropped.
1 parent 09f12f7 commit a26efd3

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

llvm/include/llvm/Analysis/VectorUtils.h

+8
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@ MDNode *uniteAccessGroups(MDNode *AccGroups1, MDNode *AccGroups2);
353353
MDNode *intersectAccessGroups(const Instruction *Inst1,
354354
const Instruction *Inst2);
355355

356+
/// Add metadata from \p Inst to \p Metadata, if it can be preserved after
357+
/// vectorization. It can be preserved after vectorization if the kind is one of
358+
/// [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath, MD_nontemporal,
359+
/// MD_access_group, MD_mmra].
360+
void getMetadataToPropagate(
361+
Instruction *Inst,
362+
SmallVectorImpl<std::pair<unsigned, MDNode *>> &Metadata);
363+
356364
/// Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath,
357365
/// MD_nontemporal, MD_access_group, MD_mmra].
358366
/// For K in Kinds, we get the MDNode for K from each of the

llvm/lib/Analysis/VectorUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ MDNode *llvm::intersectAccessGroups(const Instruction *Inst1,
986986

987987
/// Add metadata from \p Inst to \p Metadata, if it can be preserved after
988988
/// vectorization.
989-
static void getMetadataToPropagate(
989+
void llvm::getMetadataToPropagate(
990990
Instruction *Inst,
991991
SmallVectorImpl<std::pair<unsigned, MDNode *>> &Metadata) {
992992
Inst->getAllMetadataOtherThanDebugLoc(Metadata);

llvm/lib/Transforms/Vectorize/VPlan.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,12 @@ class VPWidenGEPRecipe : public VPRecipeWithIRFlags {
15051505
public:
15061506
template <typename IterT>
15071507
VPWidenGEPRecipe(GetElementPtrInst *GEP, iterator_range<IterT> Operands)
1508-
: VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP) {}
1508+
: VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP) {
1509+
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
1510+
(void)Metadata;
1511+
getMetadataToPropagate(GEP, Metadata);
1512+
assert(Metadata.empty() && "unexpected metadata on GEP");
1513+
}
15091514

15101515
~VPWidenGEPRecipe() override = default;
15111516

@@ -1812,6 +1817,11 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
18121817
Step, IndDesc, DL),
18131818
Trunc(Trunc) {
18141819
addOperand(VF);
1820+
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
1821+
(void)Metadata;
1822+
if (Trunc)
1823+
getMetadataToPropagate(Trunc, Metadata);
1824+
assert(Metadata.empty() && "unexpected metadata on Trunc");
18151825
}
18161826

18171827
~VPWidenIntOrFpInductionRecipe() override = default;

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -1966,8 +1966,6 @@ void VPWidenIntOrFpInductionRecipe::execute(VPTransformState &State) {
19661966

19671967
Instruction *LastInduction = cast<Instruction>(
19681968
Builder.CreateBinOp(AddOp, VecInd, SplatVF, "vec.ind.next"));
1969-
if (isa<TruncInst>(EntryVal))
1970-
State.addMetadata(LastInduction, EntryVal);
19711969
LastInduction->setDebugLoc(getDebugLoc());
19721970

19731971
VecInd->addIncoming(SteppedStart, VectorPH);
@@ -2154,7 +2152,6 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
21542152
getGEPNoWrapFlags());
21552153
Value *Splat = State.Builder.CreateVectorSplat(State.VF, NewGEP);
21562154
State.set(this, Splat);
2157-
State.addMetadata(Splat, GEP);
21582155
} else {
21592156
// If the GEP has at least one loop-varying operand, we are sure to
21602157
// produce a vector of pointers unless VF is scalar.
@@ -2181,7 +2178,6 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
21812178
assert((State.VF.isScalar() || NewGEP->getType()->isVectorTy()) &&
21822179
"NewGEP is not a pointer vector");
21832180
State.set(this, NewGEP);
2184-
State.addMetadata(NewGEP, GEP);
21852181
}
21862182
}
21872183

0 commit comments

Comments
 (0)