← Back to Pull requests

8397485: C2: Consolidate the logic to fold a load #33930

Open
unknown opened this pull request with 528 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 17, 2026 13:47 UTC
Author

Hi,

This PR is extracted from #33845.

Currently, the logic to fold a load is pretty messy:

  • Some subclasses try to fold a load first thing such as LoadBNode before calling LoadNode::Ideal to optimize its inputs.

  • When folding a load, some subclasses have to let Ideal change the input first, then Identity will do the folding. This is extra intricate because Identity must be able to fold the modified load, otherwise the scheduler may not be able to schedule it.

  • Because the fold happens at multiple places, it makes it hard to work with ordered accesses which have accompanying barriers that also need processing.
  • This PR consolidates the logic to fold a load to LoadNode::Ideal. Some other folding in Identity and Value is still necessary for some other optimizations such as splitting through phi, but from the IGVN perspective, only Ideal is 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 Ideal must return a new node. So we cannot directly return the folded value in Ideal. However, this is unnecessily awkward, so I add IdentityNode which is like TupleNode, 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_store is modified to return the current memory if it cannot prove independence. This does not matter because MemNode::find_previous_store does not actually guarantee that the returned memory is a matching store, and callers need to check with can_see_stored_value anyway.

    2. When folding a subword load, we need to normalize the stored value. Previously, this is done eagerly in the subclass Ideal, before calling LoadNode::Ideal. I have refactored the normalization to the same place nodes that do not need normalization are folding their results.

    Testing:

  • tier1-4,hs-comp-stress
  • Please take a look and leave your reviews, thanks a lot.

    ---------

  • I confirm that I make this contribution in accordance with the OpenJDK Interim AI Policy.
  • <!-- Anything below this marker will be automatically updated, please do not edit manually! -->
    ---------

    Progress


  • \[x\] Change must not contain extraneous whitespace

  • \[x\] Commit message must refer to an issue

  • \[ \] Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)
  • 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/33930

    Update 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 33930

    View 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>

    Diff: 528 lines (+396 / -132) across 6 files Reviewer: vnkozlov Review duration: 19819m
    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
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.5% · Safe to merge
    25.5%
    Repository