[PATCH] D103419: [VectorCombine] Fix alignment in single element store
Qiu Chaofan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 9 23:31:28 PDT 2021
qiucf updated this revision to Diff 351074.
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,7 @@
ret void
}
+; To verify align here is narrowed to scalar store size
define void @insert_store_nonconst_large_alignment(<4 x i32>* %q, i32 zeroext %s, i32 %idx) {
; CHECK-LABEL: @insert_store_nonconst_large_alignment(
; CHECK-NEXT: entry:
@@ -148,7 +149,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[IDX:%.*]], 2
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds <8 x i64>, <8 x i64>* [[Q:%.*]], i32 0, i32 [[IDX]]
-; CHECK-NEXT: store i64 [[S:%.*]], i64* [[TMP1]], align 4
+; CHECK-NEXT: store i64 [[S:%.*]], i64* [[TMP1]], align 8
; CHECK-NEXT: ret void
;
%cmp = icmp ult i32 %idx, 2
@@ -180,7 +181,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[IDX:%.*]], 2
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds <8 x i64>, <8 x i64>* [[Q:%.*]], i32 0, i32 [[IDX]]
-; CHECK-NEXT: store i64 [[S:%.*]], i64* [[TMP1]], align 2
+; CHECK-NEXT: store i64 [[S:%.*]], i64* [[TMP1]], align 4
; CHECK-NEXT: ret void
;
%cmp = icmp ult i32 %idx, 2
Index: llvm/lib/Transforms/Vectorize/VectorCombine.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -831,8 +831,15 @@
Builder.Insert(GEP);
StoreInst *NSI = Builder.CreateStore(NewElement, GEP);
NSI->copyMetadata(*SI);
- if (SI->getAlign() < NSI->getAlign())
- NSI->setAlignment(SI->getAlign());
+ 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);
replaceValue(I, *NSI);
// Need erasing the store manually.
I.eraseFromParent();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103419.351074.patch
Type: text/x-patch
Size: 2675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210610/6758428f/attachment.bin>
More information about the llvm-commits
mailing list