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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 14:17:44 PDT 2025


fhahn wrote:

> I took the time to look at more examples. From what I’ve seen so far, deferring the decision to use the first or last index to VPlan seems beneficial. However, deferring the identification of min/max recurrence phis doesn’t appear to offer any clear advantage.
> 
> Would it be possible to still identify min/max recurrences during the legality stage, but postpone validating the interaction between the recurrence phi and FindIV until VPlan construction?
> 

Thanks for taking a look. I don't think we can identifiy the min/max reductions using the plain min/max recurrence kinds, as they will have other in-loop users. But what we could do is detect min/max with multiple in-loop uses, and legalize them later if their other in-loop user is a FindLastIV. I updated the PR to do so using (U|S)Min/MaxMultiUse recurrence kinds.

That means we don't have to detect the min/max recurrence in VPlan, we just have to legalize them.


> Also, I noticed that by deferring recurrence detection to VPlan, we now need to check more types of recipes. This appears to introduce additional complexity.

Yep the detection is now done in IVDescriptors directly. It doesn't seem to save a lot of code, but limits the cases we allow with 'illegal' recurrence kinds.

WDYT?

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


More information about the llvm-commits mailing list