Skip to content

Commit a90ed34

Browse files
committed
Make SCCP to remove dead live ranges.
1 parent 320237f commit a90ed34

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,9 @@ static int replace_constant_operands(sccp_ctx *ctx) {
13311331
call = ctx->call_map[var->definition];
13321332
ZEND_ASSERT(call);
13331333
ZEND_ASSERT(call->caller_call_opline == opline);
1334+
if (opline->result_type & (IS_TMP_VAR|IS_VAR)) {
1335+
zend_optimizer_remove_live_range_ex(op_array, opline->result.var, var->definition + 1);
1336+
}
13341337
zend_ssa_remove_result_def(ssa, ssa_op);
13351338
zend_ssa_remove_instr(ssa, opline, ssa_op);
13361339
zend_ssa_remove_instr(ssa, call->caller_init_opline,
@@ -1346,6 +1349,9 @@ static int replace_constant_operands(sccp_ctx *ctx) {
13461349
call->callee_func = NULL;
13471350
} else {
13481351
/* Ordinary computational instruction -> remove it */
1352+
if (opline->result_type & (IS_TMP_VAR|IS_VAR)) {
1353+
zend_optimizer_remove_live_range_ex(op_array, opline->result.var, var->definition + 1);
1354+
}
13491355
zend_ssa_remove_result_def(ssa, ssa_op);
13501356
zend_ssa_remove_instr(ssa, opline, ssa_op);
13511357
removed_ops++;
@@ -1366,6 +1372,9 @@ static int replace_constant_operands(sccp_ctx *ctx) {
13661372
if (ssa_op->result_def >= 0
13671373
&& ssa->vars[ssa_op->result_def].use_chain < 0
13681374
&& ssa->vars[ssa_op->result_def].phi_use_chain == NULL) {
1375+
if (opline->result_type & (IS_TMP_VAR|IS_VAR)) {
1376+
zend_optimizer_remove_live_range_ex(op_array, opline->result.var, var->definition + 1);
1377+
}
13691378
zend_ssa_remove_result_def(ssa, ssa_op);
13701379
opline->result_type = IS_UNUSED;
13711380
}

ext/opcache/Optimizer/zend_optimizer.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,23 @@ void zend_optimizer_remove_live_range(zend_op_array *op_array, uint32_t var)
551551
}
552552
}
553553

554+
void zend_optimizer_remove_live_range_ex(zend_op_array *op_array, uint32_t var, uint32_t start)
555+
{
556+
uint32_t i = 0;
557+
558+
while (i < op_array->last_live_range) {
559+
if (op_array->live_range[i].var == var
560+
&& op_array->live_range[i].start == start) {
561+
op_array->last_live_range--;
562+
if (i < op_array->last_live_range) {
563+
memmove(&op_array->live_range[i], &op_array->live_range[i+1], (op_array->last_live_range - i) * sizeof(zend_live_range));
564+
}
565+
break;
566+
}
567+
i++;
568+
}
569+
}
570+
554571
int zend_optimizer_replace_by_const(zend_op_array *op_array,
555572
zend_op *opline,
556573
zend_uchar type,

ext/opcache/Optimizer/zend_optimizer_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array,
9292
zval *val);
9393

9494
void zend_optimizer_remove_live_range(zend_op_array *op_array, uint32_t var);
95+
void zend_optimizer_remove_live_range_ex(zend_op_array *op_array, uint32_t var, uint32_t start);
9596
void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx);
9697
void zend_optimizer_pass2(zend_op_array *op_array);
9798
void zend_optimizer_pass3(zend_op_array *op_array);

ext/opcache/Optimizer/zend_ssa.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "zend_ssa.h"
2424
#include "zend_dump.h"
2525
#include "zend_inference.h"
26+
#include "Optimizer/zend_optimizer_internal.h"
2627

2728
static zend_bool dominates(const zend_basic_block *blocks, int a, int b) {
2829
while (blocks[b].level > blocks[a].level) {
@@ -1361,6 +1362,9 @@ void zend_ssa_remove_block(zend_op_array *op_array, zend_ssa *ssa, int i) /* {{{
13611362
continue;
13621363
}
13631364

1365+
if (op_array->opcodes[j].result_type & (IS_TMP_VAR|IS_VAR)) {
1366+
zend_optimizer_remove_live_range_ex(op_array, op_array->opcodes[j].result.var, j + 1);
1367+
}
13641368
zend_ssa_remove_defs_of_instr(ssa, &ssa->ops[j]);
13651369
zend_ssa_remove_instr(ssa, &op_array->opcodes[j], &ssa->ops[j]);
13661370
}

0 commit comments

Comments
 (0)