Skip to content

Commit 6c983c6

Browse files
committed
Use ZEND_FUNC_FREE_LOOP_VAR flag to avoid useless iterations.
1 parent 467d8b3 commit 6c983c6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

ext/opcache/Optimizer/scdf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ int scdf_remove_unreachable_blocks(scdf_ctx *scdf) {
213213
int i;
214214
int removed_ops = 0;
215215

216+
if (!(ssa->cfg.flags & ZEND_FUNC_FREE_LOOP_VAR)) {
217+
return 0;
218+
}
216219
for (i = 0; i < ssa->cfg.blocks_count; i++) {
217220
if (!zend_bitset_in(scdf->executable_blocks, i)
218221
&& (ssa->cfg.blocks[i].flags & ZEND_BB_REACHABLE)

ext/opcache/Optimizer/zend_cfg.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *
110110
blocks[start].flags = ZEND_BB_START;
111111
zend_mark_reachable(op_array->opcodes, cfg, blocks + start);
112112

113-
if (op_array->last_live_range || op_array->last_try_catch) {
113+
if (op_array->last_try_catch) {
114114
zend_basic_block *b;
115115
int j, changed;
116116
uint32_t *block_map = cfg->map;
@@ -193,6 +193,12 @@ static void zend_mark_reachable_blocks(const zend_op_array *op_array, zend_cfg *
193193
}
194194
}
195195
} while (changed);
196+
}
197+
198+
if (cfg->flags & ZEND_FUNC_FREE_LOOP_VAR) {
199+
zend_basic_block *b;
200+
int j;
201+
uint32_t *block_map = cfg->map;
196202

197203
/* Mark blocks that are unreachable, but free a loop var created in a reachable block. */
198204
for (b = blocks; b < blocks + cfg->blocks_count; b++) {
@@ -417,6 +423,14 @@ int zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, uint32_t b
417423
case ZEND_EXT_FCALL_END:
418424
flags |= ZEND_FUNC_HAS_EXTENDED_INFO;
419425
break;
426+
case ZEND_FREE:
427+
if (opline->extended_value == ZEND_FREE_SWITCH) {
428+
flags |= ZEND_FUNC_FREE_LOOP_VAR;
429+
}
430+
break;
431+
case ZEND_FE_FREE:
432+
flags |= ZEND_FUNC_FREE_LOOP_VAR;
433+
break;
420434
}
421435
}
422436

ext/opcache/Optimizer/zend_func_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define ZEND_FUNC_VARARG (1<<2) /* uses func_get_args() */
2828
#define ZEND_FUNC_NO_LOOPS (1<<3)
2929
#define ZEND_FUNC_IRREDUCIBLE (1<<4)
30+
#define ZEND_FUNC_FREE_LOOP_VAR (1<<5)
3031
#define ZEND_FUNC_RECURSIVE (1<<7)
3132
#define ZEND_FUNC_RECURSIVE_DIRECTLY (1<<8)
3233
#define ZEND_FUNC_RECURSIVE_INDIRECTLY (1<<9)

0 commit comments

Comments
 (0)