[PATCH] D103419: [VectorCombine] Fix alignment in single element store
Qiu Chaofan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 31 10:40:44 PDT 2021
qiucf created this revision.
qiucf added reviewers: lebedev.ri, fhahn, spatel, efriedma, hgreving.
Herald added a subscriber: hiraditya.
qiucf requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This concern was raised in D98240 <https://reviews.llvm.org/D98240>. It's a miscompile and thanks for comments from @lebedev.ri.
Repository:
rG LLVM Github Monorepo
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:
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.348837.patch
Type: text/x-patch
Size: 1469 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210531/616f8dc0/attachment.bin>
More information about the llvm-commits
mailing list