Skip to content

Commit 8930557

Browse files
authored
JIT: Improve CPU register usage in FETCH_DIM_R, FETCH_DIM_IS and FETCH_LIST_R (#14222)
1 parent 77fa4c0 commit 8930557

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,8 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
22192219
}
22202220
if (!zend_jit_fetch_dim_read(&ctx, opline, ssa, ssa_op,
22212221
OP1_INFO(), OP1_REG_ADDR(), 0,
2222-
OP2_INFO(), RES_INFO(), RES_REG_ADDR(), IS_UNKNOWN)) {
2222+
OP2_INFO(), OP2_REG_ADDR(),
2223+
RES_INFO(), RES_REG_ADDR(), IS_UNKNOWN)) {
22232224
goto jit_failure;
22242225
}
22252226
goto done;

ext/opcache/jit/zend_jit_ir.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11366,6 +11366,7 @@ static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit,
1136611366
uint32_t type,
1136711367
uint32_t op1_info,
1136811368
uint32_t op2_info,
11369+
zend_jit_addr op2_addr,
1136911370
uint8_t dim_type,
1137011371
const void *found_exit_addr,
1137111372
const void *not_found_exit_addr,
@@ -11377,7 +11378,6 @@ static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit,
1137711378
ir_ref *end_inputs,
1137811379
ir_ref *not_found_inputs)
1137911380
{
11380-
zend_jit_addr op2_addr = OP2_ADDR();
1138111381
zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var);
1138211382
ir_ref ref = IR_UNUSED, cond, if_found;
1138311383
ir_ref if_type = IS_UNUSED;
@@ -11965,11 +11965,12 @@ static int zend_jit_fetch_dim_read(zend_jit_ctx *jit,
1196511965
zend_jit_addr op1_addr,
1196611966
bool op1_avoid_refcounting,
1196711967
uint32_t op2_info,
11968+
zend_jit_addr op2_addr,
1196811969
uint32_t res_info,
1196911970
zend_jit_addr res_addr,
1197011971
uint8_t dim_type)
1197111972
{
11972-
zend_jit_addr orig_op1_addr, op2_addr;
11973+
zend_jit_addr orig_op1_addr;
1197311974
const void *exit_addr = NULL;
1197411975
const void *not_found_exit_addr = NULL;
1197511976
bool result_type_guard = 0;
@@ -11981,7 +11982,6 @@ static int zend_jit_fetch_dim_read(zend_jit_ctx *jit,
1198111982
ir_ref not_found_inputs = IR_UNUSED;
1198211983

1198311984
orig_op1_addr = OP1_ADDR();
11984-
op2_addr = OP2_ADDR();
1198511985

1198611986
if (opline->opcode != ZEND_FETCH_DIM_IS
1198711987
&& JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE
@@ -12086,7 +12086,7 @@ static int zend_jit_fetch_dim_read(zend_jit_ctx *jit,
1208612086

1208712087
if (!zend_jit_fetch_dimension_address_inner(jit, opline,
1208812088
(opline->opcode != ZEND_FETCH_DIM_IS) ? BP_VAR_R : BP_VAR_IS,
12089-
op1_info, op2_info, dim_type, NULL, not_found_exit_addr, exit_addr,
12089+
op1_info, op2_info, op2_addr, dim_type, NULL, not_found_exit_addr, exit_addr,
1209012090
result_type_guard, ht_ref, found_inputs, found_vals,
1209112091
&end_inputs, &not_found_inputs)) {
1209212092
return 0;
@@ -12489,7 +12489,8 @@ static int zend_jit_fetch_dim(zend_jit_ctx *jit,
1248912489
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_STRING))) {
1249012490
may_throw = 1;
1249112491
}
12492-
if (!zend_jit_fetch_dimension_address_inner(jit, opline, type, op1_info, op2_info, dim_type, NULL, NULL, NULL,
12492+
if (!zend_jit_fetch_dimension_address_inner(jit, opline, type, op1_info,
12493+
op2_info, OP2_ADDR(), dim_type, NULL, NULL, NULL,
1249312494
0, ht_ref, found_inputs, found_vals, &end_inputs, NULL)) {
1249412495
return 0;
1249512496
}
@@ -12648,7 +12649,8 @@ static int zend_jit_isset_isempty_dim(zend_jit_ctx *jit,
1264812649
not_found_exit_addr = exit_addr;
1264912650
}
1265012651
}
12651-
if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_JIT_IS, op1_info, op2_info, dim_type, found_exit_addr, not_found_exit_addr, NULL,
12652+
if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_JIT_IS, op1_info,
12653+
op2_info, OP2_ADDR(), dim_type, found_exit_addr, not_found_exit_addr, NULL,
1265212654
0, ht_ref, true_inputs, NULL, &false_inputs, NULL)) {
1265312655
return 0;
1265412656
}
@@ -12849,7 +12851,8 @@ static int zend_jit_assign_dim(zend_jit_ctx *jit, const zend_op *opline, uint32_
1284912851
ir_refs_init(found_inputs, 8);
1285012852
ir_refs_init(found_values, 8);
1285112853

12852-
if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_VAR_W, op1_info, op2_info, dim_type, NULL, NULL, NULL,
12854+
if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_VAR_W, op1_info,
12855+
op2_info, OP2_ADDR(), dim_type, NULL, NULL, NULL,
1285312856
0, ht_ref, found_inputs, found_values, &end_inputs, NULL)) {
1285412857
return 0;
1285512858
}
@@ -13009,7 +13012,8 @@ static int zend_jit_assign_dim_op(zend_jit_ctx *jit, const zend_op *opline, uint
1300913012
}
1301013013
}
1301113014

13012-
if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_VAR_RW, op1_info, op2_info, dim_type, NULL, not_found_exit_addr, NULL,
13015+
if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_VAR_RW, op1_info,
13016+
op2_info, OP2_ADDR(), dim_type, NULL, not_found_exit_addr, NULL,
1301313017
0, ht_ref, found_inputs, found_values, &end_inputs, NULL)) {
1301413018
return 0;
1301513019
}
@@ -16536,6 +16540,8 @@ static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa
1653616540
case ZEND_FETCH_CONSTANT:
1653716541
return 1;
1653816542
case ZEND_FETCH_DIM_R:
16543+
case ZEND_FETCH_DIM_IS:
16544+
case ZEND_FETCH_LIST_R:
1653916545
op1_info = OP1_INFO();
1654016546
op2_info = OP2_INFO();
1654116547
if (trace
@@ -16544,10 +16550,8 @@ static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa
1654416550
op1_info &= ~((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_ARRAY);
1654516551
}
1654616552
return ((op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY) &&
16547-
(!(opline->op1_type & (IS_TMP_VAR|IS_VAR)) || !(op1_info & MAY_BE_RC1)) &&
1654816553
(((op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG) ||
16549-
(((op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_STRING) &&
16550-
(!(opline->op2_type & (IS_TMP_VAR|IS_VAR)) || !(op2_info & MAY_BE_RC1))));
16554+
((op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_STRING));
1655116555
}
1655216556
return 0;
1655316557
}

ext/opcache/jit/zend_jit_trace.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,9 +2909,7 @@ static zend_jit_reg_var* zend_jit_trace_allocate_registers(zend_jit_trace_rec *t
29092909
if (ssa_op->op2_use >= 0
29102910
&& ssa_op->op2_use != ssa_op->op1_use
29112911
&& RA_HAS_IVAL(ssa_op->op2_use)) {
2912-
/* Quick workaround to disable register allocation for unsupported operand */
2913-
// TODO: Find a general solution ???
2914-
if (!support_opline || opline->opcode == ZEND_FETCH_DIM_R) {
2912+
if (!support_opline) {
29152913
RA_IVAL_DEL(ssa_op->op2_use);
29162914
count--;
29172915
} else if (!zend_ssa_is_no_val_use(opline, ssa_op, ssa_op->op2_use)) {
@@ -5717,7 +5715,8 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
57175715
}
57185716
if (!zend_jit_fetch_dim_read(&ctx, opline, ssa, ssa_op,
57195717
op1_info, op1_addr, avoid_refcounting,
5720-
op2_info, res_info, RES_REG_ADDR(), val_type)) {
5718+
op2_info, OP2_REG_ADDR(),
5719+
res_info, RES_REG_ADDR(), val_type)) {
57215720
goto jit_failure;
57225721
}
57235722
if (ssa_op->op1_def >= 0 && op1_type != IS_UNKNOWN) {

0 commit comments

Comments
 (0)