[llvm] 7cbf78e - [VPlan] Remove no-op addMetadata for VPWidenGEP/VPWidenIntOrFPInd (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 9 14:04:00 PDT 2025
Author: Florian Hahn
Date: 2025-04-09T22:03:43+01:00
New Revision: 7cbf78ec74ea899ac508da0067962ab91c39930f
URL: https://github.com/llvm/llvm-project/commit/7cbf78ec74ea899ac508da0067962ab91c39930f
DIFF: https://github.com/llvm/llvm-project/commit/7cbf78ec74ea899ac508da0067962ab91c39930f.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Analysis/VectorUtils.h
llvm/lib/Analysis/VectorUtils.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/VectorUtils.h b/llvm/include/llvm/Analysis/VectorUtils.h
index 4390b45f1f730..01137481c92ba 100644
--- a/llvm/include/llvm/Analysis/VectorUtils.h
+++ b/llvm/include/llvm/Analysis/VectorUtils.h
@@ -353,6 +353,14 @@ MDNode *uniteAccessGroups(MDNode *AccGroups1, MDNode *AccGroups2);
MDNode *intersectAccessGroups(const Instruction *Inst1,
const Instruction *Inst2);
+/// Add metadata from \p Inst to \p Metadata, if it can be preserved after
+/// vectorization. It can be preserved after vectorization if the kind is one of
+/// [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath, MD_nontemporal,
+/// MD_access_group, MD_mmra].
+void getMetadataToPropagate(
+ Instruction *Inst,
+ SmallVectorImpl<std::pair<unsigned, MDNode *>> &Metadata);
+
/// Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath,
/// MD_nontemporal, MD_access_group, MD_mmra].
/// For K in Kinds, we get the MDNode for K from each of the
diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp
index 2379093b512bb..1568b0f306a8f 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -986,7 +986,7 @@ MDNode *llvm::intersectAccessGroups(const Instruction *Inst1,
/// Add metadata from \p Inst to \p Metadata, if it can be preserved after
/// vectorization.
-static void getMetadataToPropagate(
+void llvm::getMetadataToPropagate(
Instruction *Inst,
SmallVectorImpl<std::pair<unsigned, MDNode *>> &Metadata) {
Inst->getAllMetadataOtherThanDebugLoc(Metadata);
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index da7aef73f9df3..669e8f371d3d3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1505,7 +1505,12 @@ class VPWidenGEPRecipe : public VPRecipeWithIRFlags {
public:
template <typename IterT>
VPWidenGEPRecipe(GetElementPtrInst *GEP, iterator_range<IterT> Operands)
- : VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP) {}
+ : VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP) {
+ SmallVector<std::pair<unsigned, MDNode *>> Metadata;
+ (void)Metadata;
+ getMetadataToPropagate(GEP, Metadata);
+ assert(Metadata.empty() && "unexpected metadata on GEP");
+ }
~VPWidenGEPRecipe() override = default;
@@ -1812,6 +1817,11 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
Step, IndDesc, DL),
Trunc(Trunc) {
addOperand(VF);
+ SmallVector<std::pair<unsigned, MDNode *>> Metadata;
+ (void)Metadata;
+ if (Trunc)
+ getMetadataToPropagate(Trunc, Metadata);
+ assert(Metadata.empty() && "unexpected metadata on Trunc");
}
~VPWidenIntOrFpInductionRecipe() override = default;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index ea56b4fa3c833..35e141ed01267 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -1966,8 +1966,6 @@ void VPWidenIntOrFpInductionRecipe::execute(VPTransformState &State) {
Instruction *LastInduction = cast<Instruction>(
Builder.CreateBinOp(AddOp, VecInd, SplatVF, "vec.ind.next"));
- if (isa<TruncInst>(EntryVal))
- State.addMetadata(LastInduction, EntryVal);
LastInduction->setDebugLoc(getDebugLoc());
VecInd->addIncoming(SteppedStart, VectorPH);
@@ -2154,7 +2152,6 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
getGEPNoWrapFlags());
Value *Splat = State.Builder.CreateVectorSplat(State.VF, NewGEP);
State.set(this, Splat);
- State.addMetadata(Splat, GEP);
} else {
// If the GEP has at least one loop-varying operand, we are sure to
// produce a vector of pointers unless VF is scalar.
@@ -2181,7 +2178,6 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
assert((State.VF.isScalar() || NewGEP->getType()->isVectorTy()) &&
"NewGEP is not a pointer vector");
State.set(this, NewGEP);
- State.addMetadata(NewGEP, GEP);
}
}
More information about the llvm-commits
mailing list