summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2020-03-14 01:17:45 +0300
committerDmitry Stogov <dmitry@zend.com>2020-03-14 01:17:45 +0300
commit29bf7902b3b96cff1e9ee4e6680d92fc264f04e5 (patch)
tree963219b22e01f5ced34a3eae94e28507e01d2136
parent4bf2d09edeb14467ba79551a08d84efdff314899 (diff)
downloadphp-git-29bf7902b3b96cff1e9ee4e6680d92fc264f04e5.tar.gz
Fixed RC inference for ZEND_ASSIGN_STATIC_PROP and removed useless checks during RC inference
-rw-r--r--ext/opcache/Optimizer/zend_dfg.c2
-rw-r--r--ext/opcache/Optimizer/zend_inference.c47
-rw-r--r--ext/opcache/Optimizer/zend_ssa.c2
-rw-r--r--ext/opcache/tests/jit/assign_static_prop_001.phpt28
4 files changed, 55 insertions, 24 deletions
diff --git a/ext/opcache/Optimizer/zend_dfg.c b/ext/opcache/Optimizer/zend_dfg.c
index fda6b4f9a8..25a910ef71 100644
--- a/ext/opcache/Optimizer/zend_dfg.c
+++ b/ext/opcache/Optimizer/zend_dfg.c
@@ -105,11 +105,9 @@ add_op1_def:
if (!zend_bitset_in(def, var_num)) {
zend_bitset_incl(use, var_num);
}
-#if 0
if ((build_flags & ZEND_SSA_RC_INFERENCE) && next->op1_type == IS_CV) {
zend_bitset_incl(def, var_num);
}
-#endif
}
break;
case ZEND_ASSIGN_STATIC_PROP_REF:
diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c
index 2be19fcf8a..495aedfda2 100644
--- a/ext/opcache/Optimizer/zend_inference.c
+++ b/ext/opcache/Optimizer/zend_inference.c
@@ -2409,12 +2409,10 @@ static zend_always_inline int _zend_update_type_info(
if (ssa_op->op1_def >= 0) {
tmp = t1;
if ((t1 & (MAY_BE_ARRAY|MAY_BE_OBJECT)) &&
- (opline->op1_type == IS_CV) &&
(opline->extended_value == IS_ARRAY ||
opline->extended_value == IS_OBJECT)) {
tmp |= MAY_BE_RCN;
} else if ((t1 & MAY_BE_STRING) &&
- (opline->op1_type == IS_CV) &&
opline->extended_value == IS_STRING) {
tmp |= MAY_BE_RCN;
}
@@ -2454,7 +2452,7 @@ static zend_always_inline int _zend_update_type_info(
case ZEND_COPY_TMP:
if (ssa_op->op1_def >= 0) {
tmp = t1;
- if ((t1 & (MAY_BE_RC1|MAY_BE_REF)) && (opline->op1_type == IS_CV)) {
+ if (t1 & (MAY_BE_RC1|MAY_BE_REF)) {
tmp |= MAY_BE_RCN;
}
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
@@ -2729,7 +2727,7 @@ static zend_always_inline int _zend_update_type_info(
}
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
}
- if ((opline+1)->op1_type == IS_CV && (ssa_op+1)->op1_def >= 0) {
+ if ((ssa_op+1)->op1_def >= 0) {
opline++;
ssa_op++;
tmp = OP1_INFO_EX();
@@ -2763,14 +2761,27 @@ static zend_always_inline int _zend_update_type_info(
UPDATE_SSA_OBJ_TYPE(ce, 1, ssa_op->result_def);
}
}
- if ((opline+1)->op1_type == IS_CV) {
+ if ((ssa_op+1)->op1_def >= 0) {
opline++;
ssa_op++;
tmp = OP1_INFO_EX();
- if (tmp & (MAY_BE_ANY | MAY_BE_REF)) {
- if (tmp & MAY_BE_RC1) {
- tmp |= MAY_BE_RCN;
- }
+ if (tmp & MAY_BE_RC1) {
+ tmp |= MAY_BE_RCN;
+ }
+ UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
+ }
+ break;
+ case ZEND_ASSIGN_STATIC_PROP:
+ if (ssa_op->result_def >= 0) {
+ tmp = MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_RC1 | MAY_BE_RCN;
+ UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
+ }
+ if ((ssa_op+1)->op1_def >= 0) {
+ opline++;
+ ssa_op++;
+ tmp = OP1_INFO_EX();
+ if (tmp & MAY_BE_RC1) {
+ tmp |= MAY_BE_RCN;
}
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
}
@@ -2798,12 +2809,10 @@ static zend_always_inline int _zend_update_type_info(
}
break;
case ZEND_ASSIGN:
- if (opline->op2_type == IS_CV && ssa_op->op2_def >= 0) {
+ if (ssa_op->op2_def >= 0) {
tmp = t2;
- if (tmp & (MAY_BE_ANY | MAY_BE_REF)) {
- if (tmp & MAY_BE_RC1) {
- tmp |= MAY_BE_RCN;
- }
+ if (tmp & MAY_BE_RC1) {
+ tmp |= MAY_BE_RCN;
}
UPDATE_SSA_TYPE(tmp, ssa_op->op2_def);
}
@@ -2918,7 +2927,7 @@ static zend_always_inline int _zend_update_type_info(
case ZEND_SEND_VAR:
if (ssa_op->op1_def >= 0) {
tmp = t1;
- if ((t1 & (MAY_BE_RC1|MAY_BE_REF)) && (opline->op1_type == IS_CV)) {
+ if (t1 & (MAY_BE_RC1|MAY_BE_REF)) {
tmp |= MAY_BE_RCN;
}
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
@@ -3102,7 +3111,7 @@ static zend_always_inline int _zend_update_type_info(
break;
case ZEND_INIT_ARRAY:
case ZEND_ADD_ARRAY_ELEMENT:
- if (opline->op1_type == IS_CV && ssa_op->op1_def >= 0) {
+ if (ssa_op->op1_def >= 0) {
if (opline->extended_value & ZEND_ARRAY_ELEMENT_REF) {
tmp = (MAY_BE_REF | t1) & ~(MAY_BE_UNDEF|MAY_BE_RC1|MAY_BE_RCN);
if (t1 & MAY_BE_UNDEF) {
@@ -3190,10 +3199,8 @@ static zend_always_inline int _zend_update_type_info(
tmp = t1;
if (opline->opcode == ZEND_FE_RESET_RW) {
tmp |= MAY_BE_REF;
- } else {
- if ((t1 & MAY_BE_RC1) && opline->op1_type != IS_TMP_VAR) {
- tmp |= MAY_BE_RCN;
- }
+ } else if (t1 & MAY_BE_RC1) {
+ tmp |= MAY_BE_RCN;
}
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);
diff --git a/ext/opcache/Optimizer/zend_ssa.c b/ext/opcache/Optimizer/zend_ssa.c
index 10e772d4ba..63e151c76e 100644
--- a/ext/opcache/Optimizer/zend_ssa.c
+++ b/ext/opcache/Optimizer/zend_ssa.c
@@ -621,14 +621,12 @@ add_op1_def:
if (next->op1_type & (IS_CV|IS_VAR|IS_TMP_VAR)) {
ssa_ops[k + 1].op1_use = var[EX_VAR_TO_NUM(next->op1.var)];
//USE_SSA_VAR(op_array->last_var + next->op1.var);
-#if 0
if ((build_flags & ZEND_SSA_RC_INFERENCE) && next->op1_type == IS_CV) {
ssa_ops[k + 1].op1_def = ssa_vars_count;
var[EX_VAR_TO_NUM(next->op1.var)] = ssa_vars_count;
ssa_vars_count++;
//NEW_SSA_VAR(next->op1.var)
}
-#endif
}
break;
case ZEND_ASSIGN_STATIC_PROP_REF:
diff --git a/ext/opcache/tests/jit/assign_static_prop_001.phpt b/ext/opcache/tests/jit/assign_static_prop_001.phpt
new file mode 100644
index 0000000000..2d90e39a20
--- /dev/null
+++ b/ext/opcache/tests/jit/assign_static_prop_001.phpt
@@ -0,0 +1,28 @@
+--TEST--
+JIT ASSIGN_STATIC_PROP: 001
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit_buffer_size=1M
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+class Foo {
+ public static $prop;
+}
+
+function test($x) {
+ $a = [$x];
+ Foo::$prop = $a;
+ $a = 42;
+}
+test(42);
+var_dump(Foo::$prop);
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ int(42)
+}