RFR: 8265940: Enable C2's optimization for Math.pow(x, 0.5) on all platforms

Vladimir Kozlov kvn at openjdk.java.net
Wed Apr 28 16:25:52 UTC 2021


On Wed, 28 Apr 2021 08:10:36 GMT, Jie Fu <jiefu at openjdk.org> wrote:

> Hi all,
> 
> I'd like to enable C2's optimization for Math.pow(x, 0.5) on all platforms.
> 
> This is fine because:
>  1) For x86, it will call the assembly stubs.
>     This opt has already been implemented for x86_64 [1]. 
>     And the x86_32 version is added in this patch.
>  2) For non-x86, it will call the shared runtime c code [2], which does the same opt too.
> 
> Testing:
>   - tier1~3 on Linux/{x86_32, x86_64}, no regression
> 
> Thanks,
> Best regards,
> Jie
> 
> 
> [1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/x86/macroAssembler_x86_pow.cpp#L838
> [2] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/runtime/sharedRuntimeTrans.cpp#L497

The fix looks good.

src/hotspot/cpu/x86/macroAssembler_x86_pow.cpp line 2574:

> 2572:   jccb(Assembler::parity, L_NOT_DOUBLE0DOT5);
> 2573:   ucomisd(xmm0, ExternalAddress(DOUBLE0));
> 2574:   jccb(Assembler::belowEqual, L_NOT_DOUBLE0DOT5); // pow(x, 0.5) => sqrt(x) only for x > 0.0

Add comment about why 0. case is skipped: -0.0 case.

src/hotspot/share/opto/library_call.cpp line 1646:

> 1644:       set_result(_gvn.transform(new MulDNode(base, base)));
> 1645:       return true;
> 1646:     } else if (d->getd() == 0.5 && Matcher::match_rule_supported(Op_SqrtD)) {

Add the same comment at line #1654 explaining why 0. is excluded.

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

Changes requested by kvn (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/3755


More information about the hotspot-compiler-dev mailing list