[llvm] abc0e01 - [NFC][VectorCombine] Extract computeAlignmentAfterScalarization() helper function
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 11 02:47:41 PDT 2021
Author: Roman Lebedev
Date: 2021-06-11T12:47:09+03:00
New Revision: abc0e0125cc54426cd2e89080b87b706c3385173
URL: https://github.com/llvm/llvm-project/commit/abc0e0125cc54426cd2e89080b87b706c3385173
DIFF: https://github.com/llvm/llvm-project/commit/abc0e0125cc54426cd2e89080b87b706c3385173.diff
LOG: [NFC][VectorCombine] Extract computeAlignmentAfterScalarization() helper function
Added:
Modified:
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index c184c8a08fd0..affe4e82eb57 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -788,6 +788,19 @@ static bool canScalarizeAccess(FixedVectorType *VecTy, Value *Idx,
return ValidIndices.contains(IdxRange);
}
+/// The memory operation on a vector of \p ScalarType had alignment of
+/// \p VectorAlignment. Compute the maximal, but conservatively correct,
+/// alignment that will be valid for the memory operation on a single scalar
+/// element of the same type with index \p Idx.
+static Align computeAlignmentAfterScalarization(Align VectorAlignment,
+ Type *ScalarType, Value *Idx,
+ const DataLayout &DL) {
+ if (auto *C = dyn_cast<ConstantInt>(Idx))
+ return commonAlignment(VectorAlignment,
+ C->getZExtValue() * DL.getTypeStoreSize(ScalarType));
+ return commonAlignment(VectorAlignment, DL.getTypeStoreSize(ScalarType));
+}
+
// Combine patterns like:
// %0 = load <4 x i32>, <4 x i32>* %a
// %1 = insertelement <4 x i32> %0, i32 %b, i32 1
@@ -831,15 +844,10 @@ bool VectorCombine::foldSingleElementStore(Instruction &I) {
Builder.Insert(GEP);
StoreInst *NSI = Builder.CreateStore(NewElement, GEP);
NSI->copyMetadata(*SI);
- Align NewAlignment = std::max(SI->getAlign(), Load->getAlign());
- if (auto *C = dyn_cast<ConstantInt>(Idx))
- NewAlignment = commonAlignment(
- NewAlignment,
- C->getZExtValue() * DL.getTypeStoreSize(NewElement->getType()));
- else
- NewAlignment = commonAlignment(
- NewAlignment, DL.getTypeStoreSize(NewElement->getType()));
- NSI->setAlignment(NewAlignment);
+ Align ScalarOpAlignment = computeAlignmentAfterScalarization(
+ std::max(SI->getAlign(), Load->getAlign()), NewElement->getType(), Idx,
+ DL);
+ NSI->setAlignment(ScalarOpAlignment);
replaceValue(I, *NSI);
// Need erasing the store manually.
I.eraseFromParent();
More information about the llvm-commits
mailing list