[llvm] [LoopIdiomVectorize] Recognize and transform minidx pattern (PR #144987)
Madhur Amilkanthwar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 16 01:18:51 PDT 2025
madhur13490 wrote:
> > > It's my understanding that the GVN improvement brings this into a form that we can at least in principle vectorize, even if it doesn't work yet. It's not either/or, we want both.
> >
> >
> > I am not sure if that is the right understanding. @fhahn do you think GVN (with a lot of work) optimized IR would or could be vectorizable?
>
> Yes, once the loads have been simplified by GVN we should be able to tackle this in LV
Thanks.
@fhahn @nikic
I am thinking aloud. If not GVN, then is there a place in LLVM where I can pattern match and "simplify" the loads?
```
%load1_ptr = getelementptr float, ptr %first_ptr, i64 %iv
%load1 = load float, ptr %load1_ptr, align 4
%index_sext = sext i32 %index to i64
%load2_ptr = getelementptr float, ptr %second_ptr, i64 %index_sext ; <--- load the c
%load2 = load float, ptr %load2_ptr, align 4
%cmp = fcmp contract olt float %load1, %load2
```
GCC loads the second value to a register and updates it when a minimum element is found. This is PRE to me but doing this in GVN is not feasible. Is there any other pass where I can achieve this?
FWIW, here is an equivalent C loop. https://godbolt.org/z/EcT6efd3x
GCC-generated code has a single load in the loop. Register `w4` is a temporary register used to hold the last MinIdx.
https://github.com/llvm/llvm-project/pull/144987
More information about the llvm-commits
mailing list