RFR: 8310190: C2 SuperWord: AlignVector is broken, generates misaligned packs [v10]
Emanuel Peter
epeter at openjdk.org
Wed Oct 18 10:59:20 UTC 2023
> To calm your nerves: most of the changes are in auto-generated tests, and tests in general.
>
> **Context**
>
> `-XX:+AlignVector` ensures that SuperWord only creates LoadVector and StoreVector that can be memory aligned. This is achieved by iterating in the pre-loop until we reach the alignment boundary, then we can start the main loop properly aligned. However, this is not possible in all cases, sometimes some memory accesses cannot be guaranteed to be aligned, and we need to reject vectorization (at least partially, for some of the packs).
>
> Alignment is split into two tasks:
> - Alignment Correctness Checks: only relevant if `-XX:+AlignVector`. Need to reject vectorization if alignment is not possible. We must check if the address of the vector load/store is aligned with (divisible by) `ObjectAlignmentInBytes`.
> - Alignment by adjusting pre-loop limit: alignment is desirable even if `-XX:-AlignVector`. We would like to align the vectors with their vector width.
>
> **Problem**
>
> I have recently found a bug with our AlignVector [JDK-8310190](https://bugs.openjdk.org/browse/JDK-8310190).
> In that bug, we perform a misaligned memory vector access, which results in a `SIGBUS` on an ARM32 machine.
> Thanks @fg1417 for confirming this!
> Hence, we need to fix the alignment correctness checks.
>
> While working on this task, I also found some bugs in the "alignment by adjusting pre-loop limit": there were cases where it did not align the vectors correctly.
>
> **Problem Details**
>
> Reproducer:
>
>
> static void test3(byte[] a, byte[] b, byte mask) {
> for (int i = 0; i < RANGE; i+=8) {
> // Problematic for AlignVector
> b[i+0] = (byte)(a[i+0] & mask); // best_memref, align 0
>
> b[i+3] = (byte)(a[i+3] & mask); // pack at offset 6 bytes
> b[i+4] = (byte)(a[i+4] & mask);
> b[i+5] = (byte)(a[i+5] & mask);
> b[i+6] = (byte)(a[i+6] & mask);
> }
> }
>
>
> During `SuperWord::find_adjacent_refs` we used to check if the references are expected to be aligned. For that, we look at each "group" of references (eg all `LoadS`) and take the reference with the lowest offset. For that chosen reference, we check if it is alignable. If yes, we accept all references of that group, if no we reject all.
>
> This is problematic as shown in this example. We have references at index offset `0, 3, 4, 5, 6`, and byte offset `0, 6, 8, 10, 12`. While the reference at position `0` is alignable, the pack that is eventually generated has offsets `6,...
Emanuel Peter has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 60 commits:
- Merge branch 'master' into JDK-8311586
- small fix
- Merge branch 'master' into JDK-8311586
- add comments for must_verify_alignment
- fixed up verify_vector_alignment in ad file
- rename VerifyAlignment with VerifyVectorAlignment
- replace ifdef with Matcher::has_match_rule
- fix whitespace
- Disable VerifyAlignVector with warning if AlignVector is disabled
- fix up TestVectorizationMismatchedAccess.java
- ... and 50 more: https://git.openjdk.org/jdk/compare/6fc35142...cc410f1d
-------------
Changes: https://git.openjdk.org/jdk/pull/14785/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14785&range=09
Stats: 7865 lines in 20 files changed: 6771 ins; 289 del; 805 mod
Patch: https://git.openjdk.org/jdk/pull/14785.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/14785/head:pull/14785
PR: https://git.openjdk.org/jdk/pull/14785
More information about the hotspot-compiler-dev
mailing list