RFR: 8353290: C2: Refactor PhaseIdealLoop::is_counted_loop() [v2]

Cesar Soares Lucas cslucas at openjdk.org
Sat Apr 12 04:15:29 UTC 2025


On Thu, 10 Apr 2025 15:30:24 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:

>> This PR refactors `PhaseIdealLoop::is_counted_loop()` into (mostly) `CountedLoopConverter::is_counted_loop()` and `CountedLoopConverter::convert()` to decouple the detection and conversion code. This enables us to try different loop configurations easily and finally convert once a counted loop is found. 
>> 
>> A nested `PhaseIdealLoop::CountedLoopConverter` class is created to handle the context, but I'm not if this is the best name or place for it. Please let me know what you think.
>> 
>> Blocks [JDK-8336759](https://bugs.openjdk.org/browse/JDK-8336759).
>
> Kangcheng Xu has updated the pull request incrementally with one additional commit since the last revision:
> 
>   reviewer suggested changes

src/hotspot/share/opto/loopnode.hpp line 267:

> 265:     const TypeInteger* trunc_type = nullptr;
> 266:   };
> 267:   static TruncatedIncrement match_incr_with_optional_truncation(Node* expr, BasicType bt);

Just a drive-by comment: this function and some others that you created are returning a value by copy, for performance reasons it may be better to return a reference or even a pointer as usually is the case in HotSpot.

src/hotspot/share/opto/loopnode.hpp line 1276:

> 1274: 
> 1275:   struct LoopExitTest {
> 1276:     Node* cmp = nullptr;

I think it might be a good idea to use a more specific node type if you know before hand what kind of node the field will point to - in this case CmpNode*

src/hotspot/share/opto/loopnode.hpp line 1343:

> 1341:         _loop(loop),
> 1342:         _iv_bt(iv_bt) {
> 1343:       assert(phase != nullptr, "");

Would be nice to have an explanation of why the expression should be true.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24458#discussion_r2040546046
PR Review Comment: https://git.openjdk.org/jdk/pull/24458#discussion_r2040546249
PR Review Comment: https://git.openjdk.org/jdk/pull/24458#discussion_r2040546536


More information about the hotspot-compiler-dev mailing list