On Wed, 18 Mar 2026 11:57:52 GMT, Andrew Haley <[email protected]> wrote:
>>> Isn't _2. Avoid vectorizing MUL-heavy loops_ a code-quality bug in the >>> autovectorizer? It's only take one or two more registers to fix the >>> problem. Is this fix for 2 any more than a workaround for vectorization? >> >> @theRealAph Thanks for your insights. I agree. >> >> I’m currently working on a draft that improves the codegen for >> [longMulSimple](https://github.com/openjdk/jdk/blob/c5f288e2ae2ebe6ee4a0d39d91348f746bd0e353/test/micro/org/openjdk/bench/vm/compiler/VectorReduction2.java#L1035) >> to: >> >> ldr q17, [x1, #32] >> ldr q18, [x1, #16] >> ldr q19, [x1, #64] >> mul z17.d, p7/m, z17.d, z18.d >> ldr q18, [x1, #48] >> ldr q20, [x1, #96] >> mul z19.d, p7/m, z19.d, z18.d >> mul z17.d, p7/m, z17.d, z16.d >> ldr q16, [x1, #80] >> ldr q18, [x1, #128] >> mul z20.d, p7/m, z20.d, z16.d >> mul z19.d, p7/m, z19.d, z17.d >> ldr q16, [x1, #112] >> ldr q17, [x1, #160] >> mul z18.d, p7/m, z18.d, z16.d >> mul z20.d, p7/m, z20.d, z19.d >> ... >> >> The idea is to use GVN to transform: >> >> accu *= vector[i]; >> accu *= vector[i+1]; >> accu *= vector[i+2]; >> accu *= vector[i+3]; >> >> into >> >> vector[i] = vector[i] * vector[i+1]; >> vector[i+2] = vector[i+2] * vector[i+3]; >> accu *= vector[i]; >> accu *= vector[i+2]; >> >> This effectively reduces dependency chains and exposes more ILP. >> >> In my experiments, this transformation shows clear performance improvements, >> outperforming both the current vectorized version and even the scalar code >> in some cases. It should also generalize to other vector backends, and >> potentially to other reduction patterns **where strict ordering is not >> required**. >> >> Given that, I’m considering removing the “2. Avoid vectorizing MUL-heavy >> loops” logic from this patch and instead filing a separate JBS issue to >> implement this transformation more generally, since it’s no longer >> AArch64-specific. >> >> What do you think? Thanks. > >> Given that, I’m considering removing the “2. Avoid vectorizing MUL-heavy >> loops” logic from this patch and instead filing a separate JBS issue to >> implement this transformation more generally, since it’s no longer >> AArch64-specific. >> >> What do you think? Thanks. > > Yes, that's perfectly right. Thanks. Thanks for your reviewing! @theRealAph @eme64 I'll integrate it. ------------- PR Comment: https://git.openjdk.org/jdk/pull/30237#issuecomment-6856951236
