Skip to content

Commit 4b64dbb

Browse files
committed
Check if instruction may throw exception only for instructions without known side effects.
Always disable removing ASSIGN and UNSET_VAR that may throw.
1 parent c5aa1f4 commit 4b64dbb

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

ext/opcache/Optimizer/dce.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,9 @@ static inline zend_bool is_bad_mod(const zend_ssa *ssa, int use, int def) {
6969
}
7070

7171
static inline zend_bool may_have_side_effects(
72-
const context *ctx, const zend_op *opline, const zend_ssa_op *ssa_op) {
73-
zend_op_array *op_array = ctx->op_array;
74-
zend_ssa *ssa = ctx->ssa;
75-
if (zend_may_throw(opline, op_array, ssa)) {
76-
return 1;
77-
}
78-
72+
zend_op_array *op_array, zend_ssa *ssa,
73+
const zend_op *opline, const zend_ssa_op *ssa_op,
74+
zend_bool reorder_dtor_effects) {
7975
switch (opline->opcode) {
8076
case ZEND_NOP:
8177
case ZEND_IS_IDENTICAL:
@@ -154,15 +150,10 @@ static inline zend_bool may_have_side_effects(
154150
return 1;
155151
case ZEND_ASSIGN:
156152
{
157-
uint32_t t1 = OP1_INFO();
158153
if (is_bad_mod(ssa, ssa_op->op1_use, ssa_op->op1_def)) {
159154
return 1;
160155
}
161-
if (!ctx->reorder_dtor_effects) {
162-
if (t1 & MAY_HAVE_DTOR) {
163-
/* DCE might extend lifetime */
164-
return 1;
165-
}
156+
if (!reorder_dtor_effects) {
166157
if (opline->op2_type != IS_CONST && (OP2_INFO() & MAY_HAVE_DTOR)) {
167158
/* DCE might shorten lifetime */
168159
return 1;
@@ -183,10 +174,6 @@ static inline zend_bool may_have_side_effects(
183174
* is a reference, because unset breaks references. */
184175
return 1;
185176
}
186-
if (!ctx->reorder_dtor_effects && (t1 & MAY_HAVE_DTOR)) {
187-
/* DCE might extend lifetime */
188-
return 1;
189-
}
190177
return 0;
191178
}
192179
case ZEND_PRE_INC:
@@ -481,7 +468,9 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, zend_bool reor
481468

482469
/* Mark instruction with side effects as live */
483470
FOREACH_INSTR_NUM(i) {
484-
if (may_have_side_effects(&ctx, &op_array->opcodes[i], &ssa->ops[i]) || has_varargs) {
471+
if (may_have_side_effects(op_array, ssa, &op_array->opcodes[i], &ssa->ops[i], ctx.reorder_dtor_effects)
472+
|| zend_may_throw(&op_array->opcodes[i], op_array, ssa)
473+
|| has_varargs) {
485474
zend_bitset_excl(ctx.instr_dead, i);
486475
add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i]);
487476
}

ext/opcache/Optimizer/zend_inference.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4024,6 +4024,7 @@ int zend_may_throw(const zend_op *opline, zend_op_array *op_array, zend_ssa *ssa
40244024
case ZEND_COALESCE:
40254025
case ZEND_SWITCH_LONG:
40264026
case ZEND_SWITCH_STRING:
4027+
case ZEND_ISSET_ISEMPTY_VAR:
40274028
return 0;
40284029
case ZEND_INIT_FCALL:
40294030
/* can't throw, because call is resolved at compile time */
@@ -4157,6 +4158,7 @@ int zend_may_throw(const zend_op *opline, zend_op_array *op_array, zend_ssa *ssa
41574158
return (t1 & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT)) ||
41584159
(t2 & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT));
41594160
case ZEND_ASSIGN:
4161+
case ZEND_UNSET_VAR:
41604162
return (t1 & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY));
41614163
case ZEND_ASSIGN_DIM:
41624164
return (t1 & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_TRUE|MAY_BE_STRING|MAY_BE_LONG|MAY_BE_DOUBLE)) || opline->op2_type == IS_UNUSED ||

0 commit comments

Comments
 (0)