RFR: 8357726: C2 fails to recognize the counted loop when induction variable range is changed multiple times

Emanuel Peter epeter at openjdk.org
Tue Jun 3 07:29:52 UTC 2025


On Tue, 3 Jun 2025 02:09:10 GMT, Xiaohong Gong <xgong at openjdk.org> wrote:

>> test/hotspot/jtreg/compiler/c2/irTests/TestCountedLoopCastIV.java line 174:
>> 
>>> 172: 
>>> 173:     public static void main(String[] args) {
>>> 174:         TestFramework.runWithFlags("-XX:LoopUnrollLimit=0");
>> 
>> What is the reason for the flag here? Do you really need it?
>
> Thanks so much for your review! This flag prevents the loop being unrolled and splited (i.e. pre-main-post loop mode) as well. So that the compiler can get just one `CountedLoop` in the case, and we can make sure it is generated by the loop exactly. Checking the count of `CountedLoop` >0 is also fine to me without this flag. I just want to avoid any noise. WDYT?

I would suggest this:
Have one run with `-XX:LoopUnrollLimit=0`, and one run without setting the flag. Write some comments about why you are setting the flag.

You could then restrict your IR rule to `LoopUnrollLimit=0`. This is where you can most easily reproduce the multiple CastII problem, and it is the easiest to write an IR rule and explain. You should probably leave a comment as to why you set that flag.

But maybe you also succeed in writing an IR rule for `LoopUnrollLimit > 0`, though it could be a little more noisy/complicated. It would just be nice to see that things work fine without having to set special flags.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25539#discussion_r2122963453


More information about the hotspot-compiler-dev mailing list