@@ -241,6 +241,8 @@ static inline zend_bool may_have_side_effects(
241
241
return 1 ;
242
242
}
243
243
return 0 ;
244
+ case ZEND_BIND_STATIC :
245
+ return 0 ;
244
246
default :
245
247
/* For everything we didn't handle, assume a side-effect */
246
248
return 1 ;
@@ -267,19 +269,23 @@ static inline void add_to_phi_worklist_no_val(context *ctx, int var_num) {
267
269
}
268
270
}
269
271
270
- static zend_always_inline void add_operands_to_worklists (context * ctx , zend_op * opline , zend_ssa_op * ssa_op , int check ) {
272
+ static zend_always_inline void add_operands_to_worklists (context * ctx , zend_op * opline , zend_ssa_op * ssa_op , zend_ssa * ssa , int check ) {
271
273
if (ssa_op -> result_use >= 0 ) {
272
274
add_to_worklists (ctx , ssa_op -> result_use , check );
273
275
}
274
276
if (ssa_op -> op1_use >= 0 ) {
275
- if (!zend_ssa_is_no_val_use (opline , ssa_op , ssa_op -> op1_use )) {
277
+ if (!zend_ssa_is_no_val_use (opline , ssa_op , ssa_op -> op1_use )
278
+ || (opline -> opcode == ZEND_ASSIGN
279
+ && (ssa -> var_info [ssa_op -> op1_use ].type & MAY_BE_REF ) != 0 )) {
276
280
add_to_worklists (ctx , ssa_op -> op1_use , check );
277
281
} else {
278
282
add_to_phi_worklist_no_val (ctx , ssa_op -> op1_use );
279
283
}
280
284
}
281
285
if (ssa_op -> op2_use >= 0 ) {
282
- if (!zend_ssa_is_no_val_use (opline , ssa_op , ssa_op -> op2_use )) {
286
+ if (!zend_ssa_is_no_val_use (opline , ssa_op , ssa_op -> op2_use )
287
+ || (opline -> opcode == ZEND_FE_FETCH_R
288
+ && (ssa -> var_info [ssa_op -> op2_use ].type & MAY_BE_REF ) != 0 )) {
283
289
add_to_worklists (ctx , ssa_op -> op2_use , check );
284
290
} else {
285
291
add_to_phi_worklist_no_val (ctx , ssa_op -> op2_use );
@@ -528,9 +534,9 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, zend_bool reor
528
534
529
535
if (zend_bitset_in (ctx .instr_worklist , i )) {
530
536
zend_bitset_excl (ctx .instr_worklist , i );
531
- add_operands_to_worklists (& ctx , & op_array -> opcodes [i ], & ssa -> ops [i ], 0 );
537
+ add_operands_to_worklists (& ctx , & op_array -> opcodes [i ], & ssa -> ops [i ], ssa , 0 );
532
538
if (op_data >= 0 ) {
533
- add_operands_to_worklists (& ctx , & op_array -> opcodes [op_data ], & ssa -> ops [op_data ], 0 );
539
+ add_operands_to_worklists (& ctx , & op_array -> opcodes [op_data ], & ssa -> ops [op_data ], ssa , 0 );
534
540
}
535
541
} else if (may_have_side_effects (op_array , ssa , & op_array -> opcodes [i ], & ssa -> ops [i ], ctx .reorder_dtor_effects )
536
542
|| zend_may_throw (& op_array -> opcodes [i ], op_array , ssa )
@@ -542,9 +548,9 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, zend_bool reor
542
548
zend_bitset_incl (ctx .instr_dead , i );
543
549
zend_bitset_incl (ctx .instr_dead , i + 1 );
544
550
} else {
545
- add_operands_to_worklists (& ctx , & op_array -> opcodes [i ], & ssa -> ops [i ], 0 );
551
+ add_operands_to_worklists (& ctx , & op_array -> opcodes [i ], & ssa -> ops [i ], ssa , 0 );
546
552
if (op_data >= 0 ) {
547
- add_operands_to_worklists (& ctx , & op_array -> opcodes [op_data ], & ssa -> ops [op_data ], 0 );
553
+ add_operands_to_worklists (& ctx , & op_array -> opcodes [op_data ], & ssa -> ops [op_data ], ssa , 0 );
548
554
}
549
555
}
550
556
} else {
@@ -562,10 +568,10 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, zend_bool reor
562
568
|| !zend_bitset_empty (ctx .phi_worklist , ctx .phi_worklist_len )) {
563
569
while ((i = zend_bitset_pop_first (ctx .instr_worklist , ctx .instr_worklist_len )) >= 0 ) {
564
570
zend_bitset_excl (ctx .instr_dead , i );
565
- add_operands_to_worklists (& ctx , & op_array -> opcodes [i ], & ssa -> ops [i ], 1 );
571
+ add_operands_to_worklists (& ctx , & op_array -> opcodes [i ], & ssa -> ops [i ], ssa , 1 );
566
572
if (i < op_array -> last && op_array -> opcodes [i + 1 ].opcode == ZEND_OP_DATA ) {
567
573
zend_bitset_excl (ctx .instr_dead , i + 1 );
568
- add_operands_to_worklists (& ctx , & op_array -> opcodes [i + 1 ], & ssa -> ops [i + 1 ], 1 );
574
+ add_operands_to_worklists (& ctx , & op_array -> opcodes [i + 1 ], & ssa -> ops [i + 1 ], ssa , 1 );
569
575
}
570
576
}
571
577
while ((i = zend_bitset_pop_first (ctx .phi_worklist , ctx .phi_worklist_len )) >= 0 ) {
0 commit comments