RFR: 8307084: C2: Vectorized drain loop is not executed for some small trip counts [v3]

Fei Gao fgao at openjdk.org
Wed Nov 12 12:48:38 UTC 2025


On Tue, 11 Nov 2025 15:33:57 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> test/micro/org/openjdk/bench/vm/compiler/VectorThroughputForIterationCount.java line 225:
>> 
>>> 223:         for (int i = startIndex; i < startIndex + length; i++) {
>>> 224:             c[i] = a[i] + b[i];
>>> 225:         }
>> 
>> You could forceinline them, just for good measure. Up to you.
>
> Wait, you are doing some kind of special warmup above. Why? Do you maybe NOT want the methods to inline? Any other reason for the warmup?

If I understand correctly, when `ITERATION_COUNT` is set to a fixed value, all loop optimizations will know the loop iteration count from profiling. Without a special warm-up phase, the main loop is unlikely to be auto-vectorized for these small iteration counts, because [policy_unroll()](https://github.com/openjdk/jdk/blob/400a83da893f5fc285a175b63a266de21e93683c/src/hotspot/share/opto/loopTransform.cpp#L960) in C2 always attempts to generate code that is optimal for the current trip count based on profiling information. It may decide not to auto-vectorize, or even remove the loop entirely and keep only some scalar nodes. As a result, we can’t observe the potential effects of this patch.

The special warm-up phase would instead trigger auto-vectorization and full unrolling. I suppose this patch takes effect in scenarios where certain Java loops have already been compiled with auto-vectorization and unrolling, and are later used to process data with smaller array sizes. What do you think?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22629#discussion_r2518155225


More information about the hotspot-compiler-dev mailing list