[llvm] [LV] Vectorize selecting last IV of min/max element. (PR #141431)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 20 05:26:52 PST 2025


================
@@ -214,6 +214,51 @@ static bool checkOrderedReduction(RecurKind Kind, Instruction *ExactFPMathInst,
   return true;
 }
 
+/// Returns true if \p Phi is a min/max reduction matching \p Kind where \p Phi
+/// is used in the loop outside the reduction chain. This is common for
+static bool isMinMaxReductionWithLoopUsersOutsideReductionChain(
+    PHINode *Phi, RecurKind Kind, Loop *TheLoop, RecurrenceDescriptor &RedDes) {
+  BasicBlock *Latch = TheLoop->getLoopLatch();
+  if (!Latch)
+    return false;
+  assert(Phi->getNumIncomingValues() == 2 &&
+         "phi must have exactly 2 incoming values");
+  Value *Inc = Phi->getIncomingValueForBlock(Latch);
+  if (Phi->hasOneUse() ||
+      !RecurrenceDescriptor::isIntMinMaxRecurrenceKind(Kind))
----------------
ayalz wrote:

nit: can slightly simplify by sinking to default and hoisting from m_OneUse below
```suggestion
  if (Phi->hasOneUse() || !Inc->hasOneUse())
```

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


More information about the llvm-commits mailing list