[llvm] 15295d0 - [SLP][NFC]Introduce and use computeCommonAlignment function, NFC.
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 1 06:16:57 PST 2024
Author: Alexey Bataev
Date: 2024-02-01T06:13:39-08:00
New Revision: 15295d01352c922f1dfe564d801d556cf5fe01b3
URL: https://github.com/llvm/llvm-project/commit/15295d01352c922f1dfe564d801d556cf5fe01b3
DIFF: https://github.com/llvm/llvm-project/commit/15295d01352c922f1dfe564d801d556cf5fe01b3.diff
LOG: [SLP][NFC]Introduce and use computeCommonAlignment function, NFC.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index bde65717ac1d4..a8aea112bc28e 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3869,6 +3869,15 @@ static bool arePointersCompatible(Value *Ptr1, Value *Ptr2,
.getOpcode());
}
+/// Calculates minimal alignment as a common alignment.
+template <typename T>
+static Align computeCommonAlignment(ArrayRef<Value *> VL) {
+ Align CommonAlignment = cast<T>(VL.front())->getAlign();
+ for (Value *V : VL.drop_front())
+ CommonAlignment = std::min(CommonAlignment, cast<T>(V)->getAlign());
+ return CommonAlignment;
+}
+
/// Checks if the given array of loads can be represented as a vectorized,
/// scatter or just simple gather.
static LoadsState canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
@@ -3939,10 +3948,7 @@ static LoadsState canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
return (IsSorted && !GEP && doesNotNeedToBeScheduled(P)) ||
(GEP && GEP->getNumOperands() == 2);
})) {
- Align CommonAlignment = cast<LoadInst>(VL0)->getAlign();
- for (Value *V : VL)
- CommonAlignment =
- std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
+ Align CommonAlignment = computeCommonAlignment<LoadInst>(VL);
auto *VecTy = FixedVectorType::get(ScalarTy, VL.size());
if (TTI.isLegalMaskedGather(VecTy, CommonAlignment) &&
!TTI.forceScalarizeMaskedGather(VecTy, CommonAlignment))
@@ -7087,10 +7093,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
}
for (std::pair<unsigned, unsigned> P : ScatterVectorized) {
auto *LI0 = cast<LoadInst>(VL[P.first]);
- Align CommonAlignment = LI0->getAlign();
- for (Value *V : VL.slice(P.first + 1, VF - 1))
- CommonAlignment =
- std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
+ Align CommonAlignment =
+ computeCommonAlignment<LoadInst>(VL.slice(P.first + 1, VF - 1));
GatherCost += TTI.getGatherScatterOpCost(
Instruction::Load, LoadTy, LI0->getPointerOperand(),
/*VariableMask=*/false, CommonAlignment, CostKind, LI0);
@@ -8334,10 +8338,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
assert((E->State == TreeEntry::ScatterVectorize ||
E->State == TreeEntry::PossibleStridedVectorize) &&
"Unknown EntryState");
- Align CommonAlignment = LI0->getAlign();
- for (Value *V : UniqueValues)
- CommonAlignment =
- std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
+ Align CommonAlignment =
+ computeCommonAlignment<LoadInst>(UniqueValues.getArrayRef());
VecLdCost = TTI->getGatherScatterOpCost(
Instruction::Load, VecTy, LI0->getPointerOperand(),
/*VariableMask=*/false, CommonAlignment, CostKind);
@@ -11600,10 +11602,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
return E->VectorizedValue;
}
// Use the minimum alignment of the gathered loads.
- Align CommonAlignment = LI->getAlign();
- for (Value *V : E->Scalars)
- CommonAlignment =
- std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
+ Align CommonAlignment = computeCommonAlignment<LoadInst>(E->Scalars);
NewLI = Builder.CreateMaskedGather(VecTy, VecPtr, CommonAlignment);
}
Value *V = propagateMetadata(NewLI, E->Scalars);
More information about the llvm-commits
mailing list