RFR: 8282365: Consolidate and improve division by constant idealizations [v45]

Quan Anh Mai qamai at openjdk.org
Sat Jan 20 11:53:47 UTC 2024


On Sat, 20 Jan 2024 10:50:23 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

>> Quan Anh Mai has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   suggestion
>
> src/hotspot/share/opto/divconstants.cpp line 161:
> 
>> 159:       c_ovf = c > min_signed;
>> 160:       c += c - 1;
>> 161:       rc += rc - d;     // rc = 2 * rc - d
> 
> Well, `rc - d` usually underflows. This is benign on the supported CPUs, but I think the code proposed originally is clearer.
> It also makes clear that the subtraction in `-=` is safe, since `rc > d - rc`. With an addition `+=` one has to reason in reverse, so to say.
> Further, Common Subexpression Elimination can easily detect that the expression `d - rc` is identical to the one in the `if` condition. Not sure if CSE can detect that `rc - d` is `-(d - rc)` and emit a subtraction.
> Suggestion:
> 
>       rc -= d - rc;     // rc = 2 * rc - d

I think it makes it more uniform with the other case and since we are writing it as `rc = 2 * rc - d`, expanding it to `rc + rc - d` seems more natural. Note that the type is unsigned so overflow behaviour is not undefined.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/9947#discussion_r1460395700


More information about the hotspot-compiler-dev mailing list