RFR: 8282365: Optimize divideUnsigned and remainderUnsigned for constants [v15]

Quan Anh Mai qamai at openjdk.org
Wed Jul 12 17:50:13 UTC 2023


On Mon, 3 Jul 2023 13:55:48 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> May I have a second review for this patch, please?
>
> @merykitty I just discussed the testing with @TobiHartmann . He just came across this test:
> `test/hotspot/jtreg/compiler/c2/TestUnsignedByteCompare1.java`.
> The cool thing is that you can "simulate" constants with `MethodHandles.constant`. At runtime apparently the invocation specualte-and-traps it to a constant value. That means you can just set a new value, it depopts, and hopefully eventually re-compiles with the next constants.
> 
> You could easily set up one of these tests per node. Any maybe throw in some interesting ranges for the `dividend`.
> 
> An interesting experiment would be to have a IR test that works with a random constant, and then have an IR rule that fails if we find a`div` node. At least for those cases where that should work. And then you can easily compare the div results with a non-compiled method that computes the same value.

@eme64 Thanks a lot for taking a look at this patch, I will address your remaining comments soon.

The basic idea of the transformation in `javaArithmetic.hpp` is to find `M` and `s` such that `x / c = floor(x * M / 2**s)` for every interesting value of `x`. The remaining transformation in `divnode.cpp` is to convert this calculation from integer arithmetic to modular arithmetic. This is easy if the representative in the congruence class of an operand is always equal to itself, in which case we can do the calculation directly. For other cases, we have to do additional calculation to take into consideration the difference between arithmetic calculations in 2 domains.

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

PR Comment: https://git.openjdk.org/jdk/pull/9947#issuecomment-1632957417


More information about the hotspot-compiler-dev mailing list