Skip to content

Commit a447e9b

Browse files
author
vlivanov
committed
8190869: C2: missing strength reduction of Math.pow(x, 2.0D) to x*x
Reviewed-by: kvn
1 parent 4b39a26 commit a447e9b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/hotspot/cpu/x86/macroAssembler_x86_pow.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,11 @@ ALIGNED_(8) juint _log2_pow[] =
765765
0xfefa39efUL, 0x3fe62e42UL, 0xfefa39efUL, 0xbfe62e42UL
766766
};
767767

768+
ALIGNED_(8) juint _DOUBLE2[] =
769+
{
770+
0x00000000UL, 0x40000000UL
771+
};
772+
768773
//registers,
769774
// input: xmm0, xmm1
770775
// scratch: xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7
@@ -803,13 +808,21 @@ void MacroAssembler::fast_pow(XMMRegister xmm0, XMMRegister xmm1, XMMRegister xm
803808
address HIGHMASK_LOG_X = (address)_HIGHMASK_LOG_X;
804809
address HALFMASK = (address)_HALFMASK;
805810
address log2 = (address)_log2_pow;
811+
address DOUBLE2 = (address)_DOUBLE2;
806812

807813

808814
bind(start);
809815
subq(rsp, 40);
810816
movsd(Address(rsp, 8), xmm0);
811817
movsd(Address(rsp, 16), xmm1);
812818

819+
// Special case: pow(x, 2.0) => x * x
820+
movdq(tmp1, xmm1);
821+
cmp64(tmp1, ExternalAddress(DOUBLE2));
822+
jccb(Assembler::notEqual, B1_2);
823+
mulsd(xmm0, xmm0);
824+
jmp(B1_5);
825+
813826
bind(B1_2);
814827
pextrw(eax, xmm0, 3);
815828
xorpd(xmm2, xmm2);

src/hotspot/share/opto/library_call.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -1789,10 +1789,19 @@ bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) {
17891789
return StubRoutines::dexp() != NULL ?
17901790
runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dexp(), "dexp") :
17911791
runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dexp), "EXP");
1792-
case vmIntrinsics::_dpow:
1793-
return StubRoutines::dpow() != NULL ?
1794-
runtime_math(OptoRuntime::Math_DD_D_Type(), StubRoutines::dpow(), "dpow") :
1792+
case vmIntrinsics::_dpow: {
1793+
Node* exp = round_double_node(argument(2));
1794+
const TypeD* d = _gvn.type(exp)->isa_double_constant();
1795+
if (d != NULL && d->getd() == 2.0) {
1796+
// Special case: pow(x, 2.0) => x * x
1797+
Node* base = round_double_node(argument(0));
1798+
set_result(_gvn.transform(new MulDNode(base, base)));
1799+
return true;
1800+
}
1801+
return StubRoutines::dexp() != NULL ?
1802+
runtime_math(OptoRuntime::Math_DD_D_Type(), StubRoutines::dpow(), "dpow") :
17951803
runtime_math(OptoRuntime::Math_DD_D_Type(), FN_PTR(SharedRuntime::dpow), "POW");
1804+
}
17961805
#undef FN_PTR
17971806

17981807
// These intrinsics are not yet correctly implemented

0 commit comments

Comments
 (0)