RFR: 8292660: C2: blocks made unreachable by NeverBranch-to-Goto conversion are removed incorrectly [v3]

Roland Westrelin roland at openjdk.org
Fri Sep 2 06:44:06 UTC 2022


On Fri, 2 Sep 2022 06:36:50 GMT, Roberto Castañeda Lozano <rcastanedalo at openjdk.org> wrote:

>> This changeset addresses three issues in the current removal of unreachable blocks after NeverBranch-to-goto conversion (introduced recently by [JDK-8292285](https://bugs.openjdk.org/browse/JDK-8292285)):
>> 
>> 1. The [unreachable block removal and pre-order index update loop](https://github.com/openjdk/jdk/blob/7b5f9edb59ef763acca80724ca37f3624d720d06/src/hotspot/share/opto/block.cpp#L613-L621) skips the block next to the removed one, and iterates beyond the end of the block list (`PhaseCFG::_blocks`). Skipping blocks can lead to duplicate pre-order indices (`Block::_pre_order`) and/or pre-order indices greater than the size of the block list, causing problems in later transformations.
>> 
>> 2. The [outer block traversal loop](https://github.com/openjdk/jdk/blob/7b5f9edb59ef763acca80724ca37f3624d720d06/src/hotspot/share/opto/block.cpp#L698-L729) iterates beyond the end of the block list whenever one or more unreachable blocks are removed.
>> 
>> 3. Transitively unreachable blocks (such as B10 in the following example), arising in methods with multiple infinite loops, are not removed:
>> 
>> ![transitive](https://user-images.githubusercontent.com/8792647/186109043-416213b7-8735-41de-9910-acf0997db095.png)
>> 
>> This changeset addresses issues 2 and 3 by decoupling NeverBranch-to-goto conversion from removal of unreachable code. Instead of removing the blocks eagerly, the removal is postponed to a later phase that works in an iterative worklist fashion, making it possible to remove transitively unreachable blocks such as B10 in the above example. Postponing removal to a later phase (where `get_block(i)->_pre_order == i` holds) also simplifies addressing issue 1: in the changeset, it is sufficient to iterate over the blocks that follow the removed block in the block list to decrement their `_pre_order` index.
>> 
>> #### Testing
>> 
>> - tier1-3 (windows-x64, linux-x64, linux-aarch64, and macosx-x64; release and debug mode).
>> - tier4-7 (linux-x64; debug mode).
>> - fuzzing (~1 h. on each platform).
>
> Roberto Castañeda Lozano has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Iterate only over blocks with larger _pre_order than 'dead'

Looks good to me.

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

Marked as reviewed by roland (Reviewer).

PR: https://git.openjdk.org/jdk/pull/9976


More information about the hotspot-compiler-dev mailing list