@@ -3869,6 +3869,15 @@ static bool arePointersCompatible(Value *Ptr1, Value *Ptr2,
3869
3869
.getOpcode());
3870
3870
}
3871
3871
3872
+ /// Calculates minimal alignment as a common alignment.
3873
+ template <typename T>
3874
+ static Align computeCommonAlignment(ArrayRef<Value *> VL) {
3875
+ Align CommonAlignment = cast<T>(VL.front())->getAlign();
3876
+ for (Value *V : VL.drop_front())
3877
+ CommonAlignment = std::min(CommonAlignment, cast<T>(V)->getAlign());
3878
+ return CommonAlignment;
3879
+ }
3880
+
3872
3881
/// Checks if the given array of loads can be represented as a vectorized,
3873
3882
/// scatter or just simple gather.
3874
3883
static LoadsState canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
@@ -3939,10 +3948,7 @@ static LoadsState canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
3939
3948
return (IsSorted && !GEP && doesNotNeedToBeScheduled(P)) ||
3940
3949
(GEP && GEP->getNumOperands() == 2);
3941
3950
})) {
3942
- Align CommonAlignment = cast<LoadInst>(VL0)->getAlign();
3943
- for (Value *V : VL)
3944
- CommonAlignment =
3945
- std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
3951
+ Align CommonAlignment = computeCommonAlignment<LoadInst>(VL);
3946
3952
auto *VecTy = FixedVectorType::get(ScalarTy, VL.size());
3947
3953
if (TTI.isLegalMaskedGather(VecTy, CommonAlignment) &&
3948
3954
!TTI.forceScalarizeMaskedGather(VecTy, CommonAlignment))
@@ -7087,10 +7093,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
7087
7093
}
7088
7094
for (std::pair<unsigned, unsigned> P : ScatterVectorized) {
7089
7095
auto *LI0 = cast<LoadInst>(VL[P.first]);
7090
- Align CommonAlignment = LI0->getAlign();
7091
- for (Value *V : VL.slice(P.first + 1, VF - 1))
7092
- CommonAlignment =
7093
- std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
7096
+ Align CommonAlignment =
7097
+ computeCommonAlignment<LoadInst>(VL.slice(P.first + 1, VF - 1));
7094
7098
GatherCost += TTI.getGatherScatterOpCost(
7095
7099
Instruction::Load, LoadTy, LI0->getPointerOperand(),
7096
7100
/*VariableMask=*/false, CommonAlignment, CostKind, LI0);
@@ -8334,10 +8338,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
8334
8338
assert((E->State == TreeEntry::ScatterVectorize ||
8335
8339
E->State == TreeEntry::PossibleStridedVectorize) &&
8336
8340
"Unknown EntryState");
8337
- Align CommonAlignment = LI0->getAlign();
8338
- for (Value *V : UniqueValues)
8339
- CommonAlignment =
8340
- std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
8341
+ Align CommonAlignment =
8342
+ computeCommonAlignment<LoadInst>(UniqueValues.getArrayRef());
8341
8343
VecLdCost = TTI->getGatherScatterOpCost(
8342
8344
Instruction::Load, VecTy, LI0->getPointerOperand(),
8343
8345
/*VariableMask=*/false, CommonAlignment, CostKind);
@@ -11600,10 +11602,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
11600
11602
return E->VectorizedValue;
11601
11603
}
11602
11604
// Use the minimum alignment of the gathered loads.
11603
- Align CommonAlignment = LI->getAlign();
11604
- for (Value *V : E->Scalars)
11605
- CommonAlignment =
11606
- std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
11605
+ Align CommonAlignment = computeCommonAlignment<LoadInst>(E->Scalars);
11607
11606
NewLI = Builder.CreateMaskedGather(VecTy, VecPtr, CommonAlignment);
11608
11607
}
11609
11608
Value *V = propagateMetadata(NewLI, E->Scalars);
0 commit comments