JDK-8316594 : C2 SuperWord: wrong result with hand unrolled loops
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-09-20
  • Updated: 2024-01-08
  • Resolved: 2023-10-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21 JDK 22
21.0.3-oracleFixed 22 b19Fixed
Related Reports
Blocks :  
Blocks :  
Relates :  
Description
This must be a relatively new regression, I think it does not affect JDK20, but certainly the newest of JDK22 and also JDK-22-ea+15-1134.

./java -XX:CompileCommand=compileonly,Test22::test22 -XX:CompileCommand=printcompilation,Test22::test* -XX:LoopUnrollLimit=250 -XX:UseAVX=2 -Xbatch -XX:+TraceSuperWord -XX:+TraceLoopOpts -XX:LoopMaxUnroll=8 Test22.java

You get:
Exception in thread "main" java.lang.RuntimeException: bad a
	at Test22.verify(Test22.java:40)
	at Test22.main(Test22.java:26)

But with "-Xint", there is no such exception.


I have a similar example, which also uses Unsafe:

./java -XX:CompileCommand=compileonly,Test21::test21 -XX:CompileCommand=printcompilation,Test21::test* -XX:LoopUnrollLimit=250 --add-modules java.base --add-exports java.base/jdk.internal.misc=ALL-UNNAMED -XX:UseAVX=2 -Xbatch -XX:+TraceSuperWord Test21.java

You get:
Exception in thread "main" java.lang.RuntimeException: bad 18
	at Test21.main(Test21.java:28)

But again, we have no exception with "-Xint".
Comments
Fix request [21u] I backport this for parity with 21.0.3-oracle. Typical risk of a C2 change, medium. Not clean, but straight forward to adapt. Test passes, but does not reproduce the issue in 21. SAP nightly testing passed.
04-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u-dev/pull/110 Date: 2024-01-02 17:16:18 +0000
02-01-2024

While it starts to fail with existing tests after JDK-8308606, I am marking it for eventual backport to 21u in case it can actually reproduce even without JDK-8308606 in some conditions.
09-11-2023

Changeset: 3630af26 Author: Emanuel Peter <epeter@openjdk.org> Date: 2023-10-05 06:46:44 +0000 URL: https://git.openjdk.org/jdk/commit/3630af26e6f05237195e53b98603adf404e90a1a
05-10-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15866 Date: 2023-09-21 15:26:25 +0000
22-09-2023

ILW = Wrong execution when vectorizing hand unrolled loops, edge case, disable compilation of affected method or use -XX:-UseSuperWord = HLM = P3
20-09-2023

Starts to fail after JDK-8308606.
20-09-2023