Skip to content

Commit 8882e28

Browse files
committed
Try to properly reconstruct the SSA for in_array()
1 parent 85e0238 commit 8882e28

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -433,23 +433,15 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa)
433433
uint32_t op_num = send_needly - op_array->opcodes;
434434
zend_ssa_op *ssa_op = ssa->ops + op_num;
435435

436-
if (ssa_op->op1_use >= 0) {
437-
/* Reconstruct SSA */
438-
int var_num = ssa_op->op1_use;
439-
zend_ssa_var *var = ssa->vars + var_num;
440-
441-
ZEND_ASSERT(ssa_op->op1_def < 0);
442-
zend_ssa_unlink_use_chain(ssa, op_num, ssa_op->op1_use);
443-
ssa_op->op1_use = -1;
444-
ssa_op->op1_use_chain = -1;
445-
op_num = call_info->caller_call_opline - op_array->opcodes;
446-
ssa_op = ssa->ops + op_num;
447-
ssa_op->op1_use = var_num;
448-
ssa_op->op1_use_chain = var->use_chain;
449-
var->use_chain = op_num;
450-
}
451436
if (zend_hash_num_elements(src) == 0 &&
452437
!(ssa->var_info[ssa_op->op1_use].type & MAY_BE_UNDEF)) {
438+
if (ssa_op->op1_use >= 0) {
439+
/* Reconstruct SSA - the needle is no longer used by any part of the call */
440+
ZEND_ASSERT(ssa_op->op1_def < 0);
441+
zend_ssa_unlink_use_chain(ssa, op_num, ssa_op->op1_use);
442+
ssa_op->op1_use = -1;
443+
ssa_op->op1_use_chain = -1;
444+
}
453445
/* TODO remove needle from the uses of ssa graph? */
454446
ZVAL_FALSE(&tmp);
455447
zend_array_destroy(dst);
@@ -460,6 +452,21 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa)
460452
call_info->caller_call_opline->op1.constant = zend_optimizer_add_literal(op_array, &tmp);
461453
call_info->caller_call_opline->op2_type = IS_UNUSED;
462454
} else {
455+
if (ssa_op->op1_use >= 0) {
456+
/* Reconstruct SSA - the needle is now used by the ZEND_IN_ARRAY opline */
457+
int var_num = ssa_op->op1_use;
458+
zend_ssa_var *var = ssa->vars + var_num;
459+
460+
ZEND_ASSERT(ssa_op->op1_def < 0);
461+
zend_ssa_unlink_use_chain(ssa, op_num, ssa_op->op1_use);
462+
ssa_op->op1_use = -1;
463+
ssa_op->op1_use_chain = -1;
464+
op_num = call_info->caller_call_opline - op_array->opcodes;
465+
ssa_op = ssa->ops + op_num;
466+
ssa_op->op1_use = var_num;
467+
ssa_op->op1_use_chain = var->use_chain;
468+
var->use_chain = op_num;
469+
}
463470
ZVAL_ARR(&tmp, dst);
464471

465472
/* Update opcode */

0 commit comments

Comments
 (0)