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

Quan Anh Mai qamai at openjdk.org
Fri Jan 19 20:06:05 UTC 2024


On Thu, 18 Jan 2024 15:29:41 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:
>> 
>>   update include order and license year
>
> src/hotspot/share/opto/divconstants.cpp line 176:
> 
>> 174:       qv = qv * 2;
>> 175:       rv = new_rv;
>> 176:     }
> 
> One could perhaps avoid overflows in computing `rc` and `rv`, and simplify the corresponding tests, like so (not sure if this improves anything in practical terms, though):
> Suggestion:
> 
>     if (d - rc < rc) {  // 2 * rc > d
>       c_ovf = c > min_signed;
>       c += c - 1;
>       rc -= d - rc;  // rc = 2 * rc - d
>     } else {  // 2 * rc <= d
>       c_ovf = c >= min_signed;
>       c += c;
>       rc += rc;  // rc = 2 * rc
>     }
> 
>     if (rv >= v - rv) {  // 2 * rv >= v
>       qv_ovf = qv >= min_signed;
>       qv += qv + 1;
>       rv -= v - rv;  // rv = 2 * rv - v
>     } else {  // 2 * rv < v
>       qv_ovf = qv >= min_signed;
>       qv += qv;
>       rv += rv;  // rv = 2 * rv
>     }

That's a good idea, I have changed the formulae as your suggestion.

Thanks a lot for your effort, this is really dense in mathematical transformations, I really appreciate it.

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

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


More information about the hotspot-compiler-dev mailing list