RFR: 8267928: Loop predicate gets inexact loop limit before PhaseIdealLoop::rc_predicate

Yi Yang yyang at openjdk.java.net
Tue Jun 1 07:35:21 UTC 2021


On Tue, 1 Jun 2021 07:00:11 GMT, Nils Eliasson <neliasso at openjdk.org> wrote:

> Testing looks good.
> 
> Do you have any concrete example for when this happens?

Yes, this happens in a simple program:

     static int foo14(int x){
        int sum=0;
        for(int i=0;i<50;i+=2){
            sum += arr[i];
        }
        return sum;
    }

Here C2 found a range check for counted loop `arr[i]`, it would try to build lower bound and upper bound tests for that. exact_limit fails to see a HasExactTripCount flag since it would be set after performing loop predicate(iteration_split), so it creates a new LoopLimitNode and register_new_node:

https://github.com/openjdk/jdk/blob/ae2f37f868bfdcb3d46098e91ed537fb199d7dbe/src/hotspot/share/opto/loopnode.cpp#L1717-L1733

register_new_node does not carry out optimization immediately.  When using this LoopLimitNode in rc_predicate, C2 always observes TypeInt::INT and falls into overflow branch:

https://github.com/openjdk/jdk/blob/ae2f37f868bfdcb3d46098e91ed537fb199d7dbe/src/hotspot/share/opto/loopPredicate.cpp#L711-L730

![image](https://user-images.githubusercontent.com/5010047/120281514-9eaa5c00-c2eb-11eb-8065-6e5f77e01f3d.png)

After applying this patch, C2 thinks it's impossible to get an overflow(50-2 >= 0) thus falls into the right branch:

![image](https://user-images.githubusercontent.com/5010047/120283717-1083a500-c2ee-11eb-802f-e0e6fed8074d.png)

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

PR: https://git.openjdk.java.net/jdk/pull/4247


More information about the hotspot-compiler-dev mailing list