RFR: JDK-8322854: Incorrect rematerialization of scalar replaced objects in C2

Cesar Soares Lucas cslucas at openjdk.org
Mon Jan 29 18:48:26 UTC 2024


On Sat, 27 Jan 2024 21:07:22 GMT, Vladimir Kozlov <kvn at openjdk.org> wrote:

>> Current implementation of `PhaseMacroExpand::value_from_mem` returns `return _igvn.zerocon(ft);` when it hits a sentinel while searching for a memory operation on a given slice. One of the sentinels is the memory input of the allocate node origin of the memory slice. Therefore, `value_from_mem` may return `zeroconf(ft)` if `sfpt_mem` is the same memory edge used by the Allocate node origin of the memory slice being traversed.
>> 
>> The scalar replacement implementation uses `value_from_mem` during creation of metadata describing object scalar replaced (see `PhaseMacroExpand::create_scalarized_object_description`). The `create_scalarized_object_description` method is also used as part of RAM optimization implementation. The RAM optimization targets Phi nodes and therefore a memory graph loop created by a _memory phi_ node is possible to seen as part of the transformation. See image below:
>> 
>> <img src="https://github.com/openjdk/jdk/assets/2249648/288681b7-4461-41ea-8dab-bbaebac4727f" height="500" />
>> 
>> This pattern doesn't show up when scalarizing objects that don't participate in allocation merges. 
>> 
>> To fix the issue I changed the code in `value_from_mem` to instead of using the _input_ memory edge of the Allocate as a stop condition, it will now use the projection memory edge of the Allocate.
>> 
>> Tested locally on windows, mac and linux x86_64 with JTREG tier1-3 and didn't observe any regression.
>
> @JohnTortugo do I understand correctly that we have a loop and the Phi node we are processing is memory input to Allocation?
> 
> If I recall correctly, the only way we get to `alloc->in(Mem)` if there is no `Initialize` node  (there are such cases).  In such case `Allocation` may not have memory out projection.
> 
> Why your case see `alloc->in(Mem)`?  
> 
> What other `Phi` node's edge points to?
> 
> I am concern if you use projection memory edge of the Allocate you may miss/skip it during search and start searching unrelated path.

@vnkozlov - Thank you for letting me know about those edge cases. I'll investigate what happens in those situations. 
I created this Gist to demonstrate the problem: https://gist.github.com/JohnTortugo/2e6f183b0bf1e465dc871246b410ef4c

@TobiHartmann - I'll try and reproduce these failures locally.

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

PR Comment: https://git.openjdk.org/jdk/pull/17562#issuecomment-1915348659


More information about the hotspot-compiler-dev mailing list