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

Vladimir Kozlov kvn at openjdk.org
Thu Sep 29 18:34:22 UTC 2022


On Thu, 29 Sep 2022 14:35:12 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> It only works for cases with narrowed type. Which is not common case unless Java user's code check for that.
>
> May you expand on this, please? How can I know that a divisor is negative without using its type information? Thanks.

What I am trying to say is that you can not replace removed runtime code in `C2_MacroAssembler` with only this code in IR (which covers only part of cases). You need additional code for case when divisor is not constant and its type is unknown. You need to generate IR code similar to runtime code with explicit runtime check for negative divisor and calculation `(dividend & ~(dividend - divisor)) >>> (Integer.SIZE - 1)`. Which will be very disruptive for IR graph.

My suggestion is to leave this your code for cases when type is known - it will allow to avoid `div` instruction generation and it is good. But also restore `C2_MacroAssembler` code you removed - it will cover the rest of cases when type (negativity) of divisor is not known during compilation.

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

PR: https://git.openjdk.org/jdk/pull/9947


More information about the hotspot-compiler-dev mailing list