JDK-8313720 : C2 SuperWord: wrong result with -XX:+UseVectorCmov -XX:+UseCMoveUnconditionally
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-08-03
  • Updated: 2023-12-29
  • Resolved: 2023-08-16
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 b11Fixed
Related Reports
Relates :  
Description
Found this while trying to find a reproducer for JDK-8313345.

Reproduce:
java -Xbatch -XX:CompileCommand=compileonly,Test2::test -XX:+TraceLoopOpts -XX:+UseVectorCmov -XX:+UseCMoveUnconditionally -XX:+TraceSuperWord -XX:+TraceNewVectors -XX:MaxVectorSize=64 Test2.java

fail: 100 1.0 != 0.0 : 1.0 1.0
Exception in thread "main" java.lang.RuntimeException: There were wrong results
	at Test2.verify(Test2.java:56)
	at Test2.main(Test2.java:44)

I suspect the reason is the mixed comparison values in the Bool pack (le / lt):
Pack: 11
 align: 0 	 1708  Bool  === _ 1709  [[ 1707 ]] [le] !orig=1462,1241,163 !jvms: Test2::test @ bci:24 (line 16)
 align: 4 	 1702  Bool  === _ 1703  [[ 1701 ]] [lt] !orig=1456,1235,255 !jvms: Test2::test @ bci:48 (line 17)
 align: 8 	 1696  Bool  === _ 1697  [[ 1695 ]] [le] !orig=1450,163 !jvms: Test2::test @ bci:24 (line 16)
 align: 12 	 1690  Bool  === _ 1691  [[ 1689 ]] [lt] !orig=1444,255 !jvms: Test2::test @ bci:48 (line 17)
 align: 16 	 1684  Bool  === _ 1685  [[ 1683 ]] [le] !orig=1241,163 !jvms: Test2::test @ bci:24 (line 16)
 align: 20 	 1678  Bool  === _ 1679  [[ 1677 ]] [lt] !orig=1235,255 !jvms: Test2::test @ bci:48 (line 17)
 align: 24 	 1666  Bool  === _ 1667  [[ 1665 ]] [le] !orig=163 !jvms: Test2::test @ bci:24 (line 16)
 align: 28 	 1660  Bool  === _ 1661  [[ 1659 ]] [lt] !orig=255 !jvms: Test2::test @ bci:48 (line 17)
 align: 32 	 1462  Bool  === _ 1463  [[ 1461 ]] [le] !orig=1241,163 !jvms: Test2::test @ bci:24 (line 16)
 align: 36 	 1456  Bool  === _ 1457  [[ 1455 ]] [lt] !orig=1235,255 !jvms: Test2::test @ bci:48 (line 17)
 align: 40 	 1450  Bool  === _ 1451  [[ 1449 ]] [le] !orig=163 !jvms: Test2::test @ bci:24 (line 16)
 align: 44 	 1444  Bool  === _ 1445  [[ 1443 ]] [lt] !orig=255 !jvms: Test2::test @ bci:48 (line 17)
 align: 48 	 1241  Bool  === _ 1242  [[ 1240 ]] [le] !orig=163 !jvms: Test2::test @ bci:24 (line 16)
 align: 52 	 1235  Bool  === _ 1236  [[ 1234 ]] [lt] !orig=255 !jvms: Test2::test @ bci:48 (line 17)
 align: 56 	  163  Bool  === _ 162  [[ 317 ]] [le] !jvms: Test2::test @ bci:24 (line 16)
 align: 60 	  255  Bool  === _ 254  [[ 318 ]] [lt] !jvms: Test2::test @ bci:48 (line 17)

The logic I implemented in JDK-8306302 did not take account of hand unrolled loops, where the comparisons can be different.
Comments
Fix request [21u] I backport this for parity with 21.0.3-oracle. Typical risk of a C2 change, Good repro case. Clean backport. Test passes and fails without the fix. SAP nightly testing passed.
28-12-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u-dev/pull/98 Date: 2023-12-26 13:08:16 +0000
26-12-2023

Changeset: d46f0fb3 Author: Emanuel Peter <epeter@openjdk.org> Date: 2023-08-16 07:15:43 +0000 URL: https://git.openjdk.org/jdk/commit/d46f0fb31888db75f5b2b78a162fec16dfc5d0d9
16-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/15274 Date: 2023-08-14 14:57:39 +0000
15-08-2023

ILW = Wrong result with superword, edge case?, use -XX:-UseVectorCmov -XX:-UseCMoveUnconditionally = HLM = P3
04-08-2023