RFR: 8291775: C2: assert(r != __null && r->is_Region()) failed: this phi must have a region
Christian Hagedorn
chagedorn at openjdk.org
Mon Aug 15 12:47:57 UTC 2022
[JDK-8271341](https://bugs.openjdk.org/browse/JDK-8271341) fixed a case for string opts where a diamond `Region/If` in the middle of a chain of calls that are optimized out is not folded away correctly in IGVN, leading to a broken graph. The problem in the test case of JDK-8271341 was the following:
One of the inputs of the `Cmp` nodes of the `If` is replaced by top (the data projection of the removed call into the `Cmp` node). During IGVN, top propagated too quickly to the `If` before the `Region/If` diamond could be folded away. As a result, the control flow below the `If` became dead. The fix was to eagerly fold the `Region/If` diamond in string opts by replacing the `Region` by the control input of the `If` (see https://github.com/openjdk/jdk/pull/4944):

Replaced `396 Region` by control input of `If` (`330 IfTrue`):

The reason why we can rewire the phis to a non-region during string opts is because all phis are dead and will be removed. In the testcase of JDK-8271341, this is done in `PhaseRemoveUseless` because the data `424 Phi` has no users after string opts anymore.
However, in the test case of this bug (actually the same test case but run with `-XX:+AlwaysIncrementalInline`), we have an additional memory phi which is actually dead but not removed by `PhaseRemoveUseless` because it still has other users at that point. The memory phi would eventually be removed during IGVN but the problem is that it is unexpected to process a phi with a non-region control input and we fail with the assertion in `PhiNode::Ideal()`.
The fix I propose is to not replace the `Region` node with the control input of the `If` as in JDK-8271341 but instead setting the boolean input of the `If` node to a constant (doesn't matter if 0 or 1 since the phis are dead anyways). If we then process the `If` or `IfTrue/IfFalse` before the `Region` in IGVN, we simply fold the node. This allows IGVN to safely remove a diamond `Region/If` without interference of top from string opts. The memory phi is eventually removed during IGVN.
Thanks,
Christian
-------------
Commit messages:
- 8291775: C2: assert(r != __null && r->is_Region()) failed: this phi must have a region
Changes: https://git.openjdk.org/jdk/pull/9878/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=9878&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8291775
Stats: 8 lines in 2 files changed: 5 ins; 0 del; 3 mod
Patch: https://git.openjdk.org/jdk/pull/9878.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/9878/head:pull/9878
PR: https://git.openjdk.org/jdk/pull/9878
More information about the hotspot-compiler-dev
mailing list