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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 14 14:48:27 PDT 2025


fhahn wrote:

> > WDYT?
> 
> Thanks! Yes, this is roughly what I hoped. But I think we can achieve this without introducing new recurrence kinds.
> 
> I suggest separating recurrence and reduction patterns. That is, first we identify the recurrence, and then determine whether this recurrence is a reduction. In RecurrenceDescriptor, we can temporarily add a bool isReduction to distinguish the two. This approach may involve significant changes, with the final goal of replacing the existing reduction detection method. But we can start by trying it on min/max reductions.
> 

I'll try that thanks. One thing I am a bit concerned is how we best make sure that all users perform the necessary extra checks.

> If you think this approach is feasible, I can split `RecurrenceDescriptor::tryToGetMinMaxRecurrenceChain` in #141467 and make it a separate NFC patch, partially refactoring the min/max reduction detection. Then you can continue developing the min/max with index idiom based on the NFC patch. What do you think?

I tried to see if we can completely replace min/max reduction identification with an approach similar to the current changes in the patch over the last week. It seems feasible, and avoid re-analyzing the same backedge-value/phi chain for each min/max recurrence descriptor: https://github.com/llvm/llvm-project/pull/163460

Not sure if supporting other recurrence kinds would add more complexity.

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


More information about the llvm-commits mailing list