Skip to content

Commit 5a3fd5f

Browse files
committed
[LoopVectorizer] Fix PR #65212: vectorization of reduction loop wasn't respecting original store alignment
1 parent 335a9bc commit 5a3fd5f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3943,7 +3943,8 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
39433943
// inside the loop, create the final store here.
39443944
if (StoreInst *SI = RdxDesc.IntermediateStore) {
39453945
StoreInst *NewSI =
3946-
Builder.CreateStore(ReducedPartRdx, SI->getPointerOperand());
3946+
Builder.CreateAlignedStore(ReducedPartRdx, SI->getPointerOperand(),
3947+
SI->getAlign());
39473948
propagateMetadata(NewSI, SI);
39483949

39493950
// If the reduction value is used in other places,

llvm/test/Transforms/LoopVectorize/reduction-align.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ define void @fn(ptr %hbuf, ptr %ref, i32 %height) {
1818
; CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr [[REF]], align 1
1919
; CHECK-NEXT: [[TMP1:%.*]] = load i16, ptr [[HBUF]], align 1
2020
; CHECK-NEXT: [[ADD:%.*]] = add i16 [[TMP1]], [[TMP0]]
21-
; CHECK-NEXT: store i16 [[ADD]], ptr [[HBUF]], align 2
21+
; CHECK-NEXT: store i16 [[ADD]], ptr [[HBUF]], align 1
2222
; CHECK-NEXT: [[INC]] = add i32 [[I]], 1
2323
; CHECK-NEXT: br label [[FOR_COND]]
2424
; CHECK: for.end:

0 commit comments

Comments
 (0)