8397485: C2: Consolidate the logic to fold a load #33930
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 528 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.375
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #33930"
general
weight: 0.35
vnkozlov
Hi,
This PR is extracted from #33845.
Currently, the logic to fold a load is pretty messy:
LoadBNodebefore callingLoadNode::Idealto optimize its inputs.Idealchange the input first, thenIdentitywill do the folding. This is extra intricate becauseIdentitymust be able to fold the modified load, otherwise the scheduler may not be able to schedule it.This PR consolidates the logic to fold a load to
LoadNode::Ideal. Some other folding inIdentityandValueis still necessary for some other optimizations such as splitting through phi, but from the IGVN perspective, onlyIdealis necessary. This allows #33845 to process the trailing memory barriers of the access in a uniform manner when the access is folded.1. The old logic to fold a load is explained:
// The logic for reordering loads and stores uses four steps:
// (a) Walk carefully past stores and initializations which we
// can prove are independent of this load.
// (b) Observe that the next memory state makes an exact match
// with self (load or store), and locate the relevant store.
// (c) Ensure that, if we were to wire self directly to the store,
// the optimizer would fold it up somehow.
// (d) Do the rewiring, and return, depending on some other part of
// the optimizer to fold up the load.
This is because
Idealmust return a new node. So we cannot directly return the folded value inIdeal. However, this is unnecessily awkward, so I addIdentityNodewhich is likeTupleNode, but for a non-MultNode. This simplifies the logic and makes it a little bit more efficient. For this to work smoothly,MemNode::find_previous_storeis modified to return the current memory if it cannot prove independence. This does not matter becauseMemNode::find_previous_storedoes not actually guarantee that the returned memory is a matching store, and callers need to check withcan_see_stored_valueanyway.2. When folding a subword load, we need to normalize the stored value. Previously, this is done eagerly in the subclass
Ideal, before callingLoadNode::Ideal. I have refactored the normalization to the same place nodes that do not need normalization are folding their results.Testing:
Please take a look and leave your reviews, thanks a lot.
---------
<!-- Anything below this marker will be automatically updated, please do not edit manually! -->
---------
Progress
Issue
JDK-8397485: C2: Consolidate the logic to fold a load (Enhancement - P4)
Reviewers
Vladimir Kozlov (@vnkozlov - Reviewer)
Reviewing
<details><summary>Using <code>git</code></summary>
Checkout this PR locally: \
$ git fetch https://git.openjdk.org/jdk.git pull/33930/head:pull/33930\$ git checkout pull/33930Update a local copy of the PR: \
$ git checkout pull/33930\$ git pull https://git.openjdk.org/jdk.git pull/33930/head</details>
<details><summary>Using Skara CLI tools</summary>
Checkout this PR locally: \
$ git pr checkout 33930View PR using the GUI difftool: \
$ git pr show -t 33930</details>
<details><summary>Using diff file</summary>
Download this PR as a diff file: \
<a href="https://git.openjdk.org/jdk/pull/33930.diff">https://git.openjdk.org/jdk/pull/33930.diff</a>
</details>
<details><summary>Using Webrev</summary>
Link to Webrev Comment
</details>