com php-src: Move obvious optimization patterns from pass1 directly to compiler: Zend/zend_compile.c ext/opcache/Optimizer/pass 1.c
ext/opcache/Optimizer/zend_optimizer.c

From: Date: Thu, 03 Oct 2019 11:57:20 +0000
Subject: com php-src: Move obvious optimization patterns from pass1 directly to compiler: Zend/zend_compile.c ext/opcache/Optimizer/pass 1.c
ext/opcache/Optimizer/zend_optimizer.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-108702@lists.php.net to get a copy of this message
Commit: de3c1eb85e4585d4db8307d5c30991ed6973f4d3 Author: Dmitry Stogov <dmitry@zend.com> Thu, 3 Oct 2019 14:57:20 +0300 Parents: a5465728c2f33863e07b04e390f46747cffb5f87 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=de3c1eb85e4585d4db8307d5c30991ed6973f4d3 Log: Move obvious optimization patterns from pass1 directly to compiler Changed paths: M Zend/zend_compile.c M ext/opcache/Optimizer/pass1.c M ext/opcache/Optimizer/zend_optimizer.c Diff: diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 6990ad9dc7a..4911cdc5801 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -671,8 +671,21 @@ void zend_do_free(znode *op1) /* {{{ */ } if (opline->result_type == IS_TMP_VAR && opline->result.var == op1->u.op.var) { - if (opline->opcode == ZEND_BOOL || opline->opcode == ZEND_BOOL_NOT) { - return; + switch (opline->opcode) { + case ZEND_BOOL: + case ZEND_BOOL_NOT: + /* boolean resuls don't have to be freed */ + return; + case ZEND_POST_INC_STATIC_PROP: + case ZEND_POST_DEC_STATIC_PROP: + case ZEND_POST_INC_OBJ: + case ZEND_POST_DEC_OBJ: + case ZEND_POST_INC: + case ZEND_POST_DEC: + /* convert $i++ to ++$i */ + opline->opcode -= 2; + opline->result_type = IS_UNUSED; + return; } } @@ -3268,8 +3281,12 @@ int zend_compile_func_cast(znode *result, zend_ast_list *args, uint32_t type) /* } zend_compile_expr(&arg_node, args->child[0]); - opline = zend_emit_op_tmp(result, ZEND_CAST, &arg_node, NULL); - opline->extended_value = type; + if (type == _IS_BOOL) { + opline = zend_emit_op_tmp(result, ZEND_BOOL, &arg_node, NULL); + } else { + opline = zend_emit_op_tmp(result, ZEND_CAST, &arg_node, NULL); + opline->extended_value = type; + } return SUCCESS; } /* }}} */ @@ -7295,11 +7312,13 @@ void zend_compile_cast(znode *result, zend_ast *ast) /* {{{ */ zend_compile_expr(&expr_node, expr_ast); - opline = zend_emit_op_tmp(result, ZEND_CAST, &expr_node, NULL); - opline->extended_value = ast->attr; - - if (ast->attr == IS_NULL) { + if (ast->attr == _IS_BOOL) { + opline = zend_emit_op_tmp(result, ZEND_BOOL, &expr_node, NULL); + } else if (ast->attr == IS_NULL) { zend_error(E_COMPILE_ERROR, "The (unset) cast is no longer supported"); + } else { + opline = zend_emit_op_tmp(result, ZEND_CAST, &expr_node, NULL); + opline->extended_value = ast->attr; } } /* }}} */ diff --git a/ext/opcache/Optimizer/pass1.c b/ext/opcache/Optimizer/pass1.c index 9b21d819aa7..c166fe95e2a 100644 --- a/ext/opcache/Optimizer/pass1.c +++ b/ext/opcache/Optimizer/pass1.c @@ -24,10 +24,8 @@ * - constant casting (ADD expects numbers, CONCAT strings, etc) * - constant expression evaluation * - optimize constant conditional JMPs - * - convert CAST(IS_BOOL,x) into BOOL(x) * - pre-evaluate constant function calls * - eliminate FETCH $GLOBALS followed by FETCH_DIM/UNSET_DIM/ISSET_ISEMPTY_DIM - * - change $i++ to ++$i where possible */ #include "php.h" @@ -249,12 +247,6 @@ constant_binary_op: break; } } - - if (opline->extended_value == _IS_BOOL) { - /* T = CAST(X, IS_BOOL) => T = BOOL(X) */ - opline->opcode = ZEND_BOOL; - opline->extended_value = 0; - } break; case ZEND_BW_NOT: @@ -705,27 +697,6 @@ constant_binary_op: } break; - case ZEND_POST_INC_STATIC_PROP: - case ZEND_POST_DEC_STATIC_PROP: - case ZEND_POST_INC_OBJ: - case ZEND_POST_DEC_OBJ: - case ZEND_POST_INC: - case ZEND_POST_DEC: { - /* POST_INC, FREE => PRE_INC */ - zend_op *next_op = opline + 1; - - if (next_op >= end) { - break; - } - if (next_op->opcode == ZEND_FREE && - next_op->op1.var == opline->result.var) { - MAKE_NOP(next_op); - opline->opcode -= 2; - opline->result_type = IS_UNUSED; - } - } - break; - case ZEND_JMPZ_EX: case ZEND_JMPNZ_EX: /* convert Ti = JMPZ_EX(C, L) => Ti = QM_ASSIGN(C) diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 2c814025b06..1307c5f9c84 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -939,10 +939,8 @@ static void zend_optimize(zend_op_array *op_array, * - constant casting (ADD expects numbers, CONCAT strings, etc) * - constant expression evaluation * - optimize constant conditional JMPs - * - convert CAST(IS_BOOL,x) into BOOL(x) * - pre-evaluate constant function calls * - eliminate FETCH $GLOBALS followed by FETCH_DIM/UNSET_DIM/ISSET_ISEMPTY_DIM - * - change $i++ to ++$i where possible */ if (ZEND_OPTIMIZER_PASS_1 & ctx->optimization_level) { zend_optimizer_pass1(op_array, ctx);

« previous php.cvs (#108702) next »