[jdk18] RFR: 8279837: C2: assert(is_Loop()) failed: invalid node class: Region
Christian Hagedorn
chagedorn at openjdk.java.net
Tue Jan 11 15:02:00 UTC 2022
In the test case, we are attempting to apply `iteration_split_impl()` to a loop head which is a `RegionNode` and not a `LoopNode`. We then fail with an assertion when attempting to cast it.
This is quite an edge case. `build_loop_tree()` is initially adding a `NeverBranch` to an infinite inner loop. Afterwards, `beautify_loop()` makes progress on some other loop nest where the inner and outer loop share the same loop head. As a result, `build_loop_tree()` is called again:
https://github.com/openjdk/jdk/blob/2bbeae3f056243a224b0bda021f16cdcbee3b3d6/src/hotspot/share/opto/loopnode.cpp#L4184-L4189
Through `Root` -> `Halt` -> `CProj` -> `NeverBranch`, the infinite loop is now reachable and is built as child of `_ltree_root`. However, the `Region` is not yet a `Loop` node. This will only happen in the next iteration of loop opts when `beautify_loop()` is called again. We then fail with the assertion assuming that loop tree head nodes are always `LoopNodes`. Some more details can be found in the comments of the test.
The fix is straight forward to bail out of `iteration_split_impl()` for non-`LoopNodes`. We already do a similar bailout in other optimizations like loop predication:
https://github.com/openjdk/jdk/blob/2bbeae3f056243a224b0bda021f16cdcbee3b3d6/src/hotspot/share/opto/loopPredicate.cpp#L1427-L1430
Thanks,
Christian
-------------
Commit messages:
- 8279837: C2: assert(is_Loop()) failed: invalid node class: Region
Changes: https://git.openjdk.java.net/jdk18/pull/94/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk18&pr=94&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8279837
Stats: 87 lines in 2 files changed: 87 ins; 0 del; 0 mod
Patch: https://git.openjdk.java.net/jdk18/pull/94.diff
Fetch: git fetch https://git.openjdk.java.net/jdk18 pull/94/head:pull/94
PR: https://git.openjdk.java.net/jdk18/pull/94
More information about the hotspot-compiler-dev
mailing list