RFR: 8324751: C2 SuperWord: Aliasing Analysis runtime check [v5]

Manuel Hässig mhaessig at openjdk.org
Mon Aug 4 10:58:06 UTC 2025


On Sun, 3 Aug 2025 09:27:10 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> This is a big patch, but about 3.5k lines are tests. And a large part of the VM changes is comments / proofs.
>> 
>> I am adding a dynamic (runtime) aliasing check to the auto-vectorizer (SuperWord). We use the infrastructure from https://github.com/openjdk/jdk/pull/22016:
>> - Use the auto-vectorization `predicate` when available: we speculate that there is no aliasing, else we trap and re-compile without the predicate.
>> - If the predicate is not available, we use `multiversioning`, i.e. we have a `fast_loop` where there is no aliasing, and hence vectorization. And a `slow_loop` if the check fails, with no vectorization.
>> 
>> --------------------------
>> 
>> **Where to start reviewing**
>> 
>> - `src/hotspot/share/opto/mempointer.hpp`:
>>   - Read the class comment for `MemPointerRawSummand`.
>>   - Familiarize yourself with the `MemPointer Linearity Corrolary`. We need it for the proofs of the aliasing runtime checks.
>> 
>> - `src/hotspot/share/opto/vectorization.cpp`:
>>   - Read the explanations and proofs above `VPointer::can_make_speculative_aliasing_check_with`. It explains how the aliasing runtime check works.
>> 
>> - `src/hotspot/share/opto/vtransform.hpp`:
>>   - Understand the difference between weak and strong edges.
>> 
>> If you need to see some examples, then look at the tests:
>> - `test/hotspot/jtreg/compiler/loopopts/superword/TestAliasing.java`: simple array cases. IR rules that check for vectors and in somecases if we used multiversioning.
>> - `test/micro/org/openjdk/bench/vm/compiler/VectorAliasing.java`: the miro-benchmarks I show below. Simple array cases.
>> - `test/hotspot/jtreg/compiler/loopopts/superword/TestMemorySegmentAliasing.java`: a bit advanced, but similar cases.
>> - `test/hotspot/jtreg/compiler/loopopts/superword/TestAliasingFuzzer.java`: very large and rather compliex. Generates random loops, some with and some without aliasing at runtime. IR verification, but mostly currently only for array cases, MemorySegment cases have some issues (see comments).
>> --------------------------
>> 
>> **Details**
>> 
>> Most fundamentally:
>> - I had to refactor / extend `MemPointer` so that we have access to `MemPointerRawSummand`s.
>> - These raw summands us to reconstruct the `VPointer` at any `iv` value with `VPointer::make_pointer_expression(Node* iv_value)`.
>>    - With the raw summands, a pointer may look like this: `p = base + ConvI2L(x + 2) + ConvI2L(y + 2)`
>>   - With "regular" summands, this gets simplified to `p = base + 4L +ConvI2L(x) + Conv...
>
> Emanuel Peter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   fix test after merge

Thank you for addressing my comments. I only have a few follow-ups.

test/hotspot/jtreg/compiler/loopopts/superword/TestAliasingFuzzer.java line 246:

> 244:         return TestFrameworkClass.render(
> 245:             // package and class name.
> 246:             "p.xyz", "InnerTest",

Suggestion:

            "compiler.loopopts.superword.templated", "AliasingFuzzer",

This went missing

test/hotspot/jtreg/compiler/loopopts/superword/TestMemorySegment.java line 823:

> 821:         applyIfCPUFeatureOr = {"sse4.1", "true", "asimd", "true", "rvv", "true"})
> 822:     // FAILS: invariants are sorted differently, because of differently inserted Cast.
> 823:     // See: JDK-8331659

With the integration of #26429, this should pass.

test/hotspot/jtreg/compiler/loopopts/superword/TestMemorySegment.java line 866:

> 864:         applyIfCPUFeatureOr = {"sse4.1", "true", "asimd", "true", "rvv", "true"})
> 865:     // FAILS: invariants are sorted differently, because of differently inserted Cast.
> 866:     // See: JDK-8331659

With the integration of #26429, this should pass.

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

Changes requested by mhaessig (Committer).

PR Review: https://git.openjdk.org/jdk/pull/24278#pullrequestreview-3083634456
PR Review Comment: https://git.openjdk.org/jdk/pull/24278#discussion_r2251128584
PR Review Comment: https://git.openjdk.org/jdk/pull/24278#discussion_r2251112018
PR Review Comment: https://git.openjdk.org/jdk/pull/24278#discussion_r2251112943


More information about the hotspot-compiler-dev mailing list