[llvm] a8adb38 - [VPlan] Replace invariance fields from VPWidenGEPRecipe.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 08:52:38 PST 2023
Author: Florian Hahn
Date: 2023-03-09T17:52:22+01:00
New Revision: a8adb38a96d31a8845152acf1ead21f3d27e3c41
URL: https://github.com/llvm/llvm-project/commit/a8adb38a96d31a8845152acf1ead21f3d27e3c41
DIFF: https://github.com/llvm/llvm-project/commit/a8adb38a96d31a8845152acf1ead21f3d27e3c41.diff
LOG: [VPlan] Replace invariance fields from VPWidenGEPRecipe.
There is no need to store information about invariance in the recipe.
Replace the fields with checks of the operands using
isDefinedOutsideVectorRegions.
Reviewed By: Ayal
Differential Revision: https://reviews.llvm.org/D144487
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 19e6ec268e4ac..f1c6432c81c86 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8791,7 +8791,7 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
if (auto GEP = dyn_cast<GetElementPtrInst>(Instr))
return toVPRecipeResult(new VPWidenGEPRecipe(
- GEP, make_range(Operands.begin(), Operands.end()), OrigLoop));
+ GEP, make_range(Operands.begin(), Operands.end())));
if (auto *SI = dyn_cast<SelectInst>(Instr)) {
bool InvariantCond =
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 3dcbda53e55ee..a42224584686d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -990,25 +990,25 @@ class VPWidenSelectRecipe : public VPRecipeBase, public VPValue {
/// A recipe for handling GEP instructions.
class VPWidenGEPRecipe : public VPRecipeBase, public VPValue {
- bool IsPtrLoopInvariant;
- SmallBitVector IsIndexLoopInvariant;
+ bool isPointerLoopInvariant() const {
+ return getOperand(0)->isDefinedOutsideVectorRegions();
+ }
+
+ bool isIndexLoopInvariant(unsigned I) const {
+ return getOperand(I + 1)->isDefinedOutsideVectorRegions();
+ }
+
+ bool areAllOperandsInvariant() const {
+ return all_of(operands(), [](VPValue *Op) {
+ return Op->isDefinedOutsideVectorRegions();
+ });
+ }
public:
template <typename IterT>
VPWidenGEPRecipe(GetElementPtrInst *GEP, iterator_range<IterT> Operands)
- : VPRecipeBase(VPDef::VPWidenGEPSC, Operands), VPValue(this, GEP),
- IsIndexLoopInvariant(GEP->getNumIndices(), false) {}
+ : VPRecipeBase(VPDef::VPWidenGEPSC, Operands), VPValue(this, GEP) {}
- template <typename IterT>
- VPWidenGEPRecipe(GetElementPtrInst *GEP, iterator_range<IterT> Operands,
- Loop *OrigLoop)
- : VPRecipeBase(VPDef::VPWidenGEPSC, Operands), VPValue(this, GEP),
- IsIndexLoopInvariant(GEP->getNumIndices(), false) {
- IsPtrLoopInvariant = OrigLoop->isLoopInvariant(GEP->getPointerOperand());
- for (auto Index : enumerate(GEP->indices()))
- IsIndexLoopInvariant[Index.index()] =
- OrigLoop->isLoopInvariant(Index.value().get());
- }
~VPWidenGEPRecipe() override = default;
VP_CLASSOF_IMPL(VPDef::VPWidenGEPSC)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 18d42080975ce..aa4dd16f3144a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -775,7 +775,7 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
// is vector-typed. Thus, to keep the representation compact, we only use
// vector-typed operands for loop-varying values.
- if (State.VF.isVector() && IsPtrLoopInvariant && IsIndexLoopInvariant.all()) {
+ if (State.VF.isVector() && areAllOperandsInvariant()) {
// If we are vectorizing, but the GEP has only loop-invariant operands,
// the GEP we build (by only using vector-typed operands for
// loop-varying values) would be a scalar pointer. Thus, to ensure we
@@ -805,7 +805,7 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
for (unsigned Part = 0; Part < State.UF; ++Part) {
// The pointer operand of the new GEP. If it's loop-invariant, we
// won't broadcast it.
- auto *Ptr = IsPtrLoopInvariant
+ auto *Ptr = isPointerLoopInvariant()
? State.get(getOperand(0), VPIteration(0, 0))
: State.get(getOperand(0), Part);
@@ -814,7 +814,7 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
SmallVector<Value *, 4> Indices;
for (unsigned I = 1, E = getNumOperands(); I < E; I++) {
VPValue *Operand = getOperand(I);
- if (IsIndexLoopInvariant[I - 1])
+ if (isIndexLoopInvariant(I - 1))
Indices.push_back(State.get(Operand, VPIteration(0, 0)));
else
Indices.push_back(State.get(Operand, Part));
@@ -844,10 +844,9 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
void VPWidenGEPRecipe::print(raw_ostream &O, const Twine &Indent,
VPSlotTracker &SlotTracker) const {
O << Indent << "WIDEN-GEP ";
- O << (IsPtrLoopInvariant ? "Inv" : "Var");
- size_t IndicesNumber = IsIndexLoopInvariant.size();
- for (size_t I = 0; I < IndicesNumber; ++I)
- O << "[" << (IsIndexLoopInvariant[I] ? "Inv" : "Var") << "]";
+ O << (isPointerLoopInvariant() ? "Inv" : "Var");
+ for (size_t I = 0; I < getNumOperands() - 1; ++I)
+ O << "[" << (isIndexLoopInvariant(I) ? "Inv" : "Var") << "]";
O << " ";
printAsOperand(O, SlotTracker);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 31d85154c0dfc..31eae199ae5c5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -76,8 +76,8 @@ void VPlanTransforms::VPInstructionsToVPRecipes(
Plan->getOrAddVPValue(Store->getValueOperand()), nullptr /*Mask*/,
false /*Consecutive*/, false /*Reverse*/);
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
- NewRecipe = new VPWidenGEPRecipe(
- GEP, Plan->mapToVPValues(GEP->operands()), OrigLoop);
+ NewRecipe =
+ new VPWidenGEPRecipe(GEP, Plan->mapToVPValues(GEP->operands()));
} else if (CallInst *CI = dyn_cast<CallInst>(Inst)) {
NewRecipe =
new VPWidenCallRecipe(*CI, Plan->mapToVPValues(CI->args()),
More information about the llvm-commits
mailing list