[llvm] 7ea1fa5 - [LV] Skip FindLast reductions in collectInLoopReductions.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 22 13:51:05 PST 2026


Author: Florian Hahn
Date: 2026-01-22T21:49:52Z
New Revision: 7ea1fa591abc28df2596781c5d7be67cf92f6ed3

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

LOG: [LV] Skip FindLast reductions in collectInLoopReductions.

FindLast in-loop reductions are not supported, similarly to FindLastIV
reductions. Skip them in collectInLoopReductions, to avoid a crash for
loops with FindLast reductions and in-loop reductions preferred.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/test/Transforms/LoopVectorize/find-last.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 2caf711b41734..c213d2204ab34 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6670,7 +6670,8 @@ void LoopVectorizationCostModel::collectInLoopReductions() {
     // In-loop AnyOf and FindIV reductions are not yet supported.
     RecurKind Kind = RdxDesc.getRecurrenceKind();
     if (RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) ||
-        RecurrenceDescriptor::isFindIVRecurrenceKind(Kind))
+        RecurrenceDescriptor::isFindIVRecurrenceKind(Kind) ||
+        RecurrenceDescriptor::isFindLastRecurrenceKind(Kind))
       continue;
 
     // If the target would prefer this reduction to happen "in-loop", then we

diff  --git a/llvm/test/Transforms/LoopVectorize/find-last.ll b/llvm/test/Transforms/LoopVectorize/find-last.ll
index 7a0520cf3b221..59811eec8b298 100644
--- a/llvm/test/Transforms/LoopVectorize/find-last.ll
+++ b/llvm/test/Transforms/LoopVectorize/find-last.ll
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s | FileCheck %s
+; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -prefer-inloop-reductions -S %s | FileCheck %s
 
 ; Test vectorization of a "find last" pattern where a scalar value is
 ; conditionally updated based on comparing elements from two arrays.


        


More information about the llvm-commits mailing list