Skip to content

Commit

Permalink
8315554: C1: Replace "cmp reg, 0" with "test reg, reg" on x86
Browse files Browse the repository at this point in the history
Reviewed-by: iveresov, chagedorn, thartmann
  • Loading branch information
shipilev committed Sep 6, 2023
1 parent 25e85db commit bd47781
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success, L

assert_different_registers(obj, k_RInfo, klass_RInfo);

__ cmpptr(obj, NULL_WORD);
__ testptr(obj, obj);
if (op->should_profile()) {
Label not_null;
__ jccb(Assembler::notEqual, not_null);
Expand Down Expand Up @@ -1792,7 +1792,7 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success, L
__ pop(klass_RInfo);
__ pop(klass_RInfo);
// result is a boolean
__ cmpl(klass_RInfo, 0);
__ testl(klass_RInfo, klass_RInfo);
__ jcc(Assembler::equal, *failure_target);
// successful cast, fall through to profile or jump
}
Expand All @@ -1806,7 +1806,7 @@ void LIR_Assembler::emit_typecheck_helper(LIR_OpTypeCheck *op, Label* success, L
__ pop(klass_RInfo);
__ pop(k_RInfo);
// result is a boolean
__ cmpl(k_RInfo, 0);
__ testl(k_RInfo, k_RInfo);
__ jcc(Assembler::equal, *failure_target);
// successful cast, fall through to profile or jump
}
Expand Down Expand Up @@ -1859,7 +1859,7 @@ void LIR_Assembler::emit_opTypeCheck(LIR_OpTypeCheck* op) {
Label *success_target = op->should_profile() ? &profile_cast_success : &done;
Label *failure_target = op->should_profile() ? &profile_cast_failure : stub->entry();

__ cmpptr(value, NULL_WORD);
__ testptr(value, value);
if (op->should_profile()) {
Label not_null;
__ jccb(Assembler::notEqual, not_null);
Expand Down Expand Up @@ -1890,7 +1890,7 @@ void LIR_Assembler::emit_opTypeCheck(LIR_OpTypeCheck* op) {
__ pop(klass_RInfo);
__ pop(k_RInfo);
// result is a boolean
__ cmpl(k_RInfo, 0);
__ testl(k_RInfo, k_RInfo);
__ jcc(Assembler::equal, *failure_target);
// fall through to the success case

Expand Down Expand Up @@ -2664,21 +2664,26 @@ void LIR_Assembler::comp_op(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2,
// cpu register - constant
LIR_Const* c = opr2->as_constant_ptr();
if (c->type() == T_INT) {
__ cmpl(reg1, c->as_jint());
jint i = c->as_jint();
if (i == 0) {
__ testl(reg1, reg1);
} else {
__ cmpl(reg1, i);
}
} else if (c->type() == T_METADATA) {
// All we need for now is a comparison with null for equality.
assert(condition == lir_cond_equal || condition == lir_cond_notEqual, "oops");
Metadata* m = c->as_metadata();
if (m == nullptr) {
__ cmpptr(reg1, NULL_WORD);
__ testptr(reg1, reg1);
} else {
ShouldNotReachHere();
}
} else if (is_reference_type(c->type())) {
// In 64bit oops are single register
jobject o = c->as_jobject();
if (o == nullptr) {
__ cmpptr(reg1, NULL_WORD);
__ testptr(reg1, reg1);
} else {
__ cmpoop(reg1, o, rscratch1);
}
Expand Down Expand Up @@ -3146,7 +3151,7 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {

#endif // _LP64

__ cmpl(rax, 0);
__ testl(rax, rax);
__ jcc(Assembler::equal, *stub->continuation());

__ mov(tmp, rax);
Expand Down Expand Up @@ -3288,7 +3293,7 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {
__ pop(dst);
__ pop(src);

__ cmpl(src, 0);
__ testl(src, src);
__ jcc(Assembler::notEqual, cont);

__ bind(slow);
Expand Down

1 comment on commit bd47781

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.