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

Ryan Buchner via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 2 11:36:24 PST 2025


https://github.com/bababuck updated https://github.com/llvm/llvm-project/pull/165913

>From b6a8861f154293913fddc12b2f2bc63a5e20a4e0 Mon Sep 17 00:00:00 2001
From: bababuck <buchner.ryan at gmail.com>
Date: Fri, 31 Oct 2025 11:09:42 -0700
Subject: [PATCH 1/2] [LV] Add test for failing reduction remark case

Issue #165359.

https://godbolt.org/z/z1P6Wxj7d
---
 .../LoopVectorize/AArch64/bug165359.ll        | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 llvm/test/Transforms/LoopVectorize/AArch64/bug165359.ll

diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/bug165359.ll b/llvm/test/Transforms/LoopVectorize/AArch64/bug165359.ll
new file mode 100644
index 0000000000000..99cd8ec54d361
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/bug165359.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -passes=loop-vectorize -S -pass-remarks=loop-vectorize
+
+target triple = "aarch64-unknown-linux-gnu"
+
+define void @reduce_fail(i64 %loop_count, ptr %ptr0, ptr noalias %ptr1) #0 {
+entry:
+  %d1 = load double, ptr %ptr1
+  %d0 = load double, ptr %ptr0
+  br label %loop
+
+loop:
+  %acc0 = phi double [ %fadd0, %loop ], [ %d0, %entry ]
+  %counter = phi i64 [ %counter_updated, %loop ], [ %loop_count, %entry ]
+  %fadd0 = fadd double %acc0, %d1
+  %counter_updated = add nsw i64 %counter, -1
+  %exit_cond = icmp samesign ugt i64 %counter, 1
+  br i1 %exit_cond, label %loop, label %loopexit
+
+loopexit:
+  store double %fadd0, ptr %ptr1
+  ret void
+}
+
+attributes #0 = { "target-features"="+sve" }
\ No newline at end of file

>From 0b5ef277b17f60a24f52f88c9dcae667f634a61b Mon Sep 17 00:00:00 2001
From: bababuck <buchner.ryan at gmail.com>
Date: Sun, 2 Nov 2025 11:22:42 -0800
Subject: [PATCH 2/2] [LV] Update
 LoopVectorizationPlanner::emitInvalidCostRemarks to handle reduction plans

Issue #165359.

TypeSwitch did not handle the case of retrieving the opcode from a VPRedutionPlan type.
---
 llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 25bf49db0e073..17c70c7295301 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -3971,6 +3971,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 different, or if there are no other pairs,



More information about the llvm-commits mailing list