Skip to content

Commit 605e0de

Browse files
committed
Clenup "smart branch" handling
1 parent 65c4cc2 commit 605e0de

File tree

1 file changed

+62
-70
lines changed

1 file changed

+62
-70
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 62 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7761,26 +7761,24 @@ fallback:
77617761
return zend_jit_handler(Dst, opline, zend_may_throw(opline, op_array, ssa));
77627762
}
77637763

7764-
static int zend_jit_smart_true(dasm_State **Dst, const zend_op *opline, int b, const zend_op_array *op_array, zend_ssa *ssa, int jmp)
7764+
static int zend_jit_smart_true(dasm_State **Dst, const zend_op *opline, int b, const zend_op_array *op_array, zend_ssa *ssa, int jmp, zend_bool smart_branch)
77657765
{
77667766
uint32_t target_label;
77677767

7768-
if ((opline+1)->opcode == ZEND_JMPZ &&
7769-
(opline+1)->op1_type == IS_TMP_VAR &&
7770-
(opline+1)->op1.var == opline->result.var) {
7771-
if (jmp) {
7772-
| jmp >7
7768+
if (smart_branch) {
7769+
if ((opline+1)->opcode == ZEND_JMPZ) {
7770+
if (jmp) {
7771+
| jmp >7
7772+
}
7773+
} else if ((opline+1)->opcode == ZEND_JMPNZ) {
7774+
target_label = ssa->cfg.blocks[b].successors[0];
7775+
| jmp =>target_label
7776+
} else if ((opline+1)->opcode == ZEND_JMPZNZ) {
7777+
target_label = ssa->cfg.blocks[b].successors[1];
7778+
| jmp =>target_label
7779+
} else {
7780+
ZEND_ASSERT(0);
77737781
}
7774-
} else if ((opline+1)->opcode == ZEND_JMPNZ &&
7775-
(opline+1)->op1_type == IS_TMP_VAR &&
7776-
(opline+1)->op1.var == opline->result.var) {
7777-
target_label = ssa->cfg.blocks[b].successors[0];
7778-
| jmp =>target_label
7779-
} else if ((opline+1)->opcode == ZEND_JMPZNZ &&
7780-
(opline+1)->op1_type == IS_TMP_VAR &&
7781-
(opline+1)->op1.var == opline->result.var) {
7782-
target_label = ssa->cfg.blocks[b].successors[1];
7783-
| jmp =>target_label
77847782
} else {
77857783
zend_jit_addr res_addr = zend_jit_decode_op(op_array, opline->result_type, opline->result, opline, NULL, -1);
77867784

@@ -7793,26 +7791,24 @@ static int zend_jit_smart_true(dasm_State **Dst, const zend_op *opline, int b, c
77937791
return 1;
77947792
}
77957793

7796-
static int zend_jit_smart_false(dasm_State **Dst, const zend_op *opline, int b, const zend_op_array *op_array, zend_ssa *ssa, int jmp)
7794+
static int zend_jit_smart_false(dasm_State **Dst, const zend_op *opline, int b, const zend_op_array *op_array, zend_ssa *ssa, int jmp, zend_bool smart_branch)
77977795
{
77987796
uint32_t target_label;
77997797

7800-
if ((opline+1)->opcode == ZEND_JMPZ &&
7801-
(opline+1)->op1_type == IS_TMP_VAR &&
7802-
(opline+1)->op1.var == opline->result.var) {
7803-
target_label = ssa->cfg.blocks[b].successors[0];
7804-
| jmp =>target_label
7805-
} else if ((opline+1)->opcode == ZEND_JMPNZ &&
7806-
(opline+1)->op1_type == IS_TMP_VAR &&
7807-
(opline+1)->op1.var == opline->result.var) {
7808-
if (jmp) {
7809-
| jmp >7
7798+
if (smart_branch) {
7799+
if ((opline+1)->opcode == ZEND_JMPZ) {
7800+
target_label = ssa->cfg.blocks[b].successors[0];
7801+
| jmp =>target_label
7802+
} else if ((opline+1)->opcode == ZEND_JMPNZ) {
7803+
if (jmp) {
7804+
| jmp >7
7805+
}
7806+
} else if ((opline+1)->opcode == ZEND_JMPZNZ) {
7807+
target_label = ssa->cfg.blocks[b].successors[0];
7808+
| jmp =>target_label
7809+
} else {
7810+
ZEND_ASSERT(0);
78107811
}
7811-
} else if ((opline+1)->opcode == ZEND_JMPZNZ &&
7812-
(opline+1)->op1_type == IS_TMP_VAR &&
7813-
(opline+1)->op1.var == opline->result.var) {
7814-
target_label = ssa->cfg.blocks[b].successors[0];
7815-
| jmp =>target_label
78167812
} else {
78177813
zend_jit_addr res_addr = zend_jit_decode_op(op_array, opline->result_type, opline->result, opline, NULL, -1);
78187814

@@ -7948,11 +7944,11 @@ static int zend_jit_type_check(dasm_State **Dst, const zend_op *opline, int b, i
79487944
| mov FCARG1d, opline->op1.var
79497945
| EXT_CALL zend_jit_undefined_op_helper, r0
79507946
if (opline->extended_value & MAY_BE_NULL) {
7951-
if (!zend_jit_smart_true(Dst, opline, b, op_array, ssa, (op1_info & (MAY_BE_ANY|MAY_BE_REF)) != 0)) {
7947+
if (!zend_jit_smart_true(Dst, opline, b, op_array, ssa, (op1_info & (MAY_BE_ANY|MAY_BE_REF)) != 0, smart_branch)) {
79527948
return 0;
79537949
}
79547950
} else {
7955-
if (!zend_jit_smart_false(Dst, opline, b, op_array, ssa, (op1_info & (MAY_BE_ANY|MAY_BE_REF)) != 0)) {
7951+
if (!zend_jit_smart_false(Dst, opline, b, op_array, ssa, (op1_info & (MAY_BE_ANY|MAY_BE_REF)) != 0, smart_branch)) {
79567952
return 0;
79577953
}
79587954
}
@@ -7978,12 +7974,12 @@ static int zend_jit_type_check(dasm_State **Dst, const zend_op *opline, int b, i
79787974

79797975
if (!(op1_info & (MAY_BE_ANY - mask))) {
79807976
| FREE_OP opline->op1_type, opline->op1, op1_info, 1, op_array, opline
7981-
if (!zend_jit_smart_true(Dst, opline, b, op_array, ssa, 0)) {
7977+
if (!zend_jit_smart_true(Dst, opline, b, op_array, ssa, 0, smart_branch)) {
79827978
return 0;
79837979
}
79847980
} else if (!(op1_info & mask)) {
79857981
| FREE_OP opline->op1_type, opline->op1, op1_info, 1, op_array, opline
7986-
if (!zend_jit_smart_false(Dst, opline, b, op_array, ssa, 0)) {
7982+
if (!zend_jit_smart_false(Dst, opline, b, op_array, ssa, 0, smart_branch)) {
79877983
return 0;
79887984
}
79897985
} else {
@@ -8042,23 +8038,21 @@ static int zend_jit_type_check(dasm_State **Dst, const zend_op *opline, int b, i
80428038
| mov eax, 1
80438039
| shl eax, cl
80448040
| test eax, mask
8045-
if ((opline+1)->opcode == ZEND_JMPZ &&
8046-
(opline+1)->op1_type == IS_TMP_VAR &&
8047-
(opline+1)->op1.var == opline->result.var) {
8048-
target_label = ssa->cfg.blocks[b].successors[0];
8049-
| je =>target_label
8050-
} else if ((opline+1)->opcode == ZEND_JMPNZ &&
8051-
(opline+1)->op1_type == IS_TMP_VAR &&
8052-
(opline+1)->op1.var == opline->result.var) {
8053-
target_label = ssa->cfg.blocks[b].successors[0];
8054-
| jne =>target_label
8055-
} else if ((opline+1)->opcode == ZEND_JMPZNZ &&
8056-
(opline+1)->op1_type == IS_TMP_VAR &&
8057-
(opline+1)->op1.var == opline->result.var) {
8058-
target_label = ssa->cfg.blocks[b].successors[0];
8059-
| je =>target_label
8060-
target_label = ssa->cfg.blocks[b].successors[1];
8061-
| jmp =>target_label
8041+
if (smart_branch) {
8042+
if ((opline+1)->opcode == ZEND_JMPZ) {
8043+
target_label = ssa->cfg.blocks[b].successors[0];
8044+
| je =>target_label
8045+
} else if ((opline+1)->opcode == ZEND_JMPNZ) {
8046+
target_label = ssa->cfg.blocks[b].successors[0];
8047+
| jne =>target_label
8048+
} else if ((opline+1)->opcode == ZEND_JMPZNZ) {
8049+
target_label = ssa->cfg.blocks[b].successors[0];
8050+
| je =>target_label
8051+
target_label = ssa->cfg.blocks[b].successors[1];
8052+
| jmp =>target_label
8053+
} else {
8054+
ZEND_ASSERT(0);
8055+
}
80628056
} else {
80638057
zend_jit_addr res_addr = zend_jit_decode_op(op_array, opline->result_type, opline->result, opline, NULL, -1);
80648058

@@ -8117,23 +8111,21 @@ static int zend_jit_type_check(dasm_State **Dst, const zend_op *opline, int b, i
81178111
| cmp byte [FP + opline->op1.var + 8], type
81188112
}
81198113
}
8120-
if ((opline+1)->opcode == ZEND_JMPZ &&
8121-
(opline+1)->op1_type == IS_TMP_VAR &&
8122-
(opline+1)->op1.var == opline->result.var) {
8123-
target_label = ssa->cfg.blocks[b].successors[0];
8124-
| jne =>target_label
8125-
} else if ((opline+1)->opcode == ZEND_JMPNZ &&
8126-
(opline+1)->op1_type == IS_TMP_VAR &&
8127-
(opline+1)->op1.var == opline->result.var) {
8128-
target_label = ssa->cfg.blocks[b].successors[0];
8129-
| je =>target_label
8130-
} else if ((opline+1)->opcode == ZEND_JMPZNZ &&
8131-
(opline+1)->op1_type == IS_TMP_VAR &&
8132-
(opline+1)->op1.var == opline->result.var) {
8133-
target_label = ssa->cfg.blocks[b].successors[0];
8134-
| jne =>target_label
8135-
target_label = ssa->cfg.blocks[b].successors[1];
8136-
| jmp =>target_label
8114+
if (smart_branch) {
8115+
if ((opline+1)->opcode == ZEND_JMPZ) {
8116+
target_label = ssa->cfg.blocks[b].successors[0];
8117+
| jne =>target_label
8118+
} else if ((opline+1)->opcode == ZEND_JMPNZ) {
8119+
target_label = ssa->cfg.blocks[b].successors[0];
8120+
| je =>target_label
8121+
} else if ((opline+1)->opcode == ZEND_JMPZNZ) {
8122+
target_label = ssa->cfg.blocks[b].successors[0];
8123+
| jne =>target_label
8124+
target_label = ssa->cfg.blocks[b].successors[1];
8125+
| jmp =>target_label
8126+
} else {
8127+
ZEND_ASSERT(0);
8128+
}
81378129
} else {
81388130
zend_jit_addr res_addr = zend_jit_decode_op(op_array, opline->result_type, opline->result, opline, NULL, -1);
81398131

0 commit comments

Comments
 (0)