[llvm] [LoopIdiomVectorize] Recognize and transform minidx pattern (PR #144987)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 10 04:09:19 PDT 2025


https://github.com/fhahn commented:

> > @sjoerdmeijer See also some related discussion on #141556. My takeaway from that was that this really needs a GVN improvement first.
> 
> There's quite some discussion going on there, but I think you're referring to this comment:
> 
> > but it feels like the focus we should be trying to optimise the scalar IR before we attempt vectorisation. There are no stores in the loop and the bounds seem to be well-known.
> 
> My understanding is that there's two ways to optimise this:
> 
>     * GVN, which is the scalar optimisation we are talking about it. GCC is doing this PRE, and that's how this came up, as a case where we are behind.
> 
>     * But GVN and NewGVN is a difficult story, and then we found that vectorisation is actually the much better approach. The vectorisation performance gain is much bigger than the gain we get from PRE and GVN.


W/o PRE we won't be able to handle this in LV. But we at least need to implicitly perform PRE here in LoopIdiom, so it should also be able to implement this form of PRE separately.

I've not looked at the patch in detail, but on a high level, 
* it looks like there are a number of legality checks missing, e.g. it doesn't check if there are any potential memory writes in the loop, and possibly misses checks if PRE is valid
* hard codes scalable vector codegen
* doesn't check costs of generated vector code vs original scalar loop
* hard codes check for branch condition (just supporting ICMP_SGT)

I am not sure, but I suspect addressing all the above will add significant complexity & duplication compared to LV.

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


More information about the llvm-commits mailing list