Skip to content

Commit a5e502e

Browse files
committed
JIT: Combine type guard with overflow detection
1 parent 20a784e commit a5e502e

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12505,6 +12505,7 @@ static int zend_jit_incdec_obj(dasm_State **Dst,
1250512505
bool needs_slow_path = 0;
1250612506
bool use_prop_guard = 0;
1250712507
bool may_throw = 0;
12508+
uint32_t res_info = (opline->result_type != IS_UNDEF) ? RES_INFO() : 0;
1250812509

1250912510
ZEND_ASSERT(opline->op2_type == IS_CONST);
1251012511
ZEND_ASSERT(op1_info & MAY_BE_OBJECT);
@@ -12820,9 +12821,21 @@ static int zend_jit_incdec_obj(dasm_State **Dst,
1282012821
| SET_ZVAL_TYPE_INFO res_addr, IS_DOUBLE, TMP1w, TMP2
1282112822
}
1282212823
}
12823-
| b >4
12824-
|.code
12825-
|4:
12824+
if (opline->result_type != IS_UNUSED
12825+
&& (opline->opcode == ZEND_PRE_INC_OBJ || opline->opcode == ZEND_PRE_DEC_OBJ)
12826+
&& (res_info & MAY_BE_GUARD)
12827+
&& (res_info & MAY_BE_LONG)) {
12828+
int32_t exit_point = zend_jit_trace_get_exit_point(opline + 1, 0);
12829+
const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point);
12830+
12831+
ssa->var_info[ssa_op->result_def].type = res_info & ~MAY_BE_GUARD;
12832+
| b &exit_addr
12833+
|.code
12834+
} else {
12835+
| b >4
12836+
|.code
12837+
|4:
12838+
}
1282612839
}
1282712840
}
1282812841

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13209,6 +13209,7 @@ static int zend_jit_incdec_obj(dasm_State **Dst,
1320913209
bool needs_slow_path = 0;
1321013210
bool use_prop_guard = 0;
1321113211
bool may_throw = 0;
13212+
uint32_t res_info = (opline->result_type != IS_UNDEF) ? RES_INFO() : 0;
1321213213

1321313214
ZEND_ASSERT(opline->op2_type == IS_CONST);
1321413215
ZEND_ASSERT(op1_info & MAY_BE_OBJECT);
@@ -13546,9 +13547,21 @@ static int zend_jit_incdec_obj(dasm_State **Dst,
1354613547
}
1354713548
|.endif
1354813549
}
13549-
| jmp >4
13550-
|.code
13551-
|4:
13550+
if (opline->result_type != IS_UNUSED
13551+
&& (opline->opcode == ZEND_PRE_INC_OBJ || opline->opcode == ZEND_PRE_DEC_OBJ)
13552+
&& (res_info & MAY_BE_GUARD)
13553+
&& (res_info & MAY_BE_LONG)) {
13554+
int32_t exit_point = zend_jit_trace_get_exit_point(opline + 1, 0);
13555+
const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point);
13556+
13557+
ssa->var_info[ssa_op->result_def].type = res_info & ~MAY_BE_GUARD;
13558+
| jmp &exit_addr
13559+
|.code
13560+
} else {
13561+
| jmp >4
13562+
|.code
13563+
|4:
13564+
}
1355213565
}
1355313566
}
1355413567

0 commit comments

Comments
 (0)