Skip to content

Commit 29dd124

Browse files
committed
Clenup BINARY_OP + SEND_VAL optimization
1 parent 62c6d69 commit 29dd124

File tree

3 files changed

+51
-65
lines changed

3 files changed

+51
-65
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,6 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
20342034
zend_uchar smart_branch_opcode;
20352035
uint32_t target_label, target_label2;
20362036
uint32_t op1_info, op1_def_info, op2_info, res_info, res_use_info;
2037-
zend_bool send_result;
20382037
zend_jit_addr op1_addr, op1_def_addr, op2_addr, op2_def_addr, res_addr;
20392038
zend_class_entry *ce;
20402039
zend_bool ce_is_instanceof;
@@ -2306,19 +2305,19 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
23062305
&& (opline+1)->op1_type == IS_TMP_VAR
23072306
&& (opline+1)->op1.var == opline->result.var) {
23082307
i++;
2309-
send_result = 1;
23102308
res_use_info = -1;
2311-
res_addr = 0; /* set inside backend */
2309+
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
2310+
if (!zend_jit_reuse_ip(&dasm_state)) {
2311+
goto jit_failure;
2312+
}
23122313
} else {
2313-
send_result = 0;
23142314
res_use_info = RES_USE_INFO();
23152315
res_addr = RES_REG_ADDR();
23162316
}
23172317
if (!zend_jit_long_math(&dasm_state, opline,
23182318
op1_info, OP1_RANGE(), OP1_REG_ADDR(),
23192319
op2_info, OP2_RANGE(), OP2_REG_ADDR(),
23202320
res_use_info, RES_INFO(), res_addr,
2321-
send_result,
23222321
zend_may_throw(opline, ssa_op, op_array, ssa))) {
23232322
goto jit_failure;
23242323
}
@@ -2353,11 +2352,12 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
23532352
&& (opline+1)->op1_type == IS_TMP_VAR
23542353
&& (opline+1)->op1.var == opline->result.var) {
23552354
i++;
2356-
send_result = 1;
23572355
res_use_info = -1;
2358-
res_addr = 0; /* set inside backend */
2356+
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
2357+
if (!zend_jit_reuse_ip(&dasm_state)) {
2358+
goto jit_failure;
2359+
}
23592360
} else {
2360-
send_result = 0;
23612361
res_use_info = RES_USE_INFO();
23622362
res_addr = RES_REG_ADDR();
23632363
}
@@ -2366,7 +2366,6 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
23662366
op1_info, OP1_REG_ADDR(),
23672367
op2_info, OP2_REG_ADDR(),
23682368
res_use_info, res_info, res_addr,
2369-
send_result,
23702369
(op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG) && (res_info & MAY_BE_DOUBLE) && zend_may_overflow(opline, ssa_op, op_array, ssa),
23712370
zend_may_throw(opline, ssa_op, op_array, ssa))) {
23722371
goto jit_failure;
@@ -2392,12 +2391,15 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
23922391
&& (opline+1)->op1_type == IS_TMP_VAR
23932392
&& (opline+1)->op1.var == opline->result.var) {
23942393
i++;
2395-
send_result = 1;
2394+
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
2395+
if (!zend_jit_reuse_ip(&dasm_state)) {
2396+
goto jit_failure;
2397+
}
23962398
} else {
2397-
send_result = 0;
2399+
res_addr = RES_REG_ADDR();
23982400
}
23992401
if (!zend_jit_concat(&dasm_state, opline,
2400-
op1_info, op2_info, send_result,
2402+
op1_info, op2_info, res_addr,
24012403
zend_may_throw(opline, ssa_op, op_array, ssa))) {
24022404
goto jit_failure;
24032405
}

ext/opcache/jit/zend_jit_trace.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,7 +3524,10 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
35243524
}
35253525
send_result = 1;
35263526
res_use_info = -1;
3527-
res_addr = 0; /* set inside backend */
3527+
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
3528+
if (!zend_jit_reuse_ip(&dasm_state)) {
3529+
goto jit_failure;
3530+
}
35283531
} else {
35293532
send_result = 0;
35303533
if (opline->result_type == IS_CV) {
@@ -3543,7 +3546,6 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
35433546
op1_info, OP1_RANGE(), OP1_REG_ADDR(),
35443547
op2_info, OP2_RANGE(), OP2_REG_ADDR(),
35453548
res_use_info, res_info, res_addr,
3546-
send_result,
35473549
zend_may_throw(opline, ssa_op, op_array, ssa))) {
35483550
goto jit_failure;
35493551
}
@@ -3595,7 +3597,10 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
35953597
}
35963598
send_result = 1;
35973599
res_use_info = -1;
3598-
res_addr = 0; /* set inside backend */
3600+
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
3601+
if (!zend_jit_reuse_ip(&dasm_state)) {
3602+
goto jit_failure;
3603+
}
35993604
} else {
36003605
send_result = 0;
36013606
if (opline->result_type == IS_CV) {
@@ -3614,7 +3619,6 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
36143619
op1_info, OP1_REG_ADDR(),
36153620
op2_info, OP2_REG_ADDR(),
36163621
res_use_info, res_info, res_addr,
3617-
send_result,
36183622
(op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG) && (res_info & (MAY_BE_DOUBLE|MAY_BE_GUARD)) && zend_may_overflow(opline, ssa_op, op_array, ssa),
36193623
zend_may_throw(opline, ssa_op, op_array, ssa))) {
36203624
goto jit_failure;
@@ -3659,11 +3663,16 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
36593663
p++;
36603664
}
36613665
send_result = 1;
3666+
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
3667+
if (!zend_jit_reuse_ip(&dasm_state)) {
3668+
goto jit_failure;
3669+
}
36623670
} else {
36633671
send_result = 0;
3672+
res_addr = RES_REG_ADDR();
36643673
}
36653674
if (!zend_jit_concat(&dasm_state, opline,
3666-
op1_info, op2_info, send_result,
3675+
op1_info, op2_info, res_addr,
36673676
zend_may_throw(opline, ssa_op, op_array, ssa))) {
36683677
goto jit_failure;
36693678
}

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,16 @@ static void zend_jit_start_reuse_ip(void)
16561656
reuse_ip = 1;
16571657
}
16581658

1659+
static int zend_jit_reuse_ip(dasm_State **Dst)
1660+
{
1661+
if (!reuse_ip) {
1662+
zend_jit_start_reuse_ip();
1663+
| // call = EX(call);
1664+
| mov RX, EX->call
1665+
}
1666+
return 1;
1667+
}
1668+
16591669
static void zend_jit_stop_reuse_ip(void)
16601670
{
16611671
reuse_ip = 0;
@@ -4709,21 +4719,12 @@ static int zend_jit_math_helper(dasm_State **Dst,
47094719
return 1;
47104720
}
47114721

4712-
static int zend_jit_math(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint32_t op2_info, zend_jit_addr op2_addr, uint32_t res_use_info, uint32_t res_info, zend_jit_addr res_addr, zend_bool send_result, int may_overflow, int may_throw)
4722+
static int zend_jit_math(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint32_t op2_info, zend_jit_addr op2_addr, uint32_t res_use_info, uint32_t res_info, zend_jit_addr res_addr, int may_overflow, int may_throw)
47134723
{
47144724
ZEND_ASSERT(!(op1_info & MAY_BE_UNDEF) && !(op2_info & MAY_BE_UNDEF));
47154725
ZEND_ASSERT((op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE)) &&
47164726
(op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE)));
47174727

4718-
if (send_result) {
4719-
if (!reuse_ip) {
4720-
zend_jit_start_reuse_ip();
4721-
| // call = EX(call);
4722-
| mov RX, EX->call
4723-
}
4724-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
4725-
}
4726-
47274728
if (!zend_jit_math_helper(Dst, opline, opline->opcode, opline->op1_type, opline->op1, op1_addr, op1_info, opline->op2_type, opline->op2, op2_addr, op2_info, opline->result.var, res_addr, res_info, res_use_info, may_overflow, may_throw)) {
47284729
return 0;
47294730
}
@@ -5049,20 +5050,11 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
50495050
return 1;
50505051
}
50515052

5052-
static int zend_jit_long_math(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, zend_ssa_range *op1_range, zend_jit_addr op1_addr, uint32_t op2_info, zend_ssa_range *op2_range, zend_jit_addr op2_addr, uint32_t res_use_info, uint32_t res_info, zend_jit_addr res_addr, zend_bool send_result, int may_throw)
5053+
static int zend_jit_long_math(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, zend_ssa_range *op1_range, zend_jit_addr op1_addr, uint32_t op2_info, zend_ssa_range *op2_range, zend_jit_addr op2_addr, uint32_t res_use_info, uint32_t res_info, zend_jit_addr res_addr, int may_throw)
50535054
{
50545055
ZEND_ASSERT(!(op1_info & MAY_BE_UNDEF) && !(op2_info & MAY_BE_UNDEF));
50555056
ZEND_ASSERT((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG));
50565057

5057-
if (send_result) {
5058-
if (!reuse_ip) {
5059-
zend_jit_start_reuse_ip();
5060-
| // call = EX(call);
5061-
| mov RX, EX->call
5062-
}
5063-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
5064-
}
5065-
50665058
if (!zend_jit_long_math_helper(Dst, opline, opline->opcode,
50675059
opline->op1_type, opline->op1, op1_addr, op1_info, op1_range,
50685060
opline->op2_type, opline->op2, op2_addr, op2_info, op2_range,
@@ -5160,26 +5152,16 @@ static int zend_jit_concat_helper(dasm_State **Dst,
51605152
return 1;
51615153
}
51625154

5163-
static int zend_jit_concat(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, uint32_t op2_info, zend_bool send_result, int may_throw)
5155+
static int zend_jit_concat(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, uint32_t op2_info, zend_jit_addr res_addr, int may_throw)
51645156
{
5165-
zend_jit_addr op1_addr, op2_addr, res_addr;
5157+
zend_jit_addr op1_addr, op2_addr;
51665158

51675159
ZEND_ASSERT(!(op1_info & MAY_BE_UNDEF) && !(op2_info & MAY_BE_UNDEF));
51685160
ZEND_ASSERT((op1_info & MAY_BE_STRING) && (op2_info & MAY_BE_STRING));
51695161

51705162
op1_addr = OP1_ADDR();
51715163
op2_addr = OP2_ADDR();
51725164

5173-
if (send_result) {
5174-
if (!reuse_ip) {
5175-
zend_jit_start_reuse_ip();
5176-
| // call = EX(call);
5177-
| mov RX, EX->call
5178-
}
5179-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, (opline+1)->result.var);
5180-
} else {
5181-
res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var);
5182-
}
51835165
return zend_jit_concat_helper(Dst, opline, opline->op1_type, opline->op1, op1_addr, op1_info, opline->op2_type, opline->op2, op2_addr, op2_info, res_addr, may_throw);
51845166
}
51855167

@@ -10011,10 +9993,8 @@ static int zend_jit_send_val(dasm_State **Dst, const zend_op *opline, uint32_t o
100119993

100129994
ZEND_ASSERT(opline->opcode == ZEND_SEND_VAL || arg_num <= MAX_ARG_FLAG_NUM);
100139995

10014-
if (!reuse_ip) {
10015-
zend_jit_start_reuse_ip();
10016-
| // call = EX(call);
10017-
| mov RX, EX->call
9996+
if (!zend_jit_reuse_ip(Dst)) {
9997+
return 0;
100189998
}
100199999

1002010000
if (opline->opcode == ZEND_SEND_VAL_EX) {
@@ -10093,10 +10073,8 @@ static int zend_jit_send_ref(dasm_State **Dst, const zend_op *opline, const zend
1009310073
op1_addr = OP1_ADDR();
1009410074
arg_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, opline->result.var);
1009510075

10096-
if (!reuse_ip) {
10097-
zend_jit_start_reuse_ip();
10098-
| // call = EX(call);
10099-
| mov RX, EX->call
10076+
if (!zend_jit_reuse_ip(Dst)) {
10077+
return 0;
1010010078
}
1010110079

1010210080
if (opline->op1_type == IS_VAR) {
@@ -10180,10 +10158,8 @@ static int zend_jit_send_var(dasm_State **Dst, const zend_op *opline, const zend
1018010158

1018110159
arg_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, opline->result.var);
1018210160

10183-
if (!reuse_ip) {
10184-
zend_jit_start_reuse_ip();
10185-
| // call = EX(call);
10186-
| mov RX, EX->call
10161+
if (!zend_jit_reuse_ip(Dst)) {
10162+
return 0;
1018710163
}
1018810164

1018910165
if (opline->opcode == ZEND_SEND_VAR_EX) {
@@ -10427,11 +10403,10 @@ static int zend_jit_check_func_arg(dasm_State **Dst, const zend_op *opline)
1042710403
// if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(EX(call)->func, arg_num)) {
1042810404
uint32_t mask = (ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF) << ((arg_num + 3) * 2);
1042910405

10430-
if (!reuse_ip) {
10431-
zend_jit_start_reuse_ip();
10432-
| // call = EX(call);
10433-
| mov RX, EX->call
10406+
if (!zend_jit_reuse_ip(Dst)) {
10407+
return 0;
1043410408
}
10409+
1043510410
| mov r0, EX:RX->func
1043610411
| test dword [r0 + offsetof(zend_function, quick_arg_flags)], mask
1043710412
| jnz >1

0 commit comments

Comments
 (0)