RFR: 8270366: C2: Add associative rule to add/sub node
Zhengyu Gu
zgu at openjdk.java.net
Thu Jul 15 16:44:17 UTC 2021
On Wed, 14 Jul 2021 09:22:32 GMT, Andrew Dinn <adinn at openjdk.org> wrote:
>> Can this rule cause the JIT to compute different results than the interpreter if there is integer overflow? Does the spec allow that?
>
>> Can this rule cause the JIT to compute different results than the interpreter if there is integer overflow?
>
> I don't believe so.
>
> It should obvious that unsigned arithmetic will always give the same result for any order of computation. Why? Well, if we compute the result for a sequence of n-bit operations in an unlimited bit field we can be sure the results are order independent because of the associativity law. Setting and clearing of higher bits because of overflow beyond n-bits will not change the result that appears in the low n bits.
>
> For signed arithmetic all we need to note is that for every signed n-bit operation that overflows (or underflows) there is an equivalent unsigned operation in 2*n bits that has the same bottom n-bits plus some extra non-zero bits in the top n bits. So, for any chain of k signed operations there will be an equivalent chain of unsigned operations in at most k*n bits which has the same low n bits. Re-ordering the unsigned operations would produce the same unsigned result which guarantees that an equivalent re-ordering of the signed operations will produce the same signed value in the low n bits.
@adinn @vnkozlov Thanks for the review
-------------
PR: https://git.openjdk.java.net/jdk/pull/4765
More information about the hotspot-compiler-dev
mailing list