RFR: 8267239: C1: RangeCheckElimination for % operator if divisor is IntConstant [v3]
Yi Yang
yyang at openjdk.java.net
Wed May 19 02:42:03 UTC 2021
> % operator follows from this rule that the result of the remainder operation can be negative only if the dividend is negative, and can be positive only if the dividend is positive. Moreover, the magnitude of the result is always less than the magnitude of the divisor(See [LS 15.17.3](https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.17.3)).
>
> So if `y` is a constant integer and not equal to 0, then we can deduce the bound of remainder operation:
> - x % -y ==> [0, y - 1] RCE
> - x % y ==> [0, y - 1] RCE
> - -x % y ==> [-y + 1, 0]
> - -x % -y ==> [-y + 1, 0]
>
> Based on above rationale, we can apply RCE for the remainder operations whose dividend is constant integer and >= 0, e.g.:
>
>
> for(int i=0;i<1000;i++){
> int top5 = arr[i%5]; // Apply RCE if arr is a loop invariant
> ....
> }
>
>
> For more detailed RCE results, please check out the attachment on JBS, it was generated by ArithmeticRemRCE with additional flags -XX:+TraceRangeCheckElimination -XX:+PrintIR.
>
> Testing:
> - test/hotspot/jtreg/compiler/c1/(slowdebug)
Yi Yang has updated the pull request incrementally with one additional commit since the last revision:
missing whitespace; more comment
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/4083/files
- new: https://git.openjdk.java.net/jdk/pull/4083/files/64bdf0f2..35aaa375
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=4083&range=02
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=4083&range=01-02
Stats: 5 lines in 1 file changed: 3 ins; 0 del; 2 mod
Patch: https://git.openjdk.java.net/jdk/pull/4083.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/4083/head:pull/4083
PR: https://git.openjdk.java.net/jdk/pull/4083
More information about the hotspot-compiler-dev
mailing list