Skip to content

Commit c2fea2a

Browse files
committed
Respect RC_INFERENCE during DFG construction
To avoid inserting phis that are only relevant with rc inference enabled. Suprisingly, this affects only 0.8% of phis.
1 parent 949aaea commit c2fea2a

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

ext/opcache/Optimizer/zend_dfg.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "zend_compile.h"
2121
#include "zend_dfg.h"
2222

23-
int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg *dfg) /* {{{ */
23+
int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg *dfg, uint32_t build_flags) /* {{{ */
2424
{
2525
int set_size;
2626
zend_basic_block *blocks = cfg->blocks;
@@ -89,18 +89,33 @@ int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg
8989
}
9090
if (opline->op1_type == IS_CV) {
9191
switch (opline->opcode) {
92+
case ZEND_ADD_ARRAY_ELEMENT:
93+
case ZEND_INIT_ARRAY:
94+
if ((build_flags & ZEND_SSA_RC_INFERENCE)
95+
|| (opline->extended_value & ZEND_ARRAY_ELEMENT_REF)) {
96+
goto op1_def;
97+
}
98+
goto op1_use;
99+
case ZEND_FE_RESET_R:
100+
if (build_flags & ZEND_SSA_RC_INFERENCE) {
101+
goto op1_def;
102+
}
103+
goto op1_use;
104+
case ZEND_YIELD:
105+
if ((build_flags & ZEND_SSA_RC_INFERENCE)
106+
|| (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
107+
goto op1_def;
108+
}
109+
goto op1_use;
92110
case ZEND_ASSIGN:
93111
case ZEND_ASSIGN_REF:
94112
case ZEND_BIND_GLOBAL:
95113
case ZEND_BIND_STATIC:
96114
case ZEND_SEND_VAR_EX:
97115
case ZEND_SEND_REF:
98116
case ZEND_SEND_VAR_NO_REF:
99-
case ZEND_FE_RESET_R:
100117
case ZEND_FE_RESET_RW:
101-
case ZEND_ADD_ARRAY_ELEMENT:
102-
case ZEND_INIT_ARRAY:
103-
case ZEND_YIELD:
118+
op1_def:
104119
if (!DFG_ISSET(use, set_size, j, EX_VAR_TO_NUM(opline->op1.var))) {
105120
// FIXME: include into "use" to ...?
106121
DFG_SET(use, set_size, j, EX_VAR_TO_NUM(opline->op1.var));
@@ -141,6 +156,7 @@ int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg
141156
case ZEND_FETCH_OBJ_UNSET:
142157
DFG_SET(gen, set_size, j, EX_VAR_TO_NUM(opline->op1.var));
143158
default:
159+
op1_use:
144160
if (!DFG_ISSET(def, set_size, j, EX_VAR_TO_NUM(opline->op1.var))) {
145161
DFG_SET(use, set_size, j, EX_VAR_TO_NUM(opline->op1.var));
146162
}
@@ -154,10 +170,19 @@ int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg
154170
if (opline->op2_type == IS_CV) {
155171
switch (opline->opcode) {
156172
case ZEND_ASSIGN:
173+
if (build_flags & ZEND_SSA_RC_INFERENCE) {
174+
goto op2_def;
175+
}
176+
goto op2_use;
177+
case ZEND_BIND_LEXICAL:
178+
if ((build_flags & ZEND_SSA_RC_INFERENCE) || opline->extended_value) {
179+
goto op2_def;
180+
}
181+
goto op2_use;
157182
case ZEND_ASSIGN_REF:
158183
case ZEND_FE_FETCH_R:
159184
case ZEND_FE_FETCH_RW:
160-
case ZEND_BIND_LEXICAL:
185+
op2_def:
161186
if (!DFG_ISSET(use, set_size, j, EX_VAR_TO_NUM(opline->op2.var))) {
162187
// FIXME: include into "use" to ...?
163188
DFG_SET(use, set_size, j, EX_VAR_TO_NUM(opline->op2.var));
@@ -166,6 +191,7 @@ int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg
166191
DFG_SET(gen, set_size, j, EX_VAR_TO_NUM(opline->op2.var));
167192
break;
168193
default:
194+
op2_use:
169195
if (!DFG_ISSET(def, set_size, j, EX_VAR_TO_NUM(opline->op2.var))) {
170196
DFG_SET(use, set_size, j, EX_VAR_TO_NUM(opline->op2.var));
171197
}

ext/opcache/Optimizer/zend_dfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef struct _zend_dfg {
4444

4545
BEGIN_EXTERN_C()
4646

47-
int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg *dfg);
47+
int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg *dfg, uint32_t build_flags);
4848

4949
END_EXTERN_C()
5050

ext/opcache/Optimizer/zend_ssa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ int zend_build_ssa(zend_arena **arena, const zend_op_array *op_array, uint32_t b
532532
dfg.in = dfg.use + set_size * blocks_count;
533533
dfg.out = dfg.in + set_size * blocks_count;
534534

535-
if (zend_build_dfg(op_array, &ssa->cfg, &dfg) != SUCCESS) {
535+
if (zend_build_dfg(op_array, &ssa->cfg, &dfg, build_flags) != SUCCESS) {
536536
free_alloca(dfg.tmp, dfg_use_heap);
537537
return FAILURE;
538538
}

0 commit comments

Comments
 (0)