Skip to content

Commit b35a9a4

Browse files
committed
Reorder conditions to save one instruction in recursive return loop
1 parent ce668c0 commit b35a9a4

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
26732673
}
26742674
}
26752675
}
2676-
if (!zend_jit_leave_func(&dasm_state, opline, op_array, NULL)) {
2676+
if (!zend_jit_leave_func(&dasm_state, opline, op_array, NULL, NULL)) {
26772677
goto jit_failure;
26782678
}
26792679
}

ext/opcache/jit/zend_jit_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ typedef union _zend_jit_trace_stack {
331331

332332
/* trace info flags */
333333
#define ZEND_JIT_TRACE_CHECK_INTERRUPT (1<<0)
334+
#define ZEND_JIT_TRACE_LOOP (1<<1)
334335

335336
typedef struct _zend_jit_trace_info {
336337
uint32_t id; /* trace id */

ext/opcache/jit/zend_jit_trace.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,7 +3334,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
33343334
}
33353335
}
33363336
}
3337-
if (!zend_jit_leave_func(&dasm_state, opline, op_array, p + 1)) {
3337+
if (!zend_jit_leave_func(&dasm_state, opline, op_array, p + 1, &zend_jit_traces[ZEND_JIT_TRACE_NUM])) {
33383338
goto jit_failure;
33393339
}
33403340
}
@@ -4046,7 +4046,10 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
40464046
if (p->stop != ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
40474047
t->flags |= ZEND_JIT_TRACE_CHECK_INTERRUPT;
40484048
}
4049-
zend_jit_trace_end_loop(&dasm_state, 0, timeout_exit_addr); /* jump back to start of the trace loop */
4049+
if (!(t->flags & ZEND_JIT_TRACE_LOOP)) {
4050+
t->flags |= ZEND_JIT_TRACE_LOOP;
4051+
zend_jit_trace_end_loop(&dasm_state, 0, timeout_exit_addr); /* jump back to start of the trace loop */
4052+
}
40504053
} else if (p->stop == ZEND_JIT_TRACE_STOP_LINK) {
40514054
if (ra) {
40524055
/* Generate code for trace deoptimization */

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9572,7 +9572,7 @@ static int zend_jit_free_cv(dasm_State **Dst, const zend_op *opline, const zend_
95729572
return 1;
95739573
}
95749574

9575-
static int zend_jit_leave_func(dasm_State **Dst, const zend_op *opline, const zend_op_array *op_array, zend_jit_trace_rec *trace)
9575+
static int zend_jit_leave_func(dasm_State **Dst, const zend_op *opline, const zend_op_array *op_array, zend_jit_trace_rec *trace, zend_jit_trace_info *trace_info)
95769576
{
95779577
/* ZEND_CALL_FAKE_CLOSURE handled on slow path to eliminate check for ZEND_CALL_CLOSURE on fast path */
95789578
| mov FCARG1d, dword [FP + offsetof(zend_execute_data, This.u1.type_info)]
@@ -9669,8 +9669,16 @@ static int zend_jit_leave_func(dasm_State **Dst, const zend_op *opline, const ze
96699669
return 0;
96709670
}
96719671
| // TODO: exception handling ???
9672-
| CMP_IP next_opline
9673-
| jne &exit_addr
9672+
if (trace->op == ZEND_JIT_TRACE_END
9673+
&& trace->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_RET) {
9674+
trace_info->flags |= ZEND_JIT_TRACE_LOOP;
9675+
| CMP_IP next_opline
9676+
| je =>0 // LOOP
9677+
| jmp &exit_addr
9678+
} else {
9679+
| CMP_IP next_opline
9680+
| jne &exit_addr
9681+
}
96749682

96759683
last_valid_opline = trace->opline;
96769684

0 commit comments

Comments
 (0)