JDK-8255663 : Support multiple tails in C2 type flow analysis
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 16,17,21,23,24
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2020-10-30
  • Updated: 2024-08-21
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
Type flow analysis in C2 could end up with multiple blocks marked as loop head (lphd when printing with -XX:+CIPrintTypeFlow) while the Java program itself has only one loop. As a consequence, the IR contains also multiple LoopNodes. For example, C2 generates initially two LoopNodes for the following simple program (Run with -Xcomp):

public void mainTest() {
    int x = 0;
    int i = 1;
    while (++i < 35) {
        x = 6;
        if (i == 3) {
            x = 7;
        } else {
            x = 9;
        }
    }
}

The C2 type flow analysis code does some loop head cloning in ciTypeFlow::clone_loop_head() after the first pass. In this method, the next block for the tail of the loop is set to a clone of the loop head block (marked as backedge copy). We want to ensure that the loop head block is only entered by a single entry block. But in the simple program above, we actually have two loop tails coming from the if or the else block. There is no unique tail. Because of that, we set the original loop head block (which we just cloned) again as loop head while building the loop tree in ciTypeFlow::build_loop_tree() again after the loop head cloning step. This results in having two loop heads and two LoopNodes in the IR.

This seems to be inefficient as it results in more nodes and possibly unneeded loop optimizations compared to just having a unique loop head. This RFE should support the handling for multiple tails with the goal to have a unique block marked as loop head and eventually a single LoopNode in the IR.
Comments
I've attached an old patch with an idea to fix this applied on https://github.com/openjdk/jdk/commit/c2c0cb2a4372d78658326461562363de9a1a194f. This could be used as a starting point even though it most likely does not apply anymore and might require some rework.
21-08-2024

Tests for this RFE are not really useful as we can only check manually if there is a unique LoopNode. However, this RFE is a very good candidate for IR-matching and we should add a test for it, once this is implemented (see JDK-8254129).
30-10-2020