RFR: 8325746: Refactor Loop Unswitching code [v8]

Christian Hagedorn chagedorn at openjdk.org
Mon Feb 26 07:23:58 UTC 2024


On Mon, 26 Feb 2024 07:14:29 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

>> To simplify the review of https://github.com/openjdk/jdk/pull/16877, I've decided to split off some code into separate sub-tasks.
>> 
>> This sub-task focuses on the code refactoring done in Loop Unswitching. I've incorporated the feedback from @eme64 at https://github.com/openjdk/jdk/pull/16877 in the proposed changes.
>> 
>> #### Changes
>> - Adding a more detailed description about the Loop Unswitching optimization itself below the file header.
>> - Renaming `fast loop` -> `true-path-loop` and `slow loop` -> `false-path-loop` since we don't really know which one is faster and to avoid keeping a mental map of which path goes into which unswitched loop version.
>> - Creating new classes:
>>   - `UnswitchedLoopSelector` to create the unswitched loop selector `If` (i.e. the If node that selects at runtime which unswitched loop version is executed) based on the invariant and non-loop-exiting unswitch candidate `If`.
>>   - `OriginalLoop` to do the actual unswitching (i.e. loop cloning, predicates cloning and fixing the graph to the loop selector `If`).
>> - Extracting methods in `do_unswitching()` to clean it up further.
>> - Improving `TraceLoopUnswitching` result printing.
>> - Adding some shared utility methods.
>> 
>> #### Possible Follow-Up RFEs
>> There are possible follow-up opportunities to further improve the loop unswitching which, however, would go to far in the context of fixing Assertion Predicates. We could follow up with RFEs to tackle these:
>> - At some point it might be good to have a dedicated `LoopUnswitching` class to split all the methods off from `PhaseIdealLoop`. This would also avoid noisy "loop_unswitching" prefixes.
>> - Bailout code in `has_control_dependencies_from_predicates()` is too conservative. I have already some code to improve that in the full fix for Assertion Predicates which I plan to split off and propose separatly.
>> - `TraceLoopUnswitching` currently only prints the result and if it failed. We might want to improve that in the future to cover more steps to make it useful for debugging (would require some more fine-grained debug levels, though).
>
> Christian Hagedorn has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix If creation and add assert with test

Testing showed that `make_with_same_profile()` could also be called with a `BaseCountedEndLoopNode` (attached extracted test for int and long). We could be unswitching on a `BaseCountedEndLoopNode` after peeling one iteration - the exit test then serves as a zero trip guard. I've changed the code accordingly to fall back to `IfNode` if it's not a `RangeCheckNode`. I've also changed the assertion to allow all these nodes but not a `ParsePredicateNode` on which `make_with_same_profile()` should never be called.

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

PR Comment: https://git.openjdk.org/jdk/pull/17842#issuecomment-1963463544


More information about the hotspot-compiler-dev mailing list