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

Emanuel Peter epeter at openjdk.org
Thu Aug 10 11:25:34 UTC 2023


On Wed, 12 Jul 2023 17:47:26 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> @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.

@merykitty I'm mostly out of the office until September 9 (FYI).

It would be really cool if this made it in. I'm currently playing with `MethodHandles.constant`, and it is really easy to have "random" compile time constants.

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

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


More information about the hotspot-compiler-dev mailing list