RFR: 8267376: C2: Deduce the result bound of ModXNode
Yi Yang
yyang at openjdk.java.net
Mon Jul 19 08:44:53 UTC 2021
On Tue, 25 May 2021 03:16:37 GMT, Yi Yang <yyang at openjdk.org> wrote:
> if the divisor is a constant and not equal to 0, it's possible to deduce the final bound of ModXNode given that the following rules:
>
> x % -y ==> [0, y - 1]
> x % y ==> [0, y - 1]
> -x % y ==> [-y + 1, 0]
> -x % -y ==> [-y + 1, 0]
>
>
> FYI: The original purpose of this patch is to eliminate array access range check(e.g. `arr[val%5]`) which discussed in https://github.com/openjdk/jdk/pull/4083#issuecomment-846971247, because ModXNode would be transformed to other nodes during IGVN, RangeCheckNode is still generated when accessing array element. Regardless of eliminating array access range check, it's still reasonable to deduce the bound of % operation if the divisor is known constant.
I've tested it largely with assertions but it can not reach `i2->is_con()` branch currently(since idealization checks whether y is a constant value and transforms ModINode to other nodes), maybe these paths can be used in the future. I believe this is more like a refactor, it simplifies existing ModXNode::Value.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4179
More information about the hotspot-compiler-dev
mailing list