JDK-8286177 : C2: "failed: non-reduction loop contains reduction nodes" assert failure
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,17,19
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-05-05
  • Updated: 2022-07-25
  • Resolved: 2022-05-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 11 JDK 17 JDK 19
11.0.17-oracleFixed 17.0.5-oracleFixed 19 b24Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
Similarly to JDK-8279622, a node marked as a reduction is hoisted out of its original reduction loop into an outer loop that is not marked as a reduction. The assertion introduced in JDK-8279622 catches this inconsistency and fails. Unlike JDK-8279622 though, the inconsistent reduction marking in this case is not fatal, in that it would not lead to a miscompilation should the assertion be disabled. This is because the inconsistently marked loop(s) contains safepoints, which inhibits SLP vectorization.

HOW TO REPRODUCE

$ javac Test.java FuzzerUtils.java
$ java Test

#  Internal Error (/home/roland/jdk-jdk/src/hotspot/share/opto/superword.cpp:113), pid=4077494, tid=4077507
#  assert(!lpt->has_reduction_nodes() || cl->is_reduction_loop()) failed: non-reduction loop contains reduction nodes
#
# JRE version: OpenJDK Runtime Environment (19.0) (fastdebug build 19-internal-adhoc.roland.jdk-jdk)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 19-internal-adhoc.roland.jdk-jdk, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x1a3cb04]  SuperWord::transform_loop(IdealLoopTree*, bool)+0x424

FAILURE ANALYSIS

The node corresponding to (acc += j) is marked as a reduction together with its (inner) loop:

  int i = 0, acc = 0;
  do {
      int j = 0;
      do {              // inner loop marked as a reduction
          if (b) {
              acc += j; // node marked as a reduction
          }
          j++;
      } while (j < 5);
      i++;
  } while (i < 100);
  return acc;

After unrolling and constant-folding the inner loop (b is always true), the node formerly corresponding to (acc += j), and now corresponding to (acc += 10), is hoisted into the outer loop, which is not marked as a reduction. This creates an inconsistent state that is later caught by the failing assertion:

  int i = 0, acc = 0;
  do {
      acc += 10; // node marked as a reduction (inconsistent, outer loop is not marked as a reduction)
      i++;
  } while (i < 100);
  return acc;
Comments
Fix request [11u] I backport this for parity with 11.0.17-oracle. A c2 fix that is a follow up to JDK-8279622 so we should take it. Clean backport from 17. Test passes, unfortunately also without the fix. SAP nighlty testing passed.
03-07-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/1195 Date: 2022-07-01 10:32:05 +0000
01-07-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/495 Date: 2022-06-22 08:28:23 +0000
22-06-2022

Fix request [17u] I backport this for parity with 17.0.5-oracle. A c2 fix that is a follow up so we should take it. I had to resolve removing the assertion. Test passes, unfortunately also without the fix.
22-06-2022

Changeset: 6458a56e Author: Roberto CastaƱeda Lozano <rcastanedalo@openjdk.org> Date: 2022-05-24 07:19:00 +0000 URL: https://git.openjdk.java.net/jdk/commit/6458a56e60472fb2fbe8fa60bbc856dc95f50f07
24-05-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/8805 Date: 2022-05-20 09:45:19 +0000
20-05-2022

ILW = assert failure in C2; JavaFuzzer-generated program; use -XX:-SuperWordReductions = MMM = P3
05-05-2022

Assert was introduced by JDK-8279622. [~rcastanedalo], could you please have a look?
05-05-2022