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
Wed Nov 26 15:02:07 UTC 2025


On Mon, 24 Nov 2025 14:41:22 GMT, Roland Westrelin <roland at openjdk.org> wrote:

>> **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" />
>
> Looks good to me.

@rwestrel @chhagedorn Thanks for the review, and for the conversation about getting ctrl right 😊

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

PR Comment: https://git.openjdk.org/jdk/pull/28449#issuecomment-3581710051


More information about the hotspot-compiler-dev mailing list