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

Fei Gao fgao at openjdk.org
Fri Jan 16 09:33:15 UTC 2026


On Wed, 14 Jan 2026 14:47:06 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> Fei Gao has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 13 commits:
>> 
>>  - Fix build failure after rebasing and address review comments
>>  - Merge branch 'master' into optimize-atomic-post
>>  - Fixed new test failures after rebasing and refined parts of the code to address review comments
>>  - Merge branch 'master' into optimize-atomic-post
>>  - Merge branch 'master' into optimize-atomic-post
>>  - Clean up comments for consistency and add spacing for readability
>>  - Fix some corner case failures and refined part of code
>>  - Merge branch 'master' into optimize-atomic-post
>>  - Refine ascii art, rename some variables and resolve conflicts
>>  - Merge branch 'master' into optimize-atomic-post
>>  - ... and 3 more: https://git.openjdk.org/jdk/compare/a8552243...ab1de504
>
> src/hotspot/share/opto/loopTransform.cpp line 1464:
> 
>> 1462:     // We try to look up target phi from all uses of node 'iv_after_main'.
>> 1463:     drain_input = find_merge_phi_for_vectorized_drain(iv_after_main, main_merge_region);
>> 1464:   }
> 
> What is the if for here? Why do we need that condition?
> Ah, I suppose if `iv_after_main` is not on the backedge, it is in the main-loop body, right?
> Still, I don't see through yet ... can you clarify?

As explained above, only when `main_phi->in(LoopNode::LoopBackControl)` is already in the main-exit block can we find an existing valid merge phi via its uses. Otherwise, `drain_input` will remain `nullptr` at this point, so this `if` check doesn’t add much value.

It should be safe to remove it.

> src/hotspot/share/opto/loopTransform.cpp line 1491:
> 
>> 1489:       // Remove the new phi from the graph and use the hit
>> 1490:       _igvn.remove_dead_node(drain_input);
>> 1491:       drain_input = hit;
> 
> Does this actually ever happen? Would we not have expected that `find_merge_phi_for_vectorized_drain` would have succeeded?

Agreed. It’s safe to remove this part of the code.

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

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


More information about the hotspot-compiler-dev mailing list