RFR: 8373495: C2: Aggressively fold loads from objects that have not escaped [v17]
Vladimir Ivanov
vlivanov at openjdk.org
Fri Jan 16 19:25:08 UTC 2026
On Fri, 16 Jan 2026 12:11:05 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:
>> src/hotspot/share/opto/memnode.cpp line 714:
>>
>>> 712: bool is_known_instance = addr_t != nullptr && addr_t->is_known_instance_field();
>>> 713: LocalEA local_ea(phase->is_IterGVN(), base);
>>> 714: TriBool has_not_escaped = is_known_instance ? TriBool(true)
>>
>> IMO `TriBool` doesn't hold its weight here. As an alternative, encapsulating caching logic inside `LocalEA` and unconditionally querying it for escape state would look cleaner and easier to reason about.
>
> I took a try, but I find it not compelling, the caching is the consequence of `find_previous_store` keeping walking from a node to its input. So, if a node does not observe that `base` has escaped, its input should not do so, either. Moving this logic to `LocalEA` seems not logical from that POV.
`LocalEA` is already stateful and there are asserts in place to ensure that cached escape state agrees with current control (`local_ea.not_escaped_controls().member(ctrl)`). The assert can be turned into a dynamic check inside `MemNode::LocalEA::check_escape_status()` to report cached (non-escaping) state when queried control dominates cached one (and, hence, should be recorded in `LocalEA::_not_escaped_controls`). That should be equivalent to the current logic (modulo the dynamic check).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28812#discussion_r2699696483
More information about the hotspot-compiler-dev
mailing list