RFR: 8371146: C2 SuperWord: VTransform::add_speculative_check uses pre_init that is pinned after Auto_Vectorization_Check, leading to bad graph

Emanuel Peter epeter at openjdk.org
Mon Nov 24 11:53:19 UTC 2025


**Analysis**

This is a regression of [JDK-8324751](https://bugs.openjdk.org/browse/JDK-8324751) / https://github.com/openjdk/jdk/pull/24278.

The aliasing runtime check happens before the pre-loop. The values needed for the aliasing runtime check thus need to be available not just at the pre-loop, but even earlier: already at the aliasing check.

Sadly, so far we only ever checked for `is_pre_loop_invariant`, and not `is_available_for_speculative_check`. We now found an example with the fuzzer that has a `pre_init` value that is pinned after the aliasing runtime check but before the pre-loop. Thus it passed the checks, and then created a bad graph (cyclic path, think "use before definition").

This a very rare case. Getting the ctrl pinned after the aliasing runtime check but before the pre-loop requires some very specific order of loop-opts, of unroll/pre-main-post/peeling etc. But it can happen, and so we must handle it right.

Solution: check for the stronger condition `is_available_for_speculative_check`.

**Future Work**

We should improve the debug printing when aliasing checks cannot be inserted. Currently the tag `SW_REJECTIONS` is a bit messy, we should fix that up. But it would be too many changes for this bug fix here.

**Details**

During `SuperWord`, we want to insert the aliasing runtime check above `687 ParsePredicate` which is annotated with `#Auto_Vectorization_Check`. For this, we require the `pre_init` value: `1244 AddI`. Sadly, this value is pinned lower down.
<img width="1488" height="1204" alt="image" src="https://github.com/user-attachments/assets/cbbe1e67-a261-4e29-85de-b99a2f552d66" />

So when we insert the aliasing runtime check, we create a bad (circular) graph:
<img width="1480" height="1206" alt="image" src="https://github.com/user-attachments/assets/06f0f13c-2005-458a-bdda-6fa07e4321e2" />

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

Commit messages:
 - better comments
 - refined fix
 - initial fix
 - JDK-8371146

Changes: https://git.openjdk.org/jdk/pull/28449/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28449&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8371146
  Stats: 164 lines in 3 files changed: 155 ins; 0 del; 9 mod
  Patch: https://git.openjdk.org/jdk/pull/28449.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28449/head:pull/28449

PR: https://git.openjdk.org/jdk/pull/28449


More information about the hotspot-compiler-dev mailing list