[jdk18] RFR: 8279837: C2: assert(is_Loop()) failed: invalid node class: Region

Christian Hagedorn chagedorn at openjdk.java.net
Wed Jan 12 08:33:25 UTC 2022


On Tue, 11 Jan 2022 14:53:59 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

> 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/jdk18/blob/5aecb37211c2dec475c56dcc354b6bb4f7e3585e/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/jdk18/blob/5aecb37211c2dec475c56dcc354b6bb4f7e3585e/src/hotspot/share/opto/loopPredicate.cpp#L1427-L1430
> Thanks,
> Christian

Thanks Tobias for your review!

-------------

PR: https://git.openjdk.java.net/jdk18/pull/94


More information about the hotspot-compiler-dev mailing list