[llvm] [LV] Add support for cmp reductions with decreasing IVs. (PR #140451)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 27 05:32:05 PDT 2025


================
@@ -1227,9 +1227,12 @@ Value *llvm::createFindLastIVReduction(IRBuilderBase &Builder, Value *Src,
                                        RecurKind RdxKind, Value *Start,
                                        Value *Sentinel) {
   bool IsSigned = RecurrenceDescriptor::isSignedRecurrenceKind(RdxKind);
-  Value *MaxRdx = Src->getType()->isVectorTy()
-                      ? Builder.CreateIntMaxReduce(Src, IsSigned)
-                      : Src;
+  Value *MaxRdx =
+      Src->getType()->isVectorTy()
+          ? (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RdxKind)
+                 ? Builder.CreateIntMaxReduce(Src, IsSigned)
+                 : Builder.CreateIntMinReduce(Src, IsSigned))
+          : Src;
----------------
artagnon wrote:

```suggestion
 Value *MinMaxRdx = RecurrenceDescriptor::isFindLastIVRecurrenceKind(RdxKind)
                 ? Builder.CreateIntMaxReduce(Src, IsSigned)
                 : Builder.CreateIntMinReduce(Src, IsSigned);
  Value *Rdx = Src->getType()->isVectorTy() ? MinMaxRdx : Src;
```

https://github.com/llvm/llvm-project/pull/140451


More information about the llvm-commits mailing list