[llvm] 5a3fd5f - [LoopVectorizer] Fix PR #65212: vectorization of reduction loop wasn't respecting original store alignment

Nuno Lopes via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 3 08:36:03 PDT 2023


Author: Nuno Lopes
Date: 2023-09-03T16:35:05+01:00
New Revision: 5a3fd5f3f5312a5af779c80480a575bde91d6871

URL: https://github.com/llvm/llvm-project/commit/5a3fd5f3f5312a5af779c80480a575bde91d6871
DIFF: https://github.com/llvm/llvm-project/commit/5a3fd5f3f5312a5af779c80480a575bde91d6871.diff

LOG: [LoopVectorizer] Fix PR #65212: vectorization of reduction loop wasn't respecting original store alignment

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/test/Transforms/LoopVectorize/reduction-align.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 03a5b08085b19c..d67763e041eb7d 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -3943,7 +3943,8 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
   // inside the loop, create the final store here.
   if (StoreInst *SI = RdxDesc.IntermediateStore) {
     StoreInst *NewSI =
-        Builder.CreateStore(ReducedPartRdx, SI->getPointerOperand());
+        Builder.CreateAlignedStore(ReducedPartRdx, SI->getPointerOperand(),
+                                   SI->getAlign());
     propagateMetadata(NewSI, SI);
 
     // If the reduction value is used in other places,

diff  --git a/llvm/test/Transforms/LoopVectorize/reduction-align.ll b/llvm/test/Transforms/LoopVectorize/reduction-align.ll
index df5fdc65a6bd5e..ff717af5136ffd 100644
--- a/llvm/test/Transforms/LoopVectorize/reduction-align.ll
+++ b/llvm/test/Transforms/LoopVectorize/reduction-align.ll
@@ -18,7 +18,7 @@ define void @fn(ptr %hbuf, ptr %ref, i32 %height) {
 ; CHECK-NEXT:    [[TMP0:%.*]] = load i16, ptr [[REF]], align 1
 ; CHECK-NEXT:    [[TMP1:%.*]] = load i16, ptr [[HBUF]], align 1
 ; CHECK-NEXT:    [[ADD:%.*]] = add i16 [[TMP1]], [[TMP0]]
-; CHECK-NEXT:    store i16 [[ADD]], ptr [[HBUF]], align 2
+; CHECK-NEXT:    store i16 [[ADD]], ptr [[HBUF]], align 1
 ; CHECK-NEXT:    [[INC]] = add i32 [[I]], 1
 ; CHECK-NEXT:    br label [[FOR_COND]]
 ; CHECK:       for.end:


        


More information about the llvm-commits mailing list