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

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 16 10:25:48 PDT 2025


madhur13490 wrote:


> In that form, I think the pattern is a lot more straightforward, and I feel like it should be possible to extend GVN load PRE to handle it. GVN / MDA already support select dependences for the general load of select pattern. I think what is missing here is handling this case of a phi-translated select.

I was hoping for a non-GVN solution here :) 

The select case currently handled by GVN is for pointer selects; two loaded values are selected and one of them is made available. In this case, it is the index. Hypothetically, if GVN optimizes this, then the transformed would look like 
 https://llvm.godbolt.org/z/YbscY3jo6. `@tgt` is the function GVN should produce.

We need to 
1. Hoist the load.
2. Insert new PHI for the minimum value.
3. Insert a new select for selecting the min value.

Taking a pause and reiterating. While this requires work in GVN and LV by @fhann, I still think this patch should proceed as this is available today and ready to use. We are not sure about the unknowns in GVN and LV, and how they will pan out. 

Please note, this patch offers 4x speedup for the pattern. 


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


More information about the llvm-commits mailing list