[PATCH] D103419: [VectorCombine] Fix alignment in single element store
Qiu Chaofan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 1 08:37:02 PDT 2021
qiucf updated this revision to Diff 348984.
qiucf added a comment.
Add another test (first..)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103419/new/
https://reviews.llvm.org/D103419
Files:
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
llvm/test/Transforms/VectorCombine/load-insert-store.ll
Index: llvm/test/Transforms/VectorCombine/load-insert-store.ll
===================================================================
--- llvm/test/Transforms/VectorCombine/load-insert-store.ll
+++ llvm/test/Transforms/VectorCombine/load-insert-store.ll
@@ -20,7 +20,7 @@
; CHECK-LABEL: @insert_store_i16_align1(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds <8 x i16>, <8 x i16>* [[Q:%.*]], i32 0, i32 3
-; CHECK-NEXT: store i16 [[S:%.*]], i16* [[TMP0]], align 1
+; CHECK-NEXT: store i16 [[S:%.*]], i16* [[TMP0]], align 2
; CHECK-NEXT: ret void
;
entry:
@@ -125,6 +125,19 @@
ret void
}
+define void @nonconst_large_alignment(<8 x i32>* %q, i32 zeroext %s, i32 %idx) {
+; CHECK-LABEL: @nonconst_large_alignment(
+; CHECK-NEXT: [[I:%.*]] = load <8 x i32>, <8 x i32>* [[Q:%.*]], align 128
+; CHECK-NEXT: [[VECINS:%.*]] = insertelement <8 x i32> [[I]], i32 [[S:%.*]], i32 [[IDX:%.*]]
+; CHECK-NEXT: store <8 x i32> [[VECINS]], <8 x i32>* [[Q]], align 128
+; CHECK-NEXT: ret void
+;
+ %i = load <8 x i32>, <8 x i32>* %q, align 128
+ %vecins = insertelement <8 x i32> %i, i32 %s, i32 %idx
+ store <8 x i32> %vecins, <8 x i32>* %q, align 128
+ ret void
+}
+
define void @insert_store_nonconst_index_known_valid_by_assume(<16 x i8>* %q, i8 zeroext %s, i32 %idx) {
; CHECK-LABEL: @insert_store_nonconst_index_known_valid_by_assume(
; CHECK-NEXT: entry:
Index: llvm/lib/Transforms/Vectorize/VectorCombine.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -831,8 +831,14 @@
Builder.Insert(GEP);
StoreInst *NSI = Builder.CreateStore(NewElement, GEP);
NSI->copyMetadata(*SI);
- if (SI->getAlign() < NSI->getAlign())
- NSI->setAlignment(SI->getAlign());
+ Align NewAlignment(1);
+ if (auto *C = dyn_cast<ConstantInt>(Idx)) {
+ NewAlignment = std::max(SI->getAlign(), Load->getAlign());
+ NewAlignment = commonAlignment(
+ NewAlignment,
+ C->getZExtValue() * DL.getTypeStoreSize(NewElement->getType()));
+ }
+ NSI->setAlignment(NewAlignment);
replaceValue(I, *NSI);
// Need erasing the store manually.
I.eraseFromParent();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103419.348984.patch
Type: text/x-patch
Size: 2285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210601/4a467b16/attachment.bin>
More information about the llvm-commits
mailing list