com php-src: Fixed SCCP on PHI(contant_array, partial _array): ext/opcache/Optimizer/sccp.c ext/opcache/t ests/opt/sccp_013.phpt
| From: | Xinchen Hui | Date: | Sat, 02 Sep 2017 10:16:40 +0000 |
| Subject: | com php-src: Fixed SCCP on PHI(contant_array, partial _array): ext/opcache/Optimizer/sccp.c ext/opcache/t ests/opt/sccp_013.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99231@lists.php.net to get a copy of this message | ||
Commit: 8a7ba133c3c4e70a5b4fe8b9e9189cb3c64e71b3
Author: Xinchen Hui <laruence@gmail.com> Sat, 2 Sep 2017 18:16:40 +0800
Parents: a7358c756ab59bb42115d1449292cb1e93eb2b6c
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8a7ba133c3c4e70a5b4fe8b9e9189cb3c64e71b3
Log:
Fixed SCCP on PHI(contant_array, partial_array)
Changed paths:
M ext/opcache/Optimizer/sccp.c
A ext/opcache/tests/opt/sccp_013.phpt
Diff:
diff --git a/ext/opcache/Optimizer/sccp.c b/ext/opcache/Optimizer/sccp.c
index a644a49..8065a72 100644
--- a/ext/opcache/Optimizer/sccp.c
+++ b/ext/opcache/Optimizer/sccp..c
@@ -133,7 +133,7 @@ static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, zval *new) {
if (IS_BOT(new)) {
SCP_DEBUG("Lowering var %d to BOT\n", var);
- } else {
+ } else if (!IS_PARTIAL_ARRAY(new) && !IS_PARTIAL_OBJECT(new)) {
SCP_DEBUG("Lowering var %d to %Z\n", var, new);
}
@@ -144,6 +144,14 @@ static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, zval *new) {
return;
}
+ /* PARTIAL_ARRAY is lower than IS_ARRAY */
+ if (Z_TYPE_P(value) == IS_ARRAY && IS_PARTIAL_ARRAY(new)) {
+ zval_ptr_dtor_nogc(value);
+ ZVAL_COPY(value, new);
+ scdf_add_to_worklist(scdf, var);
+ return;
+ }
+
#if ZEND_DEBUG
ZEND_ASSERT(IS_PARTIAL_ARRAY(new) || IS_PARTIAL_OBJECT(new) || zend_is_identical(value, new));
#endif
@@ -1035,7 +1043,7 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op
*ssa_o
if (!op2 && IS_PARTIAL_ARRAY(&zv)) {
/* We can't add NEXT element into partial array (skip it) */
SET_RESULT(result, data);
- SET_RESULT(result, &zv);
+ SET_RESULT(op1, &zv);
} else if (ct_eval_assign_dim(&zv, data, op2) == SUCCESS) {
SET_RESULT(result, data);
SET_RESULT(op1, &zv);
@@ -2127,7 +2135,7 @@ static int replace_constant_operands(sccp_ctx *ctx) {
if (!Z_DELREF(ctx->values[i])) {
zend_array_destroy(Z_ARR(ctx->values[i]));
}
- Z_TYPE_INFO(ctx->values[i]) = BOT;
+ MAKE_BOT(&ctx->values[i]);
if ((var->use_chain < 0 && var->phi_use_chain == NULL) || var->no_val) {
removed_ops += try_remove_definition(ctx, i, var, NULL);
}
diff --git a/ext/opcache/tests/opt/sccp_013.phpt b/ext/opcache/tests/opt/sccp_013.phpt
new file mode 100644
index 0000000..052e92f
--- /dev/null
+++ b/ext/opcache/tests/opt/sccp_013.phpt
@@ -0,0 +1,21 @@
+--TEST--
+SCCP 013: Conditional Constant Propagation of non-escaping array elements on PHI
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function loadEntities($entity_information) {
+ $entity_types = [];
+ foreach ($entity_information as $info) {
+ $entity_types[$info] = 1;
+ }
+ var_dump((bool)($entity_types[$info]));
+}
+
+loadEntities(array("first", "second"));
+--EXPECT--
+bool(true)