[llvm] a04c6b5 - [LV] Update LoopVectorizationPlanner::emitInvalidCostRemarks to handle reduction plans (#165913)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 13 08:12:44 PST 2025


Author: Ryan Buchner
Date: 2025-11-13T06:12:40-10:00
New Revision: a04c6b5512bf091b4eec6c4f7dbfaaf44b290906

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

LOG: [LV] Update LoopVectorizationPlanner::emitInvalidCostRemarks to handle reduction plans (#165913)

The TypeSwitch for extracting the Opcode now handles the `VPReductionRecipe` case.

Fixes #165359.

Added: 
    llvm/test/Transforms/LoopVectorize/AArch64/bug165359.ll

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 835b0995cc4fc..f4629d22002dc 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4018,6 +4018,9 @@ void LoopVectorizationPlanner::emitInvalidCostRemarks(
             .Case<VPInterleaveRecipe>([](const VPInterleaveRecipe *R) {
               return R->getStoredValues().empty() ? Instruction::Load
                                                   : Instruction::Store;
+            })
+            .Case<VPReductionRecipe>([](const auto *R) {
+              return RecurrenceDescriptor::getOpcode(R->getRecurrenceKind());
             });
 
     // If the next recipe is 
diff erent, or if there are no other pairs,

diff  --git a/llvm/test/Transforms/LoopVectorize/AArch64/bug165359.ll b/llvm/test/Transforms/LoopVectorize/AArch64/bug165359.ll
new file mode 100644
index 0000000000000..87320c547a757
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/bug165359.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -passes=loop-vectorize -S -pass-remarks-analysis=loop-vectorize -disable-output &> %t
+; RUN: cat %t | FileCheck --check-prefix=CHECK-REMARKS %s
+
+; CHECK-REMARKS: remark: <unknown>:0:0: Recipe with invalid costs prevented vectorization at VF=(vscale x 1): fadd
+
+target triple = "aarch64-unknown-linux-gnu"
+
+define double @reduce_fail(i64 %loop_count, double %d0, ptr %ptr1) #0 {
+entry:
+  %d1 = load double, ptr %ptr1
+  br label %loop
+
+loop:
+  %acc0 = phi double [ %fadd0, %loop ], [ %d0, %entry ]
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+  %fadd0 = fadd double %acc0, %d1
+  %iv.next = add nsw nuw i64 %iv, 1
+  %exit_cond = icmp eq i64 %iv.next, %loop_count
+  br i1 %exit_cond, label %loopexit, label %loop
+
+loopexit:
+  ret double %fadd0
+}
+
+attributes #0 = { "target-features"="+sve" }


        


More information about the llvm-commits mailing list