JDK-8367028 : compiler/c2/irTests/TestFloat16ScalarOperations.java failing intermittently because of constant folding
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 26
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-09-06
  • Updated: 2025-12-11
  • Resolved: 2025-12-09
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 26 JDK 27
26Fixed 27 b02Fixed
Related Reports
Relates :  
Description
Reproduces on mainline. Issue is unexpected constant folding when special random values are chosen in the test.

I reproduced the issue by replacing the constant values with special values, see below in comments.

I could detect one failure with this seed on an aarch64 machine, but the seed does not seem to work via SDE:
-Djdk.test.lib.random.seed=-8149712388031710130
(Note: this only triggers a subset of the failures anyway, so precise investigation of all cases is still required to ensure we don't have any other failures in the future)

Important: Float16 support is required. You can simulate it with SDE, for example.

--------------------- ORIGINAL REPORT -----------------------

Failing in fibers branch of loom repo, linux-aarch64-debug only.

One or more @IR rules failed:

Failed IR Rules (1) of Methods (1)
----------------------------------
1) Method "public short TestFloat16ScalarOperations.testRandomFP16ConstantPatternSet1()" - [Failed IR rules: 1]:
   * @IR rule 2: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={"_#ADD_HF#_", " >0 ", "_#SUB_HF#_", " >0 ", "_#MUL_HF#_", " >0 ", "_#DIV_HF#_", " >0 "}, failOn={}, applyIfPlatform={}, applyIfPlatformOr={}, applyIfOr={}, applyIfCPUFeatureAnd={"fphp", "true", "asimdhp", "true"}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})"
     > Phase "PrintIdeal":
       - counts: Graph contains wrong number of nodes:
         * Constraint 4: "(\\d+(\\s){2}(DivHF.*)+(\\s){2}===.*)"
           - Failed comparison: [found] 0 > 0 [given]
           - No nodes matched!

>>> Check stdout for compilation output of the failed methods
Comments
A pull request was submitted for review. Branch: jdk26 URL: https://git.openjdk.org/jdk/pull/28720 Date: 2025-12-09 14:32:26 +0000
09-12-2025

Changeset: a4eb57c5 Branch: master Author: Emanuel Peter <epeter@openjdk.org> Date: 2025-12-09 12:45:36 +0000 URL: https://git.openjdk.org/jdk/commit/a4eb57c5ec6254e59e486042015dd00457284ef2
09-12-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/28678 Date: 2025-12-05 14:43:57 +0000
08-12-2025

Draft PR: https://github.com/openjdk/jdk/pull/28678
05-12-2025

[~thartmann] I had observed one failure with seed -Djdk.test.lib.random.seed=-8149712388031710130 on an aarch64 machine. But this seed does not reproduce on my machine with SDE. We need to analyze all uses of constant by hand anyway, because a seed will only trigger a small part of all possible failures anyway. So a seed only has limited use.
12-11-2025

[~epeter] Do we have a specific seed to reproduce this? ILW = Test fails due to unexpected constant folding (test bug), intermittent with single test, no workaround = MLH = P4
12-11-2025

[~epeter] No objection. The loom repo will often have 3 or 4 prototypes for different features so sometimes tickles test failures due to different code paths or tests that are very tied to implementation.
11-11-2025

[~alanb] Thanks for first filing this. Since I could reproduce it on mainline, I removed the repo-loop tag, and replaced it with JDK26. Let me know if you object ;)
11-11-2025

I'm not 100% sure but JDK-8352635 is from JKD26, and it is most likely the source of the failure. So until proven otherwise, I'll set it as the cause for the failure. [~jbhateja] Would you mind having a look at this? Proposal: restrict the generator so it does not generate "problematic" constants that lead to constant folding. Inspect all other uses of random constants in the test, to ensure we don't have any other failures in the future ;)
11-11-2025

The test was added in JDK-8352635. It generates random constants, and so it would be expected that it could fail intermittently: for example if out of all possible random float values it generates a "1" or "0", it could fail. And that is quite rare but it will happen occasionally. I was able to reproduce it reliably on mainline like this: edit the randomly generated results with "problematic" constants (that could also arise randomly): diff --git a/test/hotspot/jtreg/compiler/c2/irTests/TestFloat16ScalarOperations.java b/test/hotspot/jtreg/compiler/c2/irTests/TestFloat16ScalarOperations.java index c8ee5e730fa..d00720815ed 100644 --- a/test/hotspot/jtreg/compiler/c2/irTests/TestFloat16ScalarOperations.java +++ b/test/hotspot/jtreg/compiler/c2/irTests/TestFloat16ScalarOperations.java @@ -63,10 +63,10 @@ public class TestFloat16ScalarOperations { private static Generator<Short> genHF = G.uniformFloat16s(); private static final Float16 RANDOM1 = Float16.valueOf(genF.next()); - private static final Float16 RANDOM2 = Float16.valueOf(genF.next()); - private static final Float16 RANDOM3 = Float16.valueOf(genF.next()); - private static final Float16 RANDOM4 = Float16.valueOf(genF.next()); - private static final Float16 RANDOM5 = Float16.valueOf(genF.next()); + private static final Float16 RANDOM2 = Float16.valueOf(0); // genF.next()); + private static final Float16 RANDOM3 = Float16.valueOf(0); // genF.next()); + private static final Float16 RANDOM4 = Float16.valueOf(1); // genF.next()); + private static final Float16 RANDOM5 = Float16.valueOf(1); // genF.next()); private static Float16 RANDOM1_VAR = RANDOM1; private static Float16 RANDOM2_VAR = RANDOM2; Then run the test on through sde: /home/empeter/Documents/oracle/sde-external-9.58.0-2025-06-16-lin/sde -future -- /home/empeter/Documents/oracle/jtreg/bin/jtreg -va -s -jdk:/home/empeter/Documents/oracle/jdk-fork6/build/linux-x64-debug/jdk -javaoptions:"" -J-Djavatest.maxOutputSize=10000000 /home/empeter/Documents/oracle/jdk-fork6/open/test/hotspot/jtreg/compiler/c2/irTests/TestFloat16ScalarOperations.java Wait for half an eternity because of the emulator ... and observe a list of failures: Failed IR Rules (2) of Methods (2) ---------------------------------- 1) Method "public short TestFloat16ScalarOperations.testRandomFP16ConstantPatternSet1()" - [Failed IR rules: 1]: * @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={"avx512_fp16", "true", "zfh", "true"}, counts={"_#ADD_HF#_", " >0 ", "_#SUB_HF#_", " >0 ", "_#MUL_HF#_", " >0 ", "_#DIV_HF#_", " >0 "}, applyIfPlatformOr={}, applyIfPlatform={}, failOn={}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})" > Phase "PrintIdeal": - counts: Graph contains wrong number of nodes: * Constraint 2: "(\d+(\s){2}(SubHF.*)+(\s){2}===.*)" - Failed comparison: [found] 0 > 0 [given] - No nodes matched! * Constraint 3: "(\d+(\s){2}(MulHF.*)+(\s){2}===.*)" - Failed comparison: [found] 0 > 0 [given] - No nodes matched! * Constraint 4: "(\d+(\s){2}(DivHF.*)+(\s){2}===.*)" - Failed comparison: [found] 0 > 0 [given] - No nodes matched! 2) Method "public short TestFloat16ScalarOperations.testRandomFP16ConstantPatternSet2()" - [Failed IR rules: 1]: * @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={"avx512_fp16", "true", "zfh", "true"}, counts={"_#ADD_HF#_", " >0 ", "_#SUB_HF#_", " >0 ", "_#MUL_HF#_", " >0 ", "_#DIV_HF#_", " >0 "}, applyIfPlatformOr={}, applyIfPlatform={}, failOn={}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})" > Phase "PrintIdeal": - counts: Graph contains wrong number of nodes: * Constraint 3: "(\d+(\s){2}(MulHF.*)+(\s){2}===.*)" - Failed comparison: [found] 0 > 0 [given] - No nodes matched!
11-11-2025

I suspect the issue is that the constants can lead to constant folding in some cases. 430 @Test 431 @IR(counts = {IRNode.ADD_HF, " >0 ", IRNode.SUB_HF, " >0 ", IRNode.MUL_HF, " >0 ", IRNode.DIV_HF, " >0 "}, 432 applyIfCPUFeatureOr = {"avx512_fp16", "true", "zfh", "true"}) 433 @IR(counts = {IRNode.ADD_HF, " >0 ", IRNode.SUB_HF, " >0 ", IRNode.MUL_HF, " >0 ", IRNode.DIV_HF, " >0 "}, 434 applyIfCPUFeatureAnd = {"fphp", "true", "asimdhp", "true"}) 435 @Warmup(10000) 436 public short testRandomFP16ConstantPatternSet1() { 437 short res = 0; 438 res += Float.floatToFloat16(RANDOM1_VAR.floatValue() + RANDOM2.floatValue()); 439 res += Float.floatToFloat16(RANDOM2_VAR.floatValue() - RANDOM3.floatValue()); 440 res += Float.floatToFloat16(RANDOM3_VAR.floatValue() * RANDOM4.floatValue()); 441 res += Float.floatToFloat16(RANDOM4_VAR.floatValue() / RANDOM5.floatValue()); 442 return res; 443 } For example if RANDOM values are zero or 1, they can get the ops constant folded away, and we won't see them in the IR.
11-11-2025

Other occurances, probably also on mainline: Failed IR Rules (2) of Methods (2) ---------------------------------- 1) Method "public short TestFloat16ScalarOperations.testRandomFP16ConstantPatternSet1()" - [Failed IR rules: 1]: * @IR rule 2: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={"_#ADD_HF#_", " >0 ", "_#SUB_HF#_", " >0 ", "_#MUL_HF#_", " >0 ", "_#DIV_HF#_", " >0 "}, failOn={}, applyIfPlatformOr={}, applyIfPlatform={}, applyIfOr={}, applyIfCPUFeatureAnd={"fphp", "true", "asimdhp", "true"}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})" > Phase "PrintIdeal": - counts: Graph contains wrong number of nodes: * Constraint 3: "(\\d+(\\s){2}(MulHF.*)+(\\s){2}===.*)" - Failed comparison: [found] 0 > 0 [given] - No nodes matched! 2) Method "public short TestFloat16ScalarOperations.testRandomFP16ConstantPatternSet2()" - [Failed IR rules: 1]: * @IR rule 2: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={"_#ADD_HF#_", " >0 ", "_#SUB_HF#_", " >0 ", "_#MUL_HF#_", " >0 ", "_#DIV_HF#_", " >0 "}, failOn={}, applyIfPlatformOr={}, applyIfPlatform={}, applyIfOr={}, applyIfCPUFeatureAnd={"fphp", "true", "asimdhp", "true"}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})" > Phase "PrintIdeal": - counts: Graph contains wrong number of nodes: * Constraint 3: "(\\d+(\\s){2}(MulHF.*)+(\\s){2}===.*)" - Failed comparison: [found] 0 > 0 [given] - No nodes matched!
11-11-2025