Skip to content

Commit f1f5c41

Browse files
moved opcode fixing to dce
1 parent 2ae379b commit f1f5c41

File tree

3 files changed

+5
-50
lines changed

3 files changed

+5
-50
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -431,53 +431,6 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
431431
case ZEND_CASE:
432432
case ZEND_CASE_STRICT:
433433
case ZEND_COPY_TMP:
434-
/* Check for printf optimization from `zend_compile_func_printf()`
435-
* where the result of `printf()` is actually unused and remove the
436-
* superflous COPY_TMP, STRLEN and FREE opcodes:
437-
* T1 = COPY_TMP T0
438-
* ECHO T0
439-
* T2 = STRLEN T1
440-
* FREE T2
441-
*/
442-
if (opline->op1_type == IS_TMP_VAR &&
443-
opline + 1 < end && (opline + 1)->opcode == ZEND_ECHO &&
444-
opline + 2 < end && (opline + 2)->opcode == ZEND_STRLEN &&
445-
opline + 3 < end && (opline + 3)->opcode == ZEND_FREE) {
446-
447-
zend_op *echo_op = opline + 1;
448-
zend_op *strlen_op = opline + 2;
449-
zend_op *free_op = opline + 3;
450-
451-
/* Verify the pattern:
452-
* - ECHO uses the same source as COPY_TMP
453-
* - STRLEN uses the result of COPY_TMP
454-
* - FREE uses the result of STRLEN
455-
*/
456-
if (echo_op->op1_type == IS_TMP_VAR &&
457-
echo_op->op1.var == opline->op1.var &&
458-
strlen_op->op1_type == IS_TMP_VAR &&
459-
strlen_op->op1.var == opline->result.var &&
460-
free_op->op1_type == IS_TMP_VAR &&
461-
free_op->op1.var == strlen_op->result.var) {
462-
463-
/* Remove COPY_TMP, STRLEN, and FREE */
464-
MAKE_NOP(opline);
465-
MAKE_NOP(strlen_op);
466-
MAKE_NOP(free_op);
467-
468-
/* Update source tracking */
469-
if (opline->result_type == IS_TMP_VAR) {
470-
VAR_SOURCE(opline->result) = NULL;
471-
}
472-
if (strlen_op->result_type == IS_TMP_VAR) {
473-
VAR_SOURCE(strlen_op->result) = NULL;
474-
}
475-
476-
++(*opt_count);
477-
break;
478-
}
479-
}
480-
481434
if (opline->op1_type & (IS_TMP_VAR|IS_VAR)) {
482435
/* Variable will be deleted later by FREE, so we can't optimize it */
483436
Tsource[VAR_NUM(opline->op1.var)] = NULL;

Zend/Optimizer/dce.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ static inline bool may_have_side_effects(
124124
case ZEND_FUNC_NUM_ARGS:
125125
case ZEND_FUNC_GET_ARGS:
126126
case ZEND_ARRAY_KEY_EXISTS:
127+
case ZEND_COPY_TMP:
127128
/* No side effects */
128129
return 0;
129130
case ZEND_FREE:
@@ -425,10 +426,12 @@ static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
425426
return 0;
426427
}
427428

428-
if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))&& !is_var_dead(ctx, ssa_op->op1_use)) {
429+
if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) && !is_var_dead(ctx, ssa_op->op1_use)) {
429430
if (!try_remove_var_def(ctx, ssa_op->op1_use, ssa_op->op1_use_chain, opline)) {
430431
if (may_be_refcounted(ssa->var_info[ssa_op->op1_use].type)
431-
&& opline->opcode != ZEND_CASE && opline->opcode != ZEND_CASE_STRICT) {
432+
&& opline->opcode != ZEND_CASE
433+
&& opline->opcode != ZEND_CASE_STRICT
434+
&& opline->opcode != ZEND_COPY_TMP) {
432435
free_var = ssa_op->op1_use;
433436
free_var_type = opline->op1_type;
434437
}

Zend/Optimizer/pass1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "zend_constants.h"
3434
#include "zend_execute.h"
3535
#include "zend_vm.h"
36-
#include "zend_vm_opcodes.h"
3736

3837
#define TO_STRING_NOWARN(val) do { \
3938
if (Z_TYPE_P(val) < IS_ARRAY) { \

0 commit comments

Comments
 (0)