JDK-8351515 : C2 incorrectly removes double negation for double and float
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8,11,17,21,25
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-03-10
  • Updated: 2025-04-10
  • Resolved: 2025-03-24
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 25
25 b16Fixed
Related Reports
Causes :  
Causes :  
Causes :  
Description
C2 incorrectly folds '0 - (0 - x)' to 'x' for double and float 'x':
https://github.com/openjdk/jdk/blob/4b463ee70eceb94fdfbffa5c49dd58dcc6a6c890/src/hotspot/share/opto/subnode.cpp#L56-L62

Attached test demonstrates this:

java -XX:-TieredCompilation -Xbatch -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,Test::test* Test.java
Exception in thread "main" java.lang.RuntimeException: Invalid result: -2147483648
	at Test.main(Test.java:37)
Comments
Changeset: 5591f8a4 Branch: master Author: Manuel Hässig <manuel@haessig.org> Date: 2025-03-24 07:59:20 +0000 URL: https://git.openjdk.org/jdk/commit/5591f8a42997c7bbe99d26f7a75d494a53e436fa
24-03-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/24150 Date: 2025-03-21 10:20:53 +0000
21-03-2025

ILW = Incorrect result of C2 compiled code, old issue; edge case of double negation of float/double val and bit level comparison, no workaround but disable compilation of affected method = HLM = P3
10-03-2025