RFR: 8325746: Refactor Loop Unswitching code [v8]
Emanuel Peter
epeter at openjdk.org
Mon Feb 26 10:01:02 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
Update makes sense. A few suggestions below.
src/hotspot/share/opto/ifnode.cpp line 466:
> 464: // In theory, we should not clone BaseCountedLoopEndNodes. But they can end up being used as normal If nodes when
> 465: // peeling a loop - they serve as zero-trip guard. Allow them as well.
> 466: assert(if_node_profile->Opcode() == Op_If || if_node_profile->is_RangeCheck()
`if_node_profile->is_RangeCheck()` seems excluded by the if-else above...
You could move the assert before the if, then it would be correct, I think
test/hotspot/jtreg/compiler/loopopts/TestBaseCountedEndLoopUnswitchCandidate.java line 31:
> 29: * @run main/othervm -XX:CompileCommand=compileonly,compiler.loopopts.TestBaseCountedEndLoopUnswitchCandidate::test*
> 30: * -Xcomp -XX:LoopMaxUnroll=0 -XX:-UseLoopPredicate -XX:-RangeCheckElimination
> 31: * compiler.loopopts.TestBaseCountedEndLoopUnswitchCandidate
Might it make sense to have a run with fewer flags?
test/hotspot/jtreg/compiler/loopopts/TestBaseCountedEndLoopUnswitchCandidate.java line 50:
> 48:
> 49:
> 50: public static void testLongCountedLoopEnd() {
Remove a newline
-------------
Marked as reviewed by epeter (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/17842#pullrequestreview-1900415966
PR Review Comment: https://git.openjdk.org/jdk/pull/17842#discussion_r1502325550
PR Review Comment: https://git.openjdk.org/jdk/pull/17842#discussion_r1502323589
PR Review Comment: https://git.openjdk.org/jdk/pull/17842#discussion_r1502326997
More information about the hotspot-compiler-dev
mailing list