RFR: 8345485: C2 MergeLoads: merge adjacent array/native memory loads into larger load [v12]

kuaiwei duke at openjdk.org
Mon Apr 28 13:50:51 UTC 2025


On Tue, 22 Apr 2025 08:53:06 GMT, kuaiwei <duke at openjdk.org> wrote:

>> Also: I would change the name of the method if we keep it. It is really about checking down, i.e. that there is not other candidate below. Maybe `has_no_merge_load_combine_below`?
>> 
>> Ah, another example: We could have two merged loads that we OR:
>> 
>> int x = (... merge load pattern with OR ...);
>> int y = (... merge load pattern with OR ...);
>> int z = x | y;
>> 
>> It would be nice if this could be optimized too, and we should have an IR test for it :)
>
> Yes, it's the limit of this implementation. I need to find the last `combine` node which can be replaced with merged load. But if it's used by other `Or` operator. So far I can not find a good way to distinguish these two cases.
> I may add a new `checked` flag for combine operator. For case like:
> 
> int x = (... merge load pattern with OR ...);
> int y = (... merge load pattern with OR ...);
> int z = x | y;
> 
> When IGVN check the `Or` in `x | y`, it's the last one of combine nodes. But it will fail to merge because `collect_merge_list` can not find a related `Load` for it. And I can mark it as `checked`. So when IGVN check the `Or` nodes in line 1 and line2. it will find the next `Or` is checked and get the right one.
> 
> Do you think if it is doable? Other suggestion is appreciated. Thanks.

I added a flag, `_merge_memops_checked`  in `AddNode`. It will be checked when search `MergePrimitiveLoads::has_no_merge_load_combine_below()` . So these cases can be handled. And tests are added.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24023#discussion_r2063697381


More information about the hotspot-compiler-dev mailing list