Skip to content

Commit 8f601be

Browse files
committed
JIT: Allow keeping result of FETCH_CONSTANT in a CPU register
1 parent 8e6e983 commit 8f601be

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

ext/opcache/jit/zend_jit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3861,7 +3861,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
38613861
}
38623862
goto done;
38633863
case ZEND_FETCH_CONSTANT:
3864-
if (!zend_jit_fetch_constant(&dasm_state, opline, op_array, ssa, ssa_op)) {
3864+
if (!zend_jit_fetch_constant(&dasm_state, opline, op_array, ssa, ssa_op, RES_REG_ADDR())) {
38653865
goto jit_failure;
38663866
}
38673867
goto done;

ext/opcache/jit/zend_jit_arm64.dasc

+9-3
Original file line numberDiff line numberDiff line change
@@ -13884,10 +13884,10 @@ static int zend_jit_fetch_constant(dasm_State **Dst,
1388413884
const zend_op *opline,
1388513885
const zend_op_array *op_array,
1388613886
zend_ssa *ssa,
13887-
const zend_ssa_op *ssa_op)
13887+
const zend_ssa_op *ssa_op,
13888+
zend_jit_addr res_addr)
1388813889
{
1388913890
zval *zv = RT_CONSTANT(opline, opline->op2) + 1;
13890-
zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var);
1389113891
zend_jit_addr const_addr = ZEND_ADDR_MEM_ZVAL(ZREG_REG0, 0);
1389213892
uint32_t res_info = RES_INFO();
1389313893

@@ -13929,7 +13929,11 @@ static int zend_jit_fetch_constant(dasm_State **Dst,
1392913929
}
1393013930
| ZVAL_COPY_VALUE_V res_addr, -1, const_addr, res_info, ZREG_REG0, ZREG_REG1, ZREG_TMP1, ZREG_FPR0
1393113931
if (type < IS_STRING) {
13932-
| SET_ZVAL_TYPE_INFO res_addr, type, TMP1w, TMP2
13932+
if (Z_MODE(res_addr) == IS_MEM_ZVAL) {
13933+
| SET_ZVAL_TYPE_INFO res_addr, type, TMP1w, TMP2
13934+
} else if (!zend_jit_store_var_if_necessary(Dst, opline->result.var, res_addr, res_info)) {
13935+
return 0;
13936+
}
1393313937
} else {
1393413938
| SET_ZVAL_TYPE_INFO_FROM_REG res_addr, REG2w, TMP1
1393513939
| TRY_ADDREF res_info, REG2w, REG1, TMP1w
@@ -14266,6 +14270,8 @@ static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa
1426614270
case ZEND_JMPZ_EX:
1426714271
case ZEND_JMPNZ_EX:
1426814272
return 1;
14273+
case ZEND_FETCH_CONSTANT:
14274+
return 1;
1426914275
case ZEND_FETCH_DIM_R:
1427014276
op1_info = OP1_INFO();
1427114277
op2_info = OP2_INFO();

ext/opcache/jit/zend_jit_trace.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2743,7 +2743,8 @@ static zend_lifetime_interval** zend_jit_trace_allocate_registers(zend_jit_trace
27432743
|| opline->opcode == ZEND_ADD
27442744
|| opline->opcode == ZEND_SUB
27452745
|| opline->opcode == ZEND_MUL
2746-
|| opline->opcode == ZEND_FETCH_DIM_R) {
2746+
|| opline->opcode == ZEND_FETCH_DIM_R
2747+
|| opline->opcode == ZEND_FETCH_CONSTANT) {
27472748
if (!(ssa->var_info[ssa_op->result_def].type & MAY_BE_DOUBLE)
27482749
|| (opline->opcode != ZEND_PRE_INC && opline->opcode != ZEND_PRE_DEC)) {
27492750
start[ssa_op->result_def] = idx;
@@ -5730,7 +5731,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
57305731
}
57315732
goto done;
57325733
case ZEND_FETCH_CONSTANT:
5733-
if (!zend_jit_fetch_constant(&dasm_state, opline, op_array, ssa, ssa_op)) {
5734+
if (!zend_jit_fetch_constant(&dasm_state, opline, op_array, ssa, ssa_op, RES_REG_ADDR())) {
57345735
goto jit_failure;
57355736
}
57365737
goto done;

ext/opcache/jit/zend_jit_x86.dasc

+9-3
Original file line numberDiff line numberDiff line change
@@ -14729,10 +14729,10 @@ static int zend_jit_fetch_constant(dasm_State **Dst,
1472914729
const zend_op *opline,
1473014730
const zend_op_array *op_array,
1473114731
zend_ssa *ssa,
14732-
const zend_ssa_op *ssa_op)
14732+
const zend_ssa_op *ssa_op,
14733+
zend_jit_addr res_addr)
1473314734
{
1473414735
zval *zv = RT_CONSTANT(opline, opline->op2) + 1;
14735-
zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var);
1473614736
zend_jit_addr const_addr = ZEND_ADDR_MEM_ZVAL(ZREG_R0, 0);
1473714737
uint32_t res_info = RES_INFO();
1473814738

@@ -14774,7 +14774,11 @@ static int zend_jit_fetch_constant(dasm_State **Dst,
1477414774
}
1477514775
| ZVAL_COPY_VALUE_V res_addr, -1, const_addr, res_info, ZREG_R0, ZREG_R1
1477614776
if (type < IS_STRING) {
14777-
| SET_ZVAL_TYPE_INFO res_addr, type
14777+
if (Z_MODE(res_addr) == IS_MEM_ZVAL) {
14778+
| SET_ZVAL_TYPE_INFO res_addr, type
14779+
} else if (!zend_jit_store_var_if_necessary(Dst, opline->result.var, res_addr, res_info)) {
14780+
return 0;
14781+
}
1477814782
} else {
1477914783
| SET_ZVAL_TYPE_INFO res_addr, edx
1478014784
| TRY_ADDREF res_info, dh, r1
@@ -15111,6 +15115,8 @@ static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa
1511115115
case ZEND_JMPZ_EX:
1511215116
case ZEND_JMPNZ_EX:
1511315117
return 1;
15118+
case ZEND_FETCH_CONSTANT:
15119+
return 1;
1511415120
case ZEND_FETCH_DIM_R:
1511515121
op1_info = OP1_INFO();
1511615122
op2_info = OP2_INFO();

0 commit comments

Comments
 (0)