com php-src: Fixed escape analysis for ASSIGN_DIM/ASSIGN_OB J opcodes and improved DCE: ext/opcache/Optimizer/d ce.c
ext/opcache/Optimizer/escape_analysis.c ext/opca che/tests/opt/dce_008.phpt
| From: | Dmitry Stogov | Date: | Thu, 14 Sep 2017 08:03:47 +0000 |
| Subject: | com php-src: Fixed escape analysis for ASSIGN_DIM/ASSIGN_OB J opcodes and improved DCE: ext/opcache/Optimizer/d ce.c ext/opcache/Optimizer/escape_analysis.c ext/opca che/tests/opt/dce_008.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99433@lists.php.net to get a copy of this message | ||
Commit: 80abd8134412b2566c12a8439d7a1a2d07e0346f
Author: Dmitry Stogov <dmitry@zend.com> Thu, 14 Sep 2017 11:03:47 +0300
Parents: a68f50f201e2c11c7f2dd1f7395685e33aa26c5d
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=80abd8134412b2566c12a8439d7a1a2d07e0346f
Log:
Fixed escape analysis for ASSIGN_DIM/ASSIGN_OBJ opcodes and improved DCE
Changed paths:
M ext/opcache/Optimizer/dce.c
M ext/opcache/Optimizer/escape_analysis.c
A ext/opcache/tests/opt/dce_008.phpt
Diff:
diff --git a/ext/opcache/Optimizer/dce.c b/ext/opcache/Optimizer/dce.c
index d7e5e91..21d99a8 100644
--- a/ext/opcache/Optimizer/dce.c
+++ b/ext/opcache/Optimizer/dce.c
@@ -222,8 +222,7 @@ static inline zend_bool may_have_side_effects(
opline++;
ssa_op++;
if (opline->op1_type != IS_CONST
- && (OP1_INFO() & MAY_HAVE_DTOR)
- && ssa->vars[ssa_op->op1_use].escape_state != ESCAPE_STATE_NO_ESCAPE) {
+ && (OP1_INFO() & MAY_HAVE_DTOR)) {
/* DCE might shorten lifetime */
return 1;
}
diff --git a/ext/opcache/Optimizer/escape_analysis.c b/ext/opcache/Optimizer/escape_analysis.c
index 2185dd0..357fcd2 100644
--- a/ext/opcache/Optimizer/escape_analysis.c
+++ b/ext/opcache/Optimizer/escape_analysis.c
@@ -284,6 +284,25 @@ static int is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int
va
}
/* reference dependencies processed separately */
break;
+ case ZEND_OP_DATA:
+ if ((opline-1)->opcode != ZEND_ASSIGN_DIM
+ && (opline-1)->opcode != ZEND_ASSIGN_OBJ) {
+ return 1;
+ }
+ if (OP1_INFO() & MAY_BE_OBJECT) {
+ /* object aliasing */
+ return 1;
+ }
+ opline--;
+ op--;
+ if (opline->op1_type != IS_CV
+ || (OP1_INFO() & MAY_BE_REF)
+ || (op->op1_def >= 0 && ssa->vars[op->op1_def]..alias)) {
+ /* asignment into escaping structure */
+ return 1;
+ }
+ /* reference dependencies processed separately */
+ break;
default:
return 1;
}
@@ -291,19 +310,11 @@ static int is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int
va
if (op->op2_use == var) {
switch (opline->opcode) {
- case ZEND_ASSIGN_DIM:
- case ZEND_ASSIGN_OBJ:
- if (OP2_INFO() & MAY_BE_OBJECT) {
- /* object aliasing */
- return 1;
- }
- /* reference dependencies processed separately */
- break;
case ZEND_ASSIGN:
- if (OP1_INFO() & MAY_BE_REF) {
- return 1;
- }
- if (op->op1_def >= 0 && ssa->vars[op->op1_def].alias) {
+ if (opline->op1_type != IS_CV
+ || (OP1_INFO() & MAY_BE_REF)
+ || (op->op1_def >= 0 && ssa->vars[op->op1_def].alias)) {
+ /* asignment into escaping variable */
return 1;
}
if (opline->op2_type == IS_CV || opline->result_type != IS_UNUSED) {
@@ -426,11 +437,12 @@ int zend_ssa_escape_analysis(const zend_script *script, zend_op_array
*op_array,
zend_op *opline = op_array->opcodes + use;
int enclosing_root;
- if ((opline->opcode == ZEND_ASSIGN_DIM ||
- opline->opcode == ZEND_ASSIGN_OBJ) &&
- op->op2_use == i &&
- op->op1_use >= 0) {
- enclosing_root = ees[op->op1_use];
+ if (opline->opcode == ZEND_OP_DATA &&
+ ((opline-1)->opcode == ZEND_ASSIGN_DIM ||
+ (opline-1)->opcode == ZEND_ASSIGN_OBJ) &&
+ op->op1_use == i &&
+ (op-1)->op1_use >= 0) {
+ enclosing_root = ees[(op-1)->op1_use];
} else if ((opline->opcode == ZEND_INIT_ARRAY ||
opline->opcode == ZEND_ADD_ARRAY_ELEMENT) &&
op->op1_use == i &&
diff --git a/ext/opcache/tests/opt/dce_008.phpt b/ext/opcache/tests/opt/dce_008.phpt
new file mode 100644
index 0000000..86c263b
--- /dev/null
+++ b/ext/opcache/tests/opt/dce_008.phpt
@@ -0,0 +1,29 @@
+--TEST--
+DCE 008: Escaping of enclosed arrays doesn't prevent removal of enclosing array
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.opt_debug_level=0x20000
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function esc(int $x) {
+ $a[0] = $x;
+ $b[0] = $a;
+ return $a;
+}
+--EXPECTF--
+$_main: ; (lines=1, args=0, vars=0, tmps=0)
+ ; (after optimizer)
+ ; %sdce_008.php:1-7
+L0: RETURN int(1)
+
+esc: ; (lines=4, args=1, vars=2, tmps=0)
+ ; (after optimizer)
+ ; %sdce_008.php:2-6
+L0: CV0($x) = RECV 1
+L1: ASSIGN_DIM CV1($a) int(0)
+L2: OP_DATA CV0($x)
+L3: RETURN CV1($a)