RFR: 8308504: C2: "malformed control flow" after JDK-8303466
Emanuel Peter
epeter at openjdk.org
Mon Jul 10 12:52:20 UTC 2023
On Thu, 22 Jun 2023 13:54:37 GMT, Roland Westrelin <roland at openjdk.org> wrote:
>>> > It doesn't seem to be true that the loop incr never overflows in the general case. See this example:
>>>
>>> But don't we check that the limit is small enough at runtime, such that there cannot be an overflow? We do that with `check_stride_overflow` and `insert_loop_limit_check_predicate`. And if it does overflow, we do not go into the counted-loop, but we uncommon trap, I think. Or are you sure that we actually enter the counted-loop with your example? Or just some peeled version?
>>
>> Ran with:
>>
>> -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-TieredCompilation -XX:CompileOnly=TestOverflowCountedLoopIncr::test -XX:CompileCommand=quiet -XX:LoopMaxUnroll=0 -XX:+UseCountedLoopSafepoints
>>
>> I see a single counted loop, no uncommon trap in the IR.
>
>> @rwestrel so you think the `incr` can indeed overflow, and that is ok? Or would that be a bug? Why do we even have the loop limit check in the first place, if overflow is allowed?
>
> To guarantee no overflow requires init < limit (for a loop going up). Nothing guarantees that when c2 pattern matches a counted loop. Whether overflow is a problem or not would require taking a closer look at individual optimizations.
@rwestrel I finally looked into your overflow-example. Ran it like this:
`./java -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-TieredCompilation -XX:CompileOnly=TestOverflowCountedLoopIncr::test -XX:CompileCommand=quiet -XX:LoopMaxUnroll=0 -XX:+UseCountedLoopSafepoints -XX:+PrintIdeal -Xbatch TestOverflowCountedLoopIncr.java`
This is the graph I get:

These are the constants:
1 Con === 0 [[ ]] #top
28 ConI === 0 [[ 152 ]] #int:1
153 ConI === 0 [[ 173 181 ]] #int:min+100
157 ConL === 0 [[ 158 ]] #long:1176
189 ConF === 0 [[ 187 ]] #ftcon:2.000000
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14331#issuecomment-1628893068
More information about the hotspot-compiler-dev
mailing list