Skip to content

Commit 8126205

Browse files
committed
Try with pass_two modification of result_op instead
1 parent 2bb4ad1 commit 8126205

File tree

13 files changed

+28
-47
lines changed

13 files changed

+28
-47
lines changed

Zend/Optimizer/optimize_temp_vars_5.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
4949
int *map_T; /* Map's the T to its new index */
5050
zend_op *opline, *end;
5151
int currT;
52-
int exclNextT = -1;
5352
int i;
5453
int max = -1;
5554
void *checkpoint = zend_arena_checkpoint(ctx->arena);
@@ -145,11 +144,6 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
145144
opline->op2.var = NUM_VAR(map_T[currT] + offset);
146145
}
147146

148-
if (exclNextT != -1) {
149-
zend_bitset_excl(taken_T, exclNextT);
150-
exclNextT = -1;
151-
}
152-
153147
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
154148
currT = VAR_NUM(opline->result.var) - offset;
155149
if (map_T[currT] == INVALID_VAR) {
@@ -163,12 +157,7 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
163157
* since the fast_var could also be set by ZEND_HANDLE_EXCEPTION
164158
* which could be ahead of it */
165159
if (opline->opcode != ZEND_FAST_CALL) {
166-
if (opline->opcode == ZEND_OP_DATA) {
167-
/* ZEND_OP_DATA may contain a result, which must not be equal to any of its prior opcode vars */
168-
exclNextT = map_T[currT];
169-
} else {
170-
zend_bitset_excl(taken_T, map_T[currT]);
171-
}
160+
zend_bitset_excl(taken_T, map_T[currT]);
172161
}
173162
if (opline->opcode == ZEND_ROPE_INIT) {
174163
uint32_t num = ((opline->extended_value * sizeof(zend_string*)) + (sizeof(zval) - 1)) / sizeof(zval);

Zend/Optimizer/sccp.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,10 +2139,6 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
21392139
}
21402140
return 0;
21412141
}
2142-
if (opline->opcode == ZEND_OP_DATA) {
2143-
/* Consider the primary opline for matching */
2144-
--opline;
2145-
}
21462142
if (ssa_op->op1_def >= 0 || ssa_op->op2_def >= 0) {
21472143
if (var->use_chain < 0 && var->phi_use_chain == NULL) {
21482144
switch (opline->opcode) {
@@ -2213,8 +2209,6 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
22132209
zend_ssa_remove_instr(ssa, opline, ssa_op);
22142210
removed_ops++;
22152211
if (has_op_data) {
2216-
old_type = opline[1].result_type;
2217-
old_var = opline[1].result.var;
22182212
zend_ssa_remove_instr(ssa, opline + 1, ssa_op + 1);
22192213
removed_ops++;
22202214
}

Zend/Optimizer/scdf.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ void scdf_solve(scdf_ctx *scdf, const char *name) {
124124
zend_ssa_op *ssa_op = &ssa->ops[i];
125125
if (opline->opcode == ZEND_OP_DATA) {
126126
opline--;
127-
if (opline->opcode != ZEND_FRAMELESS_ICALL_3) {
128-
// result op not on OP_DATA
129-
ssa_op--;
130-
}
127+
ssa_op--;
131128
}
132129
scdf->handlers.visit_instr(scdf, opline, ssa_op);
133130
if (i == block->start + block->len - 1) {
@@ -165,7 +162,7 @@ void scdf_solve(scdf_ctx *scdf, const char *name) {
165162
for (j = block->start; j < end; j++) {
166163
opline = &scdf->op_array->opcodes[j];
167164
zend_bitset_excl(scdf->instr_worklist, j);
168-
if (opline->opcode != ZEND_OP_DATA || opline[-1].opcode == ZEND_FRAMELESS_ICALL_3) {
165+
if (opline->opcode != ZEND_OP_DATA) {
169166
scdf->handlers.visit_instr(scdf, opline, &ssa->ops[j]);
170167
}
171168
}
@@ -175,10 +172,7 @@ void scdf_solve(scdf_ctx *scdf, const char *name) {
175172
ZEND_ASSERT(opline && "Should have opline in non-empty block");
176173
if (opline->opcode == ZEND_OP_DATA) {
177174
opline--;
178-
if (opline->opcode != ZEND_FRAMELESS_ICALL_3) {
179-
// result op not on OP_DATA
180-
j--;
181-
}
175+
j--;
182176
}
183177
scdf->handlers.mark_feasible_successors(scdf, i, block, opline, &ssa->ops[j-1]);
184178
}

Zend/Optimizer/zend_dfg.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ static zend_always_inline void _zend_dfg_add_use_def_op(const zend_op_array *op_
130130
zend_bitset_incl(use, var_num);
131131
}
132132
}
133-
if (opline->opcode == ZEND_FRAMELESS_ICALL_3) {
134-
++opline; // OP_DATA has result
135-
}
136133
break;
137134
case ZEND_ASSIGN_DIM_OP:
138135
case ZEND_ASSIGN_OBJ_OP:

Zend/Optimizer/zend_inference.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3869,7 +3869,7 @@ static zend_always_inline zend_result _zend_update_type_info(
38693869
UPDATE_SSA_TYPE(tmp, ssa_op->op2_def);
38703870
}
38713871
if (opline->opcode == ZEND_FRAMELESS_ICALL_3) {
3872-
zend_ssa_op *next_ssa_op = ++ssa_op; // OP_DATA has result op
3872+
zend_ssa_op *next_ssa_op = ssa_op + 1;
38733873
if (next_ssa_op->op1_def >= 0) {
38743874
ZEND_ASSERT(next_ssa_op->op1_use >= 0);
38753875
tmp = ssa->var_info[next_ssa_op->op1_use].type;

Zend/Optimizer/zend_optimizer.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,9 @@ static void zend_revert_pass_two(zend_op_array *op_array)
11541154
}
11551155
/* reset smart branch flags IS_SMART_BRANCH_JMP[N]Z */
11561156
opline->result_type &= (IS_TMP_VAR|IS_VAR|IS_CV|IS_CONST);
1157+
if (opline->opcode == ZEND_FRAMELESS_ICALL_3) {
1158+
(opline+1)->result_type = IS_UNUSED;
1159+
}
11571160
opline++;
11581161
}
11591162
#if !ZEND_USE_ABS_CONST_ADDR
@@ -1273,6 +1276,10 @@ static void zend_redo_pass_two(zend_op_array *op_array)
12731276
}
12741277
}
12751278
break;
1279+
case ZEND_FRAMELESS_ICALL_3:
1280+
(opline+1)->result.var = opline->result.var;
1281+
(opline+1)->result_type = opline->result_type;
1282+
break;
12761283
}
12771284
ZEND_VM_SET_OPCODE_HANDLER(opline);
12781285
opline++;
@@ -1395,6 +1402,10 @@ static void zend_redo_pass_two_ex(zend_op_array *op_array, zend_ssa *ssa)
13951402
}
13961403
}
13971404
break;
1405+
case ZEND_FRAMELESS_ICALL_3:
1406+
(opline+1)->result.var = opline->result.var;
1407+
(opline+1)->result_type = opline->result_type;
1408+
break;
13981409
}
13991410
#ifdef ZEND_VERIFY_TYPE_INFERENCE
14001411
if (ssa_op->op1_use >= 0) {

Zend/Optimizer/zend_ssa.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,14 +782,12 @@ static zend_always_inline int _zend_ssa_rename_op(const zend_op_array *op_array,
782782
//NEW_SSA_VAR(opline->op2.var)
783783
}
784784
if (opline->opcode == ZEND_FRAMELESS_ICALL_3) {
785-
// Result is on following OP_DATA
786-
next = ++opline;
787-
++k;
785+
next = opline + 1;
788786
if (next->op1_type & (IS_CV|IS_VAR|IS_TMP_VAR)) {
789-
ssa_ops[k].op1_use = var[EX_VAR_TO_NUM(next->op1.var)];
787+
ssa_ops[k + 1].op1_use = var[EX_VAR_TO_NUM(next->op1.var)];
790788
//USE_SSA_VAR(op_array->last_var + next->op1.var);
791789
if ((build_flags & ZEND_SSA_RC_INFERENCE) && next->op1_type == IS_CV) {
792-
ssa_ops[k].op1_def = ssa_vars_count;
790+
ssa_ops[k + 1].op1_def = ssa_vars_count;
793791
var[EX_VAR_TO_NUM(next->op1.var)] = ssa_vars_count;
794792
ssa_vars_count++;
795793
//NEW_SSA_VAR(next->op1.var)

Zend/zend_compile.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4608,12 +4608,7 @@ static uint32_t zend_compile_frameless_icall_ex(znode *result, zend_ast_list *ar
46084608
SET_NODE(opline->op2, &arg_zvs[1]);
46094609
}
46104610
if (num_args >= 3) {
4611-
// Put result znode on OP_DATA to ensure dispatch in observer fallback can be aligned with the last opcode of the call
4612-
zend_op *op_data = zend_emit_op_data(&arg_zvs[2]);
4613-
op_data->result = opline->result;
4614-
op_data->result_type = opline->result_type;
4615-
opline->result_type = IS_UNUSED;
4616-
++opnum;
4611+
zend_emit_op_data(&arg_zvs[2]);
46174612
}
46184613
return opnum;
46194614
}

Zend/zend_opcode.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,11 @@ ZEND_API void pass_two(zend_op_array *op_array)
11221122
case ZEND_JMP_FRAMELESS:
11231123
ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, opline->op2);
11241124
break;
1125+
case ZEND_FRAMELESS_ICALL_3:
1126+
// Copy result to OP_DATA to ensure dispatch in observer fallback can be aligned with the last opcode of the call
1127+
opline[1].result.var = opline->result.var;
1128+
opline[1].result_type = opline->result_type;
1129+
break;
11251130
case ZEND_ASSERT_CHECK:
11261131
{
11271132
/* If result of assert is unused, result of check is unused as well */

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9694,7 +9694,7 @@ ZEND_VM_HANDLER(207, ZEND_FRAMELESS_ICALL_3, ANY, ANY, SPEC(OBSERVER))
96949694
USE_OPLINE
96959695
SAVE_OPLINE();
96969696
zend_frameless_function_3 function = (zend_frameless_function_3)ZEND_FLF_HANDLER(opline);
9697-
zval *result = EX_VAR(opline[1].result.var);
9697+
zval *result = EX_VAR(opline->result.var);
96989698
ZVAL_NULL(result);
96999699
zval *arg1 = GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R);
97009700
zval *arg2 = GET_OP2_ZVAL_PTR_DEREF(BP_VAR_R);

ext/opcache/jit/zend_jit_internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ typedef uintptr_t zend_jit_addr;
9090
OP_ADDR(opline, result_type, result)
9191
#define OP1_DATA_ADDR() \
9292
OP_ADDR(opline + 1, op1_type, op1)
93-
#define RES_DATA_ADDR() \
94-
OP_ADDR(opline + 1, result_type, result)
9593

9694
#define OP1_REG_ADDR() \
9795
OP_REG_ADDR(opline, op1_type, op1, op1_use)

ext/opcache/jit/zend_jit_ir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16886,7 +16886,7 @@ static void jit_frameless_icall3(zend_jit_ctx *jit, int checked_stack, const zen
1688616886

1688716887
void *function = ZEND_FLF_HANDLER(opline);
1688816888
uint8_t op_data_type = (opline + 1)->op1_type;
16889-
zend_jit_addr res_addr = RES_DATA_ADDR();
16889+
zend_jit_addr res_addr = RES_ADDR();
1689016890
zend_jit_addr op1_addr = OP1_ADDR();
1689116891
zend_jit_addr op2_addr = OP2_ADDR();
1689216892
zend_jit_addr op3_addr = OP1_DATA_ADDR();

ext/opcache/tests/opt/inference_frameless.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ _strpos:
2525
; (after optimizer)
2626
; %sinference_frameless.php:2-4
2727
0000 CV0($str) = RECV 1
28-
0001 FRAMELESS_ICALL_3(strpos) CV0($str) string("o")
28+
0001 T1 = FRAMELESS_ICALL_3(strpos) CV0($str) string("o")
2929
0002 T1 = OP_DATA int(1)
3030
0003 RETURN T1

0 commit comments

Comments
 (0)