Skip to content

Commit 6a5d600

Browse files
committed
Support VERIFY_RETURN_TYPE elision with unused operand
This handles the degenerate case where SCCP replaced the value in the RETURN opcode with a constant, but the VERIFY_RETURN is still there. We can still apply the same optimization, just don't need to adjust the use list in this case. The result is still sub-optimal in that a dead QM_ASSIGN is left behind.
1 parent 8ed8cf8 commit 6a5d600

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Zend/Optimizer/dfa_pass.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,6 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
12361236
&& ssa->ops[op_1].op1_def == v
12371237
&& ssa->ops[op_1].op1_use >= 0
12381238
&& ssa->ops[op_1].op1_use_chain == -1
1239-
&& ssa->vars[v].use_chain >= 0
12401239
&& can_elide_return_type_check(op_array, ssa, &ssa->ops[op_1])) {
12411240

12421241
// op_1: VERIFY_RETURN_TYPE #orig_var.? [T] -> #v.? [T] => NOP
@@ -1245,10 +1244,11 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
12451244
if (zend_ssa_unlink_use_chain(ssa, op_1, orig_var)) {
12461245

12471246
int ret = ssa->vars[v].use_chain;
1248-
1249-
ssa->ops[ret].op1_use = orig_var;
1250-
ssa->ops[ret].op1_use_chain = ssa->vars[orig_var].use_chain;
1251-
ssa->vars[orig_var].use_chain = ret;
1247+
if (ret >= 0) {
1248+
ssa->ops[ret].op1_use = orig_var;
1249+
ssa->ops[ret].op1_use_chain = ssa->vars[orig_var].use_chain;
1250+
ssa->vars[orig_var].use_chain = ret;
1251+
}
12521252

12531253
ssa->vars[v].definition = -1;
12541254
ssa->vars[v].use_chain = -1;

ext/opcache/tests/opt/verify_return_type.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ class Test2 {
3737
}
3838
}
3939

40+
class Test3 {
41+
private function getBool() {
42+
return true;
43+
}
44+
45+
private function getBool2(): bool {
46+
return $this->getBool();
47+
}
48+
}
49+
4050
?>
4151
--EXPECTF--
4252
$_main:
@@ -91,3 +101,16 @@ Test2::getInt3:
91101
0003 V1 = DO_FCALL
92102
0004 VERIFY_RETURN_TYPE V1
93103
0005 RETURN V1
104+
105+
Test3::getBool:
106+
; (lines=1, args=0, vars=0, tmps=0)
107+
; (after optimizer)
108+
; %s
109+
0000 RETURN bool(true)
110+
111+
Test3::getBool2:
112+
; (lines=2, args=0, vars=0, tmps=1)
113+
; (after optimizer)
114+
; %s
115+
0000 V0 = QM_ASSIGN bool(true)
116+
0001 RETURN bool(true)

0 commit comments

Comments
 (0)