Skip to content

JIT: Avoid IS_UNDEF check for ZEND_FETCH_DIM/OBJ_IS with a result type guard #14298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -7744,8 +7744,13 @@ static zend_jit_addr zend_jit_guard_fetch_result_type(zend_jit_ctx *jit,
SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_UNKNOWN, 1);

if (deref) {
ir_ref if_type = jit_if_Z_TYPE(jit, val_addr, type);
ir_ref if_type;

if (type == IS_NULL && (opline->opcode == ZEND_FETCH_DIM_IS || opline->opcode == ZEND_FETCH_OBJ_IS)) {
if_type = ir_IF(ir_ULE(jit_Z_TYPE(jit, val_addr), ir_CONST_U8(type)));
} else {
if_type = jit_if_Z_TYPE(jit, val_addr, type);
}
ir_IF_TRUE(if_type);
end1 = ir_END();
ref1 = ref;
Expand All @@ -7770,7 +7775,11 @@ static zend_jit_addr zend_jit_guard_fetch_result_type(zend_jit_ctx *jit,
return 0;
}

jit_guard_Z_TYPE(jit, val_addr, type, res_exit_addr);
if (!deref && type == IS_NULL && (opline->opcode == ZEND_FETCH_DIM_IS || opline->opcode == ZEND_FETCH_OBJ_IS)) {
ir_GUARD(ir_ULE(jit_Z_TYPE(jit, val_addr), ir_CONST_U8(type)), ir_CONST_ADDR(res_exit_addr));
} else {
jit_guard_Z_TYPE(jit, val_addr, type, res_exit_addr);
}

if (deref) {
ir_MERGE_WITH(end1);
Expand Down Expand Up @@ -11576,39 +11585,20 @@ static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit,
if (packed_loaded) {
ir_ref type_ref = jit_Z_TYPE_ref(jit, ref);

if (op1_info & MAY_BE_ARRAY_NUMERIC_HASH) {
ir_ref if_def = ir_IF(type_ref);
ir_IF_TRUE(if_def);
ir_refs_add(found_inputs, ir_END());
ir_refs_add(found_vals, ref);
ir_IF_FALSE(if_def);
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr));
} else if (type == BP_VAR_IS && not_found_exit_addr) {
jit_SIDE_EXIT(jit, ir_CONST_ADDR(not_found_exit_addr));
} else if (type == BP_VAR_IS && result_type_guard) {
ir_END_list(*not_found_inputs);
} else {
ir_END_list(idx_not_found_inputs);
}
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
if (result_type_guard) {
/* perform IS_UNDEF check only after result type guard (during deoptimization) */
if (!result_type_guard) {
ir_GUARD(type_ref, ir_CONST_ADDR(exit_addr));
}
} else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
ir_GUARD(type_ref, ir_CONST_ADDR(exit_addr));
} else if (type == BP_VAR_IS && not_found_exit_addr) {
ir_GUARD(type_ref, ir_CONST_ADDR(not_found_exit_addr));
} else if (type == BP_VAR_IS && result_type_guard) {
ir_ref if_def = ir_IF(type_ref);
ir_IF_FALSE(if_def);
ir_END_list(*not_found_inputs);
ir_IF_TRUE(if_def);
} else {
ir_ref if_def = ir_IF(type_ref);
ir_IF_FALSE(if_def);
ir_END_list(idx_not_found_inputs);
ir_IF_TRUE(if_def);
}
ir_refs_add(found_inputs, ir_END());
ir_refs_add(found_vals, ref);
}
if (op1_info & MAY_BE_ARRAY_NUMERIC_HASH) {
if (if_packed) {
Expand Down Expand Up @@ -11641,10 +11631,7 @@ static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit,
}
ir_refs_add(found_inputs, ir_END());
ir_refs_add(found_vals, ref);
} else if (packed_loaded) {
ir_refs_add(found_inputs, ir_END());
ir_refs_add(found_vals, ref);
} else {
} else if (!packed_loaded) {
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) {
jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr));
} else if (type == BP_VAR_IS && not_found_exit_addr) {
Expand Down
10 changes: 9 additions & 1 deletion ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -8497,7 +8497,15 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf

if (UNEXPECTED(Z_TYPE_P(val) == IS_UNDEF)) {
/* Undefined array index or property */
repeat_last_opline = 1;
const zend_op *op = t->exit_info[exit_num].opline;
ZEND_ASSERT(op);
op--;
if (op->opcode == ZEND_FETCH_DIM_IS || op->opcode == ZEND_FETCH_OBJ_IS) {
ZVAL_NULL(EX_VAR_NUM(i));
} else {
assert(op->opcode == ZEND_FETCH_DIM_R || op->opcode == ZEND_FETCH_LIST_R || op->opcode == ZEND_FETCH_OBJ_R);
repeat_last_opline = 1;
}
} else {
ZVAL_COPY(EX_VAR_NUM(i), val);
}
Expand Down
Loading