Skip to content

Commit d1eb5ed

Browse files
committed
Proper SSA reconstruction for "$a = $a;"
1 parent 4872d13 commit d1eb5ed

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -608,24 +608,28 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
608608

609609
// op_1: ASSIGN #orig_var.CV [undef,scalar] -> #v.CV, CONST|TMPVAR => QM_ASSIGN v.CV, CONST|TMPVAR
610610

611-
if (zend_ssa_unlink_use_chain(ssa, op_1, orig_var)) {
612-
/* Reconstruct SSA */
613-
ssa->ops[op_1].result_def = v;
614-
ssa->ops[op_1].op1_def = -1;
615-
ssa->ops[op_1].op1_use = ssa->ops[op_1].op2_use;
616-
ssa->ops[op_1].op1_use_chain = ssa->ops[op_1].op2_use_chain;
617-
ssa->ops[op_1].op2_use = -1;
618-
ssa->ops[op_1].op2_use_chain = -1;
619-
620-
/* Update opcode */
621-
opline->result_type = opline->op1_type;
622-
opline->result.var = opline->op1.var;
623-
opline->op1_type = opline->op2_type;
624-
opline->op1.var = opline->op2.var;
625-
opline->op2_type = IS_UNUSED;
626-
opline->op2.var = 0;
627-
opline->opcode = ZEND_QM_ASSIGN;
611+
if (ssa->ops[op_1].op1_use != ssa->ops[op_1].op2_use) {
612+
ZEND_ASSERT(zend_ssa_unlink_use_chain(ssa, op_1, orig_var));
613+
} else {
614+
ssa->ops[op_1].op2_use_chain = ssa->ops[op_1].op1_use_chain;
628615
}
616+
617+
/* Reconstruct SSA */
618+
ssa->ops[op_1].result_def = v;
619+
ssa->ops[op_1].op1_def = -1;
620+
ssa->ops[op_1].op1_use = ssa->ops[op_1].op2_use;
621+
ssa->ops[op_1].op1_use_chain = ssa->ops[op_1].op2_use_chain;
622+
ssa->ops[op_1].op2_use = -1;
623+
ssa->ops[op_1].op2_use_chain = -1;
624+
625+
/* Update opcode */
626+
opline->result_type = opline->op1_type;
627+
opline->result.var = opline->op1.var;
628+
opline->op1_type = opline->op2_type;
629+
opline->op1.var = opline->op2.var;
630+
opline->op2_type = IS_UNUSED;
631+
opline->op2.var = 0;
632+
opline->opcode = ZEND_QM_ASSIGN;
629633
}
630634
}
631635

0 commit comments

Comments
 (0)