On Mon, 16 Nov 2026 10:54:42 GMT, Fei Gao <[email protected]> wrote:

>Yes, I believe so. We’re also planning to propose some optimizations for 
>min/max reductions in the near future.

Good to know this. Thanks!

> That sounds like a good idea. For add reductions, we can easily distinguish 
> between Vector API and auto-vectorization using requires_strict_order(), but 
> it’s not as straightforward for other reduction opcodes.
>
> I’m wondering whether we should add a field to the existing reduction IR 
> nodes, similar to what we did for add reductions, or introduce a separate set 
> of IR nodes for Vector API reductions. Both approaches would allow us to 
> distinguish between the two and optimize them independently.

Adding a new field is not an optimal to me, especially for FP add/mul 
reductions. This increases the code complexity. In addition, compiler usually 
need to co-work it with the `requires_strict_order` flag. An ideal way is 
defining two kinds of reduction IRs, one accept a scalar input while another 
not. For OPs that accept the scalar input, it usually requires the strict order 
when basic type is floating-point. This kind of reductions can be used for 
auto-vectorization. But for another kind of IRs that do not need the scalar 
input, the computation order is relaxed which matches the Vector API 
requirements. 
This is an example in LLVM, which defines two kinds of FP add/mul reduction IRs 
in backend: 
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/CodeGen/ISDOpcodes.h#L1516.
 Maybe we can use it as a reference. 

I know that changing IRs for existing ones need additional cost, since we need 
to go through all the mid-end and back-end code on all architectures.  I'd 
appreciate if @eme64 or @iwanowww could give any feedback or suggestions on 
this!

BTW, There is a PR https://github.com/openjdk/jdk/pull/33335 which splits the 
vector IR mapping for Vector API and auto-vectorization. I think this is a good 
start for those OPs that Vector API and auto-vectorization behave differently.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/33319#issuecomment-6940910895

Reply via email to