Skip to content

Commit 84e0ea6

Browse files
committed
Optimize out double memory load
1 parent 79484b4 commit 84e0ea6

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
28922892
}
28932893
} else {
28942894
int j;
2895+
zend_bool left_frame = 0;
28952896

28962897
if (!zend_jit_return(&dasm_state, opline, op_array,
28972898
op1_info, OP1_REG_ADDR())) {
@@ -2907,20 +2908,23 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
29072908
if (!zend_jit_label(&dasm_state, jit_return_label)) {
29082909
goto jit_failure;
29092910
}
2910-
if (!zend_jit_leave_frame(&dasm_state)) {
2911-
goto jit_failure;
2912-
}
29132911
for (j = 0 ; j < op_array->last_var; j++) {
29142912
uint32_t info = zend_ssa_cv_info(op_array, ssa, j);
29152913

29162914
if (info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) {
2915+
if (!left_frame) {
2916+
left_frame = 1;
2917+
if (!zend_jit_leave_frame(&dasm_state)) {
2918+
goto jit_failure;
2919+
}
2920+
}
29172921
if (!zend_jit_free_cv(&dasm_state, info, j)) {
29182922
goto jit_failure;
29192923
}
29202924
}
29212925
}
2922-
if (!zend_jit_leave_func(&dasm_state, op_array, opline, op1_info, NULL, NULL,
2923-
(ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS) != 0, 1)) {
2926+
if (!zend_jit_leave_func(&dasm_state, op_array, opline, op1_info, left_frame,
2927+
NULL, NULL, (ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS) != 0, 1)) {
29242928
goto jit_failure;
29252929
}
29262930
}

ext/opcache/jit/zend_jit_trace.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4433,14 +4433,12 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
44334433
} else {
44344434
int j;
44354435
int may_throw = 0;
4436+
zend_bool left_frame = 0;
44364437

44374438
if (!zend_jit_return(&dasm_state, opline, op_array,
44384439
op1_info, OP1_REG_ADDR())) {
44394440
goto jit_failure;
44404441
}
4441-
if (!zend_jit_leave_frame(&dasm_state)) {
4442-
goto jit_failure;
4443-
}
44444442
for (j = 0 ; j < op_array->last_var; j++) {
44454443
uint32_t info;
44464444
zend_uchar type;
@@ -4456,6 +4454,12 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
44564454
type = STACK_TYPE(stack, j);
44574455
info = zend_jit_trace_type_to_info_ex(type, info);
44584456
if (info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) {
4457+
if (!left_frame) {
4458+
left_frame = 1;
4459+
if (!zend_jit_leave_frame(&dasm_state)) {
4460+
goto jit_failure;
4461+
}
4462+
}
44594463
if (!zend_jit_free_cv(&dasm_state, info, j)) {
44604464
goto jit_failure;
44614465
}
@@ -4466,7 +4470,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
44664470
}
44674471
}
44684472
}
4469-
if (!zend_jit_leave_func(&dasm_state, op_array, opline, op1_info,
4473+
if (!zend_jit_leave_func(&dasm_state, op_array, opline, op1_info, left_frame,
44704474
p + 1, &zend_jit_traces[ZEND_JIT_TRACE_NUM],
44714475
(op_array_ssa->cfg.flags & ZEND_FUNC_INDIRECT_VAR_ACCESS) != 0, may_throw)) {
44724476
goto jit_failure;

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11044,7 +11044,15 @@ static int zend_jit_free_op(dasm_State **Dst, const zend_op *opline, uint32_t in
1104411044
return 1;
1104511045
}
1104611046

11047-
static int zend_jit_leave_func(dasm_State **Dst, const zend_op_array *op_array, const zend_op *opline, uint32_t op1_info, zend_jit_trace_rec *trace, zend_jit_trace_info *trace_info, int indirect_var_access, int may_throw)
11047+
static int zend_jit_leave_func(dasm_State **Dst,
11048+
const zend_op_array *op_array,
11049+
const zend_op *opline,
11050+
uint32_t op1_info,
11051+
zend_bool left_frame,
11052+
zend_jit_trace_rec *trace,
11053+
zend_jit_trace_info *trace_info,
11054+
int indirect_var_access,
11055+
int may_throw)
1104811056
{
1104911057
zend_bool may_be_top_frame =
1105011058
JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE ||
@@ -11071,6 +11079,12 @@ static int zend_jit_leave_func(dasm_State **Dst, const zend_op_array *op_array,
1107111079
| mov FCARG1d, dword [FP + offsetof(zend_execute_data, This.u1.type_info)]
1107211080
}
1107311081
if (may_need_call_helper) {
11082+
if (!left_frame) {
11083+
left_frame = 1;
11084+
if (!zend_jit_leave_frame(Dst)) {
11085+
return 0;
11086+
}
11087+
}
1107411088
/* ZEND_CALL_FAKE_CLOSURE handled on slow path to eliminate check for ZEND_CALL_CLOSURE on fast path */
1107511089
| test FCARG1d, (ZEND_CALL_TOP|ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_ALLOCATED|ZEND_CALL_HAS_EXTRA_NAMED_PARAMS|ZEND_CALL_FAKE_CLOSURE)
1107611090
if (trace && trace->op != ZEND_JIT_TRACE_END) {
@@ -11108,12 +11122,24 @@ static int zend_jit_leave_func(dasm_State **Dst, const zend_op_array *op_array,
1110811122
}
1110911123

1111011124
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
11125+
if (!left_frame) {
11126+
left_frame = 1;
11127+
if (!zend_jit_leave_frame(Dst)) {
11128+
return 0;
11129+
}
11130+
}
1111111131
| // OBJ_RELEASE(ZEND_CLOSURE_OBJECT(EX(func)));
1111211132
| mov FCARG1a, EX->func
1111311133
| sub FCARG1a, sizeof(zend_object)
1111411134
| OBJ_RELEASE ZREG_FCARG1a, >4
1111511135
|4:
1111611136
} else if (may_need_release_this) {
11137+
if (!left_frame) {
11138+
left_frame = 1;
11139+
if (!zend_jit_leave_frame(Dst)) {
11140+
return 0;
11141+
}
11142+
}
1111711143
| // if (call_info & ZEND_CALL_RELEASE_THIS)
1111811144
| test FCARG1d, ZEND_CALL_RELEASE_THIS
1111911145
| je >4
@@ -11131,6 +11157,11 @@ static int zend_jit_leave_func(dasm_State **Dst, const zend_op_array *op_array,
1113111157
| // execute_data = EX(prev_execute_data);
1113211158
| mov FP, EX->prev_execute_data
1113311159

11160+
if (!left_frame) {
11161+
| // EG(current_execute_data) = execute_data;
11162+
| MEM_OP2_1_ZTS mov, aword, executor_globals, current_execute_data, FP, r0
11163+
}
11164+
1113411165
|9:
1113511166
if (trace) {
1113611167
if (trace->op != ZEND_JIT_TRACE_END

0 commit comments

Comments
 (0)