8026844: Various Math functions needs intrinsification

Reviewed-by: kvn, twisti
This commit is contained in:
Rickard Bäckman 2013-10-18 10:41:56 +02:00
parent 073409c543
commit 615376fb9b
52 changed files with 2970 additions and 270 deletions

View file

@ -2022,6 +2022,10 @@ const RegMask Matcher::mathExactI_result_proj_mask() {
return G1_REGI_mask();
}
const RegMask Matcher::mathExactL_result_proj_mask() {
return G1_REGL_mask();
}
const RegMask Matcher::mathExactI_flags_proj_mask() {
return INT_FLAGS_mask();
}

View file

@ -1405,6 +1405,15 @@ void Assembler::imull(Register dst, Register src, int value) {
}
}
void Assembler::imull(Register dst, Address src) {
InstructionMark im(this);
prefix(src, dst);
emit_int8(0x0F);
emit_int8((unsigned char) 0xAF);
emit_operand(dst, src);
}
void Assembler::incl(Address dst) {
// Don't use it directly. Use MacroAssembler::increment() instead.
InstructionMark im(this);
@ -5024,6 +5033,14 @@ void Assembler::imulq(Register dst, Register src, int value) {
}
}
void Assembler::imulq(Register dst, Address src) {
InstructionMark im(this);
prefixq(src, dst);
emit_int8(0x0F);
emit_int8((unsigned char) 0xAF);
emit_operand(dst, src);
}
void Assembler::incl(Register dst) {
// Don't use it directly. Use MacroAssembler::incrementl() instead.
// Use two-byte form (one-byte from is a REX prefix in 64-bit mode)

View file

@ -1162,9 +1162,13 @@ private:
void imull(Register dst, Register src);
void imull(Register dst, Register src, int value);
void imull(Register dst, Address src);
void imulq(Register dst, Register src);
void imulq(Register dst, Register src, int value);
#ifdef _LP64
void imulq(Register dst, Address src);
#endif
// jcc is the generic conditional branch generator to run-

View file

@ -1538,6 +1538,11 @@ const RegMask Matcher::mathExactI_result_proj_mask() {
return EAX_REG_mask();
}
const RegMask Matcher::mathExactL_result_proj_mask() {
ShouldNotReachHere();
return RegMask();
}
const RegMask Matcher::mathExactI_flags_proj_mask() {
return INT_FLAGS_mask();
}
@ -7519,7 +7524,7 @@ instruct cmovL_regUCF(cmpOpUCF cop, eFlagsRegUCF cr, eRegL dst, eRegL src) %{
//----------Arithmetic Instructions--------------------------------------------
//----------Addition Instructions----------------------------------------------
instruct addExactI_rReg(eAXRegI dst, rRegI src, eFlagsReg cr)
instruct addExactI_eReg(eAXRegI dst, rRegI src, eFlagsReg cr)
%{
match(AddExactI dst src);
effect(DEF cr);
@ -7531,7 +7536,7 @@ instruct addExactI_rReg(eAXRegI dst, rRegI src, eFlagsReg cr)
ins_pipe(ialu_reg_reg);
%}
instruct addExactI_rReg_imm(eAXRegI dst, immI src, eFlagsReg cr)
instruct addExactI_eReg_imm(eAXRegI dst, immI src, eFlagsReg cr)
%{
match(AddExactI dst src);
effect(DEF cr);
@ -7543,6 +7548,20 @@ instruct addExactI_rReg_imm(eAXRegI dst, immI src, eFlagsReg cr)
ins_pipe(ialu_reg_reg);
%}
instruct addExactI_eReg_mem(eAXRegI dst, memory src, eFlagsReg cr)
%{
match(AddExactI dst (LoadI src));
effect(DEF cr);
ins_cost(125);
format %{ "ADD $dst,$src\t# addExact int" %}
ins_encode %{
__ addl($dst$$Register, $src$$Address);
%}
ins_pipe( ialu_reg_mem );
%}
// Integer Addition Instructions
instruct addI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
match(Set dst (AddI dst src));
@ -7851,6 +7870,44 @@ instruct xchgP( memory mem, pRegP newval) %{
%}
//----------Subtraction Instructions-------------------------------------------
instruct subExactI_eReg(eAXRegI dst, rRegI src, eFlagsReg cr)
%{
match(SubExactI dst src);
effect(DEF cr);
format %{ "SUB $dst, $src\t# subExact int" %}
ins_encode %{
__ subl($dst$$Register, $src$$Register);
%}
ins_pipe(ialu_reg_reg);
%}
instruct subExactI_eReg_imm(eAXRegI dst, immI src, eFlagsReg cr)
%{
match(SubExactI dst src);
effect(DEF cr);
format %{ "SUB $dst, $src\t# subExact int" %}
ins_encode %{
__ subl($dst$$Register, $src$$constant);
%}
ins_pipe(ialu_reg_reg);
%}
instruct subExactI_eReg_mem(eAXRegI dst, memory src, eFlagsReg cr)
%{
match(SubExactI dst (LoadI src));
effect(DEF cr);
ins_cost(125);
format %{ "SUB $dst,$src\t# subExact int" %}
ins_encode %{
__ subl($dst$$Register, $src$$Address);
%}
ins_pipe( ialu_reg_mem );
%}
// Integer Subtraction Instructions
instruct subI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
match(Set dst (SubI dst src));
@ -7919,6 +7976,16 @@ instruct negI_eReg(rRegI dst, immI0 zero, eFlagsReg cr) %{
ins_pipe( ialu_reg );
%}
instruct negExactI_eReg(eAXRegI dst, eFlagsReg cr) %{
match(NegExactI dst);
effect(DEF cr);
format %{ "NEG $dst\t# negExact int"%}
ins_encode %{
__ negl($dst$$Register);
%}
ins_pipe(ialu_reg);
%}
//----------Multiplication/Division Instructions-------------------------------
// Integer Multiplication Instructions
@ -8131,6 +8198,46 @@ instruct mulL_eReg_con(eADXRegL dst, immL_127 src, rRegI tmp, eFlagsReg cr) %{
ins_pipe( pipe_slow );
%}
instruct mulExactI_eReg(eAXRegI dst, rRegI src, eFlagsReg cr)
%{
match(MulExactI dst src);
effect(DEF cr);
ins_cost(300);
format %{ "IMUL $dst, $src\t# mulExact int" %}
ins_encode %{
__ imull($dst$$Register, $src$$Register);
%}
ins_pipe(ialu_reg_reg_alu0);
%}
instruct mulExactI_eReg_imm(eAXRegI dst, rRegI src, immI imm, eFlagsReg cr)
%{
match(MulExactI src imm);
effect(DEF cr);
ins_cost(300);
format %{ "IMUL $dst, $src, $imm\t# mulExact int" %}
ins_encode %{
__ imull($dst$$Register, $src$$Register, $imm$$constant);
%}
ins_pipe(ialu_reg_reg_alu0);
%}
instruct mulExactI_eReg_mem(eAXRegI dst, memory src, eFlagsReg cr)
%{
match(MulExactI dst (LoadI src));
effect(DEF cr);
ins_cost(350);
format %{ "IMUL $dst, $src\t# mulExact int" %}
ins_encode %{
__ imull($dst$$Register, $src$$Address);
%}
ins_pipe(ialu_reg_mem_alu0);
%}
// Integer DIV with Register
instruct divI_eReg(eAXRegI rax, eDXRegI rdx, eCXRegI div, eFlagsReg cr) %{
match(Set rax (DivI rax div));

View file

@ -1653,6 +1653,10 @@ const RegMask Matcher::mathExactI_result_proj_mask() {
return INT_RAX_REG_mask();
}
const RegMask Matcher::mathExactL_result_proj_mask() {
return LONG_RAX_REG_mask();
}
const RegMask Matcher::mathExactI_flags_proj_mask() {
return INT_FLAGS_mask();
}
@ -6962,6 +6966,58 @@ instruct addExactI_rReg_imm(rax_RegI dst, immI src, rFlagsReg cr)
ins_pipe(ialu_reg_reg);
%}
instruct addExactI_rReg_mem(rax_RegI dst, memory src, rFlagsReg cr)
%{
match(AddExactI dst (LoadI src));
effect(DEF cr);
ins_cost(125); // XXX
format %{ "addl $dst, $src\t# addExact int" %}
ins_encode %{
__ addl($dst$$Register, $src$$Address);
%}
ins_pipe(ialu_reg_mem);
%}
instruct addExactL_rReg(rax_RegL dst, rRegL src, rFlagsReg cr)
%{
match(AddExactL dst src);
effect(DEF cr);
format %{ "addq $dst, $src\t# addExact long" %}
ins_encode %{
__ addq($dst$$Register, $src$$Register);
%}
ins_pipe(ialu_reg_reg);
%}
instruct addExactL_rReg_imm(rax_RegL dst, immL32 src, rFlagsReg cr)
%{
match(AddExactL dst src);
effect(DEF cr);
format %{ "addq $dst, $src\t# addExact long" %}
ins_encode %{
__ addq($dst$$Register, $src$$constant);
%}
ins_pipe(ialu_reg_reg);
%}
instruct addExactL_rReg_mem(rax_RegL dst, memory src, rFlagsReg cr)
%{
match(AddExactL dst (LoadL src));
effect(DEF cr);
ins_cost(125); // XXX
format %{ "addq $dst, $src\t# addExact long" %}
ins_encode %{
__ addq($dst$$Register, $src$$Address);
%}
ins_pipe(ialu_reg_mem);
%}
instruct addI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
%{
match(Set dst (AddI dst src));
@ -7574,6 +7630,80 @@ instruct subI_mem_imm(memory dst, immI src, rFlagsReg cr)
ins_pipe(ialu_mem_imm);
%}
instruct subExactI_rReg(rax_RegI dst, rRegI src, rFlagsReg cr)
%{
match(SubExactI dst src);
effect(DEF cr);
format %{ "subl $dst, $src\t# subExact int" %}
ins_encode %{
__ subl($dst$$Register, $src$$Register);
%}
ins_pipe(ialu_reg_reg);
%}
instruct subExactI_rReg_imm(rax_RegI dst, immI src, rFlagsReg cr)
%{
match(SubExactI dst src);
effect(DEF cr);
format %{ "subl $dst, $src\t# subExact int" %}
ins_encode %{
__ subl($dst$$Register, $src$$constant);
%}
ins_pipe(ialu_reg_reg);
%}
instruct subExactI_rReg_mem(rax_RegI dst, memory src, rFlagsReg cr)
%{
match(SubExactI dst (LoadI src));
effect(DEF cr);
ins_cost(125);
format %{ "subl $dst, $src\t# subExact int" %}
ins_encode %{
__ subl($dst$$Register, $src$$Address);
%}
ins_pipe(ialu_reg_mem);
%}
instruct subExactL_rReg(rax_RegL dst, rRegL src, rFlagsReg cr)
%{
match(SubExactL dst src);
effect(DEF cr);
format %{ "subq $dst, $src\t# subExact long" %}
ins_encode %{
__ subq($dst$$Register, $src$$Register);
%}
ins_pipe(ialu_reg_reg);
%}
instruct subExactL_rReg_imm(rax_RegL dst, immL32 src, rFlagsReg cr)
%{
match(SubExactL dst (LoadL src));
effect(DEF cr);
format %{ "subq $dst, $src\t# subExact long" %}
ins_encode %{
__ subq($dst$$Register, $src$$constant);
%}
ins_pipe(ialu_reg_reg);
%}
instruct subExactL_rReg_mem(rax_RegI dst, memory src, rFlagsReg cr)
%{
match(SubExactI dst src);
effect(DEF cr);
ins_cost(125);
format %{ "subq $dst, $src\t# subExact long" %}
ins_encode %{
__ subq($dst$$Register, $src$$Address);
%}
ins_pipe(ialu_reg_mem);
%}
instruct subL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
%{
match(Set dst (SubL dst src));
@ -7690,6 +7820,30 @@ instruct negL_mem(memory dst, immL0 zero, rFlagsReg cr)
ins_pipe(ialu_reg);
%}
instruct negExactI_rReg(rax_RegI dst, rFlagsReg cr)
%{
match(NegExactI dst);
effect(KILL cr);
format %{ "negl $dst\t# negExact int" %}
ins_encode %{
__ negl($dst$$Register);
%}
ins_pipe(ialu_reg);
%}
instruct negExactL_rReg(rax_RegL dst, rFlagsReg cr)
%{
match(NegExactL dst);
effect(KILL cr);
format %{ "negq $dst\t# negExact long" %}
ins_encode %{
__ negq($dst$$Register);
%}
ins_pipe(ialu_reg);
%}
//----------Multiplication/Division Instructions-------------------------------
// Integer Multiplication Instructions
@ -7807,6 +7961,86 @@ instruct mulHiL_rReg(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
ins_pipe(ialu_reg_reg_alu0);
%}
instruct mulExactI_rReg(rax_RegI dst, rRegI src, rFlagsReg cr)
%{
match(MulExactI dst src);
effect(DEF cr);
ins_cost(300);
format %{ "imull $dst, $src\t# mulExact int" %}
ins_encode %{
__ imull($dst$$Register, $src$$Register);
%}
ins_pipe(ialu_reg_reg_alu0);
%}
instruct mulExactI_rReg_imm(rax_RegI dst, rRegI src, immI imm, rFlagsReg cr)
%{
match(MulExactI src imm);
effect(DEF cr);
ins_cost(300);
format %{ "imull $dst, $src, $imm\t# mulExact int" %}
ins_encode %{
__ imull($dst$$Register, $src$$Register, $imm$$constant);
%}
ins_pipe(ialu_reg_reg_alu0);
%}
instruct mulExactI_rReg_mem(rax_RegI dst, memory src, rFlagsReg cr)
%{
match(MulExactI dst (LoadI src));
effect(DEF cr);
ins_cost(350);
format %{ "imull $dst, $src\t# mulExact int" %}
ins_encode %{
__ imull($dst$$Register, $src$$Address);
%}
ins_pipe(ialu_reg_mem_alu0);
%}
instruct mulExactL_rReg(rax_RegL dst, rRegL src, rFlagsReg cr)
%{
match(MulExactL dst src);
effect(DEF cr);
ins_cost(300);
format %{ "imulq $dst, $src\t# mulExact long" %}
ins_encode %{
__ imulq($dst$$Register, $src$$Register);
%}
ins_pipe(ialu_reg_reg_alu0);
%}
instruct mulExactL_rReg_imm(rax_RegL dst, rRegL src, immL32 imm, rFlagsReg cr)
%{
match(MulExactL src imm);
effect(DEF cr);
ins_cost(300);
format %{ "imulq $dst, $src, $imm\t# mulExact long" %}
ins_encode %{
__ imulq($dst$$Register, $src$$Register, $imm$$constant);
%}
ins_pipe(ialu_reg_reg_alu0);
%}
instruct mulExactL_rReg_mem(rax_RegL dst, memory src, rFlagsReg cr)
%{
match(MulExactL dst (LoadL src));
effect(DEF cr);
ins_cost(350);
format %{ "imulq $dst, $src\t# mulExact long" %}
ins_encode %{
__ imulq($dst$$Register, $src$$Address);
%}
ins_pipe(ialu_reg_mem_alu0);
%}
instruct divI_rReg(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div,
rFlagsReg cr)
%{

View file

@ -1193,6 +1193,13 @@ void ArchDesc::buildMustCloneMap(FILE *fp_hpp, FILE *fp_cpp) {
|| strcmp(idealName,"FastLock") == 0
|| strcmp(idealName,"FastUnlock") == 0
|| strcmp(idealName,"AddExactI") == 0
|| strcmp(idealName,"AddExactL") == 0
|| strcmp(idealName,"SubExactI") == 0
|| strcmp(idealName,"SubExactL") == 0
|| strcmp(idealName,"MulExactI") == 0
|| strcmp(idealName,"MulExactL") == 0
|| strcmp(idealName,"NegExactI") == 0
|| strcmp(idealName,"NegExactL") == 0
|| strcmp(idealName,"FlagsProj") == 0
|| strcmp(idealName,"Bool") == 0
|| strcmp(idealName,"Binary") == 0 ) {

View file

@ -624,6 +624,7 @@
do_class(java_lang_StrictMath, "java/lang/StrictMath") \
do_signature(double2_double_signature, "(DD)D") \
do_signature(int2_int_signature, "(II)I") \
do_signature(long2_long_signature, "(JJ)J") \
\
/* here are the math names, all together: */ \
do_name(abs_name,"abs") do_name(sin_name,"sin") do_name(cos_name,"cos") \
@ -632,8 +633,11 @@
do_name(exp_name,"exp") do_name(min_name,"min") do_name(max_name,"max") \
\
do_name(addExact_name,"addExact") \
do_name(subtractExact_name,"subtractExact") \
do_name(decrementExact_name,"decrementExact") \
do_name(incrementExact_name,"incrementExact") \
do_name(multiplyExact_name,"multiplyExact") \
do_name(negateExact_name,"negateExact") \
do_name(subtractExact_name,"subtractExact") \
\
do_intrinsic(_dabs, java_lang_Math, abs_name, double_double_signature, F_S) \
do_intrinsic(_dsin, java_lang_Math, sin_name, double_double_signature, F_S) \
@ -647,7 +651,18 @@
do_intrinsic(_dexp, java_lang_Math, exp_name, double_double_signature, F_S) \
do_intrinsic(_min, java_lang_Math, min_name, int2_int_signature, F_S) \
do_intrinsic(_max, java_lang_Math, max_name, int2_int_signature, F_S) \
do_intrinsic(_addExact, java_lang_Math, addExact_name, int2_int_signature, F_S) \
do_intrinsic(_addExactI, java_lang_Math, addExact_name, int2_int_signature, F_S) \
do_intrinsic(_addExactL, java_lang_Math, addExact_name, long2_long_signature, F_S) \
do_intrinsic(_decrementExactI, java_lang_Math, decrementExact_name, int_int_signature, F_S) \
do_intrinsic(_decrementExactL, java_lang_Math, decrementExact_name, long2_long_signature, F_S) \
do_intrinsic(_incrementExactI, java_lang_Math, incrementExact_name, int_int_signature, F_S) \
do_intrinsic(_incrementExactL, java_lang_Math, incrementExact_name, long2_long_signature, F_S) \
do_intrinsic(_multiplyExactI, java_lang_Math, multiplyExact_name, int2_int_signature, F_S) \
do_intrinsic(_multiplyExactL, java_lang_Math, multiplyExact_name, long2_long_signature, F_S) \
do_intrinsic(_negateExactI, java_lang_Math, negateExact_name, int_int_signature, F_S) \
do_intrinsic(_negateExactL, java_lang_Math, negateExact_name, long_long_signature, F_S) \
do_intrinsic(_subtractExactI, java_lang_Math, subtractExact_name, int2_int_signature, F_S) \
do_intrinsic(_subtractExactL, java_lang_Math, subtractExact_name, long2_long_signature, F_S) \
\
do_intrinsic(_floatToRawIntBits, java_lang_Float, floatToRawIntBits_name, float_int_signature, F_S) \
do_name( floatToRawIntBits_name, "floatToRawIntBits") \

View file

@ -30,6 +30,7 @@ macro(AbsF)
macro(AbsI)
macro(AddD)
macro(AddExactI)
macro(AddExactL)
macro(AddF)
macro(AddI)
macro(AddL)
@ -170,6 +171,8 @@ macro(LoopLimit)
macro(Mach)
macro(MachProj)
macro(MathExact)
macro(MathExactI)
macro(MathExactL)
macro(MaxI)
macro(MemBarAcquire)
macro(MemBarAcquireLock)
@ -189,12 +192,16 @@ macro(MoveF2I)
macro(MoveL2D)
macro(MoveD2L)
macro(MulD)
macro(MulExactI)
macro(MulExactL)
macro(MulF)
macro(MulHiL)
macro(MulI)
macro(MulL)
macro(Multi)
macro(NegD)
macro(NegExactI)
macro(NegExactL)
macro(NegF)
macro(NeverBranch)
macro(Opaque1)
@ -244,6 +251,8 @@ macro(StrComp)
macro(StrEquals)
macro(StrIndexOf)
macro(SubD)
macro(SubExactI)
macro(SubExactL)
macro(SubF)
macro(SubI)
macro(SubL)

View file

@ -203,8 +203,15 @@ class LibraryCallKit : public GraphKit {
bool inline_math_native(vmIntrinsics::ID id);
bool inline_trig(vmIntrinsics::ID id);
bool inline_math(vmIntrinsics::ID id);
bool inline_math_mathExact(Node* math);
bool inline_math_addExact();
void inline_math_mathExact(Node* math);
bool inline_math_addExactI(bool is_increment);
bool inline_math_addExactL(bool is_increment);
bool inline_math_multiplyExactI();
bool inline_math_multiplyExactL();
bool inline_math_negateExactI();
bool inline_math_negateExactL();
bool inline_math_subtractExactI(bool is_decrement);
bool inline_math_subtractExactL(bool is_decrement);
bool inline_exp();
bool inline_pow();
void finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName);
@ -507,13 +514,33 @@ CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
if (!UseCRC32Intrinsics) return NULL;
break;
case vmIntrinsics::_addExact:
if (!Matcher::match_rule_supported(Op_AddExactI)) {
return NULL;
}
if (!UseMathExactIntrinsics) {
return NULL;
}
case vmIntrinsics::_incrementExactI:
case vmIntrinsics::_addExactI:
if (!Matcher::match_rule_supported(Op_AddExactI) || !UseMathExactIntrinsics) return NULL;
break;
case vmIntrinsics::_incrementExactL:
case vmIntrinsics::_addExactL:
if (!Matcher::match_rule_supported(Op_AddExactL) || !UseMathExactIntrinsics) return NULL;
break;
case vmIntrinsics::_decrementExactI:
case vmIntrinsics::_subtractExactI:
if (!Matcher::match_rule_supported(Op_SubExactI) || !UseMathExactIntrinsics) return NULL;
break;
case vmIntrinsics::_decrementExactL:
case vmIntrinsics::_subtractExactL:
if (!Matcher::match_rule_supported(Op_SubExactL) || !UseMathExactIntrinsics) return NULL;
break;
case vmIntrinsics::_negateExactI:
if (!Matcher::match_rule_supported(Op_NegExactI) || !UseMathExactIntrinsics) return NULL;
break;
case vmIntrinsics::_negateExactL:
if (!Matcher::match_rule_supported(Op_NegExactL) || !UseMathExactIntrinsics) return NULL;
break;
case vmIntrinsics::_multiplyExactI:
if (!Matcher::match_rule_supported(Op_MulExactI) || !UseMathExactIntrinsics) return NULL;
break;
case vmIntrinsics::_multiplyExactL:
if (!Matcher::match_rule_supported(Op_MulExactL) || !UseMathExactIntrinsics) return NULL;
break;
default:
@ -686,7 +713,18 @@ bool LibraryCallKit::try_to_inline() {
case vmIntrinsics::_min:
case vmIntrinsics::_max: return inline_min_max(intrinsic_id());
case vmIntrinsics::_addExact: return inline_math_addExact();
case vmIntrinsics::_addExactI: return inline_math_addExactI(false /* add */);
case vmIntrinsics::_addExactL: return inline_math_addExactL(false /* add */);
case vmIntrinsics::_decrementExactI: return inline_math_subtractExactI(true /* decrement */);
case vmIntrinsics::_decrementExactL: return inline_math_subtractExactL(true /* decrement */);
case vmIntrinsics::_incrementExactI: return inline_math_addExactI(true /* increment */);
case vmIntrinsics::_incrementExactL: return inline_math_addExactL(true /* increment */);
case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI();
case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL();
case vmIntrinsics::_negateExactI: return inline_math_negateExactI();
case vmIntrinsics::_negateExactL: return inline_math_negateExactL();
case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */);
case vmIntrinsics::_subtractExactL: return inline_math_subtractExactL(false /* subtract */);
case vmIntrinsics::_arraycopy: return inline_arraycopy();
@ -1931,7 +1969,14 @@ bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) {
return true;
}
bool LibraryCallKit::inline_math_mathExact(Node* math) {
void LibraryCallKit::inline_math_mathExact(Node* math) {
// If we didn't get the expected opcode it means we have optimized
// the node to something else and don't need the exception edge.
if (!math->is_MathExact()) {
set_result(math);
return;
}
Node* result = _gvn.transform( new(C) ProjNode(math, MathExactNode::result_proj_node));
Node* flags = _gvn.transform( new(C) FlagsProjNode(math, MathExactNode::flags_proj_node));
@ -1954,19 +1999,106 @@ bool LibraryCallKit::inline_math_mathExact(Node* math) {
set_control(fast_path);
set_result(result);
}
bool LibraryCallKit::inline_math_addExactI(bool is_increment) {
Node* arg1 = argument(0);
Node* arg2 = NULL;
if (is_increment) {
arg2 = intcon(1);
} else {
arg2 = argument(1);
}
Node* add = _gvn.transform( new(C) AddExactINode(NULL, arg1, arg2) );
inline_math_mathExact(add);
return true;
}
bool LibraryCallKit::inline_math_addExact() {
bool LibraryCallKit::inline_math_addExactL(bool is_increment) {
Node* arg1 = argument(0); // type long
// argument(1) == TOP
Node* arg2 = NULL;
if (is_increment) {
arg2 = longcon(1);
} else {
arg2 = argument(2); // type long
// argument(3) == TOP
}
Node* add = _gvn.transform(new(C) AddExactLNode(NULL, arg1, arg2));
inline_math_mathExact(add);
return true;
}
bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) {
Node* arg1 = argument(0);
Node* arg2 = NULL;
if (is_decrement) {
arg2 = intcon(1);
} else {
arg2 = argument(1);
}
Node* sub = _gvn.transform(new(C) SubExactINode(NULL, arg1, arg2));
inline_math_mathExact(sub);
return true;
}
bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) {
Node* arg1 = argument(0); // type long
// argument(1) == TOP
Node* arg2 = NULL;
if (is_decrement) {
arg2 = longcon(1);
} else {
Node* arg2 = argument(2); // type long
// argument(3) == TOP
}
Node* sub = _gvn.transform(new(C) SubExactLNode(NULL, arg1, arg2));
inline_math_mathExact(sub);
return true;
}
bool LibraryCallKit::inline_math_negateExactI() {
Node* arg1 = argument(0);
Node* neg = _gvn.transform(new(C) NegExactINode(NULL, arg1));
inline_math_mathExact(neg);
return true;
}
bool LibraryCallKit::inline_math_negateExactL() {
Node* arg1 = argument(0);
// argument(1) == TOP
Node* neg = _gvn.transform(new(C) NegExactLNode(NULL, arg1));
inline_math_mathExact(neg);
return true;
}
bool LibraryCallKit::inline_math_multiplyExactI() {
Node* arg1 = argument(0);
Node* arg2 = argument(1);
Node* add = _gvn.transform( new(C) AddExactINode(NULL, arg1, arg2) );
if (add->Opcode() == Op_AddExactI) {
return inline_math_mathExact(add);
} else {
set_result(add);
}
Node* mul = _gvn.transform(new(C) MulExactINode(NULL, arg1, arg2));
inline_math_mathExact(mul);
return true;
}
bool LibraryCallKit::inline_math_multiplyExactL() {
Node* arg1 = argument(0);
// argument(1) == TOP
Node* arg2 = argument(2);
// argument(3) == TOP
Node* mul = _gvn.transform(new(C) MulExactLNode(NULL, arg1, arg2));
inline_math_mathExact(mul);
return true;
}

View file

@ -338,6 +338,7 @@ public:
static RegMask modL_proj_mask();
static const RegMask mathExactI_result_proj_mask();
static const RegMask mathExactL_result_proj_mask();
static const RegMask mathExactI_flags_proj_mask();
// Use hardware DIV instruction when it is faster than

View file

@ -31,10 +31,17 @@
#include "opto/mathexactnode.hpp"
#include "opto/subnode.hpp"
MathExactNode::MathExactNode(Node* ctrl, Node* n1, Node* n2) : MultiNode(3) {
MathExactNode::MathExactNode(Node* ctrl, Node* in1) : MultiNode(2) {
init_class_id(Class_MathExact);
init_req(0, ctrl);
init_req(1, n1);
init_req(2, n2);
init_req(1, in1);
}
MathExactNode::MathExactNode(Node* ctrl, Node* in1, Node* in2) : MultiNode(3) {
init_class_id(Class_MathExact);
init_req(0, ctrl);
init_req(1, in1);
init_req(2, in2);
}
BoolNode* MathExactNode::bool_node() const {
@ -64,23 +71,10 @@ Node* MathExactNode::non_throwing_branch() const {
return ifnode->proj_out(1);
}
Node* AddExactINode::match(const ProjNode* proj, const Matcher* m) {
uint ideal_reg = proj->ideal_reg();
RegMask rm;
if (proj->_con == result_proj_node) {
rm = m->mathExactI_result_proj_mask();
} else {
assert(proj->_con == flags_proj_node, "must be result or flags");
assert(ideal_reg == Op_RegFlags, "sanity");
rm = m->mathExactI_flags_proj_mask();
}
return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg);
}
// If the MathExactNode won't overflow we have to replace the
// FlagsProjNode and ProjNode that is generated by the MathExactNode
Node* MathExactNode::no_overflow(PhaseGVN *phase, Node* new_result) {
PhaseIterGVN *igvn = phase->is_IterGVN();
Node* MathExactNode::no_overflow(PhaseGVN* phase, Node* new_result) {
PhaseIterGVN* igvn = phase->is_IterGVN();
if (igvn) {
ProjNode* result = result_node();
ProjNode* flags = flags_node();
@ -110,9 +104,35 @@ Node* MathExactNode::no_overflow(PhaseGVN *phase, Node* new_result) {
return new_result;
}
Node *AddExactINode::Ideal(PhaseGVN *phase, bool can_reshape) {
Node *arg1 = in(1);
Node *arg2 = in(2);
Node* MathExactINode::match(const ProjNode* proj, const Matcher* m) {
uint ideal_reg = proj->ideal_reg();
RegMask rm;
if (proj->_con == result_proj_node) {
rm = m->mathExactI_result_proj_mask();
} else {
assert(proj->_con == flags_proj_node, "must be result or flags");
assert(ideal_reg == Op_RegFlags, "sanity");
rm = m->mathExactI_flags_proj_mask();
}
return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg);
}
Node* MathExactLNode::match(const ProjNode* proj, const Matcher* m) {
uint ideal_reg = proj->ideal_reg();
RegMask rm;
if (proj->_con == result_proj_node) {
rm = m->mathExactL_result_proj_mask();
} else {
assert(proj->_con == flags_proj_node, "must be result or flags");
assert(ideal_reg == Op_RegFlags, "sanity");
rm = m->mathExactI_flags_proj_mask();
}
return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg);
}
Node* AddExactINode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* arg1 = in(1);
Node* arg2 = in(2);
const Type* type1 = phase->type(arg1);
const Type* type2 = phase->type(arg2);
@ -130,12 +150,7 @@ Node *AddExactINode::Ideal(PhaseGVN *phase, bool can_reshape) {
return NULL;
}
if (type1 == TypeInt::ZERO) { // (Add 0 x) == x
Node* add_result = new (phase->C) AddINode(arg1, arg2);
return no_overflow(phase, add_result);
}
if (type2 == TypeInt::ZERO) { // (Add x 0) == x
if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) { // (Add 0 x) == x
Node* add_result = new (phase->C) AddINode(arg1, arg2);
return no_overflow(phase, add_result);
}
@ -169,3 +184,247 @@ Node *AddExactINode::Ideal(PhaseGVN *phase, bool can_reshape) {
return NULL;
}
Node* AddExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* arg1 = in(1);
Node* arg2 = in(2);
const Type* type1 = phase->type(arg1);
const Type* type2 = phase->type(arg2);
if (type1 != Type::TOP && type1->singleton() &&
type2 != Type::TOP && type2->singleton()) {
jlong val1 = arg1->get_long();
jlong val2 = arg2->get_long();
jlong result = val1 + val2;
// Hacker's Delight 2-12 Overflow if both arguments have the opposite sign of the result
if ( (((val1 ^ result) & (val2 ^ result)) >= 0)) {
Node* con_result = ConLNode::make(phase->C, result);
return no_overflow(phase, con_result);
}
return NULL;
}
if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) { // (Add 0 x) == x
Node* add_result = new (phase->C) AddLNode(arg1, arg2);
return no_overflow(phase, add_result);
}
if (type2->singleton()) {
return NULL; // no change - keep constant on the right
}
if (type1->singleton()) {
// Make it x + Constant - move constant to the right
swap_edges(1, 2);
return this;
}
if (arg2->is_Load()) {
return NULL; // no change - keep load on the right
}
if (arg1->is_Load()) {
// Make it x + Load - move load to the right
swap_edges(1, 2);
return this;
}
if (arg1->_idx > arg2->_idx) {
// Sort the edges
swap_edges(1, 2);
return this;
}
return NULL;
}
Node* SubExactINode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* arg1 = in(1);
Node* arg2 = in(2);
const Type* type1 = phase->type(arg1);
const Type* type2 = phase->type(arg2);
if (type1 != Type::TOP && type1->singleton() &&
type2 != Type::TOP && type2->singleton()) {
jint val1 = arg1->get_int();
jint val2 = arg2->get_int();
jint result = val1 - val2;
// Hacker's Delight 2-12 Overflow iff the arguments have different signs and
// the sign of the result is different than the sign of arg1
if (((val1 ^ val2) & (val1 ^ result)) >= 0) {
Node* con_result = ConINode::make(phase->C, result);
return no_overflow(phase, con_result);
}
return NULL;
}
if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) {
// Sub with zero is the same as add with zero
Node* add_result = new (phase->C) AddINode(arg1, arg2);
return no_overflow(phase, add_result);
}
return NULL;
}
Node* SubExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* arg1 = in(1);
Node* arg2 = in(2);
const Type* type1 = phase->type(arg1);
const Type* type2 = phase->type(arg2);
if (type1 != Type::TOP && type1->singleton() &&
type2 != Type::TOP && type2->singleton()) {
jlong val1 = arg1->get_long();
jlong val2 = arg2->get_long();
jlong result = val1 - val2;
// Hacker's Delight 2-12 Overflow iff the arguments have different signs and
// the sign of the result is different than the sign of arg1
if (((val1 ^ val2) & (val1 ^ result)) >= 0) {
Node* con_result = ConLNode::make(phase->C, result);
return no_overflow(phase, con_result);
}
return NULL;
}
if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) {
// Sub with zero is the same as add with zero
Node* add_result = new (phase->C) AddLNode(arg1, arg2);
return no_overflow(phase, add_result);
}
return NULL;
}
Node* NegExactINode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node *arg = in(1);
const Type* type = phase->type(arg);
if (type != Type::TOP && type->singleton()) {
jint value = arg->get_int();
if (value != min_jint) {
Node* neg_result = ConINode::make(phase->C, -value);
return no_overflow(phase, neg_result);
}
}
return NULL;
}
Node* NegExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node *arg = in(1);
const Type* type = phase->type(arg);
if (type != Type::TOP && type->singleton()) {
jlong value = arg->get_long();
if (value != min_jlong) {
Node* neg_result = ConLNode::make(phase->C, -value);
return no_overflow(phase, neg_result);
}
}
return NULL;
}
Node* MulExactINode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* arg1 = in(1);
Node* arg2 = in(2);
const Type* type1 = phase->type(arg1);
const Type* type2 = phase->type(arg2);
if (type1 != Type::TOP && type1->singleton() &&
type2 != Type::TOP && type2->singleton()) {
jint val1 = arg1->get_int();
jint val2 = arg2->get_int();
jlong result = (jlong) val1 * (jlong) val2;
if ((jint) result == result) {
// no overflow
Node* mul_result = ConINode::make(phase->C, result);
return no_overflow(phase, mul_result);
}
}
if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) {
return no_overflow(phase, ConINode::make(phase->C, 0));
}
if (type1 == TypeInt::ONE) {
Node* mul_result = new (phase->C) AddINode(arg2, phase->intcon(0));
return no_overflow(phase, mul_result);
}
if (type2 == TypeInt::ONE) {
Node* mul_result = new (phase->C) AddINode(arg1, phase->intcon(0));
return no_overflow(phase, mul_result);
}
if (type1 == TypeInt::MINUS_1) {
return new (phase->C) NegExactINode(NULL, arg2);
}
if (type2 == TypeInt::MINUS_1) {
return new (phase->C) NegExactINode(NULL, arg1);
}
return NULL;
}
Node* MulExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) {
Node* arg1 = in(1);
Node* arg2 = in(2);
const Type* type1 = phase->type(arg1);
const Type* type2 = phase->type(arg2);
if (type1 != Type::TOP && type1->singleton() &&
type2 != Type::TOP && type2->singleton()) {
jlong val1 = arg1->get_long();
jlong val2 = arg2->get_long();
jlong result = val1 * val2;
jlong ax = (val1 < 0 ? -val1 : val1);
jlong ay = (val2 < 0 ? -val2 : val2);
bool overflow = false;
if ((ax | ay) & CONST64(0xFFFFFFFF00000000)) {
// potential overflow if any bit in upper 32 bits are set
if ((val1 == min_jlong && val2 == -1) || (val2 == min_jlong && val1 == -1)) {
// -1 * Long.MIN_VALUE will overflow
overflow = true;
} else if (val2 != 0 && (result / val2 != val1)) {
overflow = true;
}
}
if (!overflow) {
Node* mul_result = ConLNode::make(phase->C, result);
return no_overflow(phase, mul_result);
}
}
if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) {
return no_overflow(phase, ConLNode::make(phase->C, 0));
}
if (type1 == TypeLong::ONE) {
Node* mul_result = new (phase->C) AddLNode(arg2, phase->longcon(0));
return no_overflow(phase, mul_result);
}
if (type2 == TypeLong::ONE) {
Node* mul_result = new (phase->C) AddLNode(arg1, phase->longcon(0));
return no_overflow(phase, mul_result);
}
if (type1 == TypeLong::MINUS_1) {
return new (phase->C) NegExactLNode(NULL, arg2);
}
if (type2 == TypeLong::MINUS_1) {
return new (phase->C) NegExactLNode(NULL, arg1);
}
return NULL;
}

View file

@ -39,6 +39,7 @@ class PhaseTransform;
class MathExactNode : public MultiNode {
public:
MathExactNode(Node* ctrl, Node* in1);
MathExactNode(Node* ctrl, Node* in1, Node* in2);
enum {
result_proj_node = 0,
@ -62,15 +63,80 @@ protected:
Node* no_overflow(PhaseGVN *phase, Node* new_result);
};
class AddExactINode : public MathExactNode {
public:
AddExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {}
class MathExactINode : public MathExactNode {
public:
MathExactINode(Node* ctrl, Node* in1) : MathExactNode(ctrl, in1) {}
MathExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {}
virtual int Opcode() const;
virtual const Type* bottom_type() const { return TypeTuple::INT_CC_PAIR; }
virtual Node* match(const ProjNode* proj, const Matcher* m);
virtual const Type* bottom_type() const { return TypeTuple::INT_CC_PAIR; }
};
class MathExactLNode : public MathExactNode {
public:
MathExactLNode(Node* ctrl, Node* in1) : MathExactNode(ctrl, in1) {}
MathExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {}
virtual int Opcode() const;
virtual Node* match(const ProjNode* proj, const Matcher* m);
virtual const Type* bottom_type() const { return TypeTuple::LONG_CC_PAIR; }
};
class AddExactINode : public MathExactINode {
public:
AddExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {}
virtual int Opcode() const;
virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
};
class AddExactLNode : public MathExactLNode {
public:
AddExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {}
virtual int Opcode() const;
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
};
class SubExactINode : public MathExactINode {
public:
SubExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {}
virtual int Opcode() const;
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
};
class SubExactLNode : public MathExactLNode {
public:
SubExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {}
virtual int Opcode() const;
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
};
class NegExactINode : public MathExactINode {
public:
NegExactINode(Node* ctrl, Node* in1) : MathExactINode(ctrl, in1) {}
virtual int Opcode() const;
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
};
class NegExactLNode : public MathExactLNode {
public:
NegExactLNode(Node* ctrl, Node* in1) : MathExactLNode(ctrl, in1) {}
virtual int Opcode() const;
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
};
class MulExactINode : public MathExactINode {
public:
MulExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {}
virtual int Opcode() const;
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
};
class MulExactLNode : public MathExactLNode {
public:
MulExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {}
virtual int Opcode() const;
virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
};
class FlagsProjNode : public ProjNode {
public:
FlagsProjNode(Node* src, uint con) : ProjNode(src, con) {

View file

@ -100,6 +100,7 @@ class MachSafePointNode;
class MachSpillCopyNode;
class MachTempNode;
class Matcher;
class MathExactNode;
class MemBarNode;
class MemBarStoreStoreNode;
class MemNode;
@ -568,6 +569,7 @@ public:
DEFINE_CLASS_ID(MemBar, Multi, 3)
DEFINE_CLASS_ID(Initialize, MemBar, 0)
DEFINE_CLASS_ID(MemBarStoreStore, MemBar, 1)
DEFINE_CLASS_ID(MathExact, Multi, 4)
DEFINE_CLASS_ID(Mach, Node, 1)
DEFINE_CLASS_ID(MachReturn, Mach, 0)
@ -757,6 +759,7 @@ public:
DEFINE_CLASS_QUERY(MachSafePoint)
DEFINE_CLASS_QUERY(MachSpillCopy)
DEFINE_CLASS_QUERY(MachTemp)
DEFINE_CLASS_QUERY(MathExact)
DEFINE_CLASS_QUERY(Mem)
DEFINE_CLASS_QUERY(MemBar)
DEFINE_CLASS_QUERY(MemBarStoreStore)

View file

@ -435,6 +435,11 @@ void Type::Initialize_shared(Compile* current) {
intccpair[1] = TypeInt::CC;
TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
const Type **longccpair = TypeTuple::fields(2);
longccpair[0] = TypeLong::LONG;
longccpair[1] = TypeInt::CC;
TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
_const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
_const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
_const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
@ -1675,6 +1680,7 @@ const TypeTuple *TypeTuple::START_I2C;
const TypeTuple *TypeTuple::INT_PAIR;
const TypeTuple *TypeTuple::LONG_PAIR;
const TypeTuple *TypeTuple::INT_CC_PAIR;
const TypeTuple *TypeTuple::LONG_CC_PAIR;
//------------------------------make-------------------------------------------

View file

@ -593,6 +593,7 @@ public:
static const TypeTuple *INT_PAIR;
static const TypeTuple *LONG_PAIR;
static const TypeTuple *INT_CC_PAIR;
static const TypeTuple *LONG_CC_PAIR;
#ifndef PRODUCT
virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
#endif

View file

@ -1938,7 +1938,13 @@ typedef BinaryTreeDictionary<Metablock, FreeList> MetablockTreeDictionary;
declare_c2_type(CmpDNode, CmpNode) \
declare_c2_type(CmpD3Node, CmpDNode) \
declare_c2_type(MathExactNode, MultiNode) \
declare_c2_type(AddExactINode, MathExactNode) \
declare_c2_type(MathExactINode, MathExactNode) \
declare_c2_type(AddExactINode, MathExactINode) \
declare_c2_type(AddExactLNode, MathExactLNode) \
declare_c2_type(SubExactINode, MathExactINode) \
declare_c2_type(SubExactLNode, MathExactLNode) \
declare_c2_type(NegExactINode, MathExactINode) \
declare_c2_type(MulExactINode, MathExactINode) \
declare_c2_type(FlagsProjNode, ProjNode) \
declare_c2_type(BoolNode, Node) \
declare_c2_type(AbsNode, Node) \