Skip to content

Commit 6aece7b

Browse files
committed
Optimize VERIFY_RETURN_TYPE for TMP operands as well
Only exclude CONST operands, which use a different instruction format (they have a return operand).
1 parent f07565b commit 6aece7b

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,34 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
11201120
&& !(OP2_INFO() & MAY_BE_OBJECT)) {
11211121
opline->opcode = ZEND_FAST_CONCAT;
11221122
}
1123+
} else if (opline->opcode == ZEND_VERIFY_RETURN_TYPE
1124+
&& opline->op1_type != IS_CONST
1125+
&& ssa->ops[op_1].op1_def == v
1126+
&& ssa->ops[op_1].op1_use >= 0
1127+
&& ssa->ops[op_1].op1_use_chain == -1
1128+
&& ssa->vars[v].use_chain >= 0
1129+
&& can_elide_return_type_check(op_array, ssa, &ssa->ops[op_1])) {
1130+
1131+
// op_1: VERIFY_RETURN_TYPE #orig_var.? [T] -> #v.? [T] => NOP
1132+
1133+
int orig_var = ssa->ops[op_1].op1_use;
1134+
if (zend_ssa_unlink_use_chain(ssa, op_1, orig_var)) {
1135+
1136+
int ret = ssa->vars[v].use_chain;
1137+
1138+
ssa->ops[ret].op1_use = orig_var;
1139+
ssa->ops[ret].op1_use_chain = ssa->vars[orig_var].use_chain;
1140+
ssa->vars[orig_var].use_chain = ret;
1141+
1142+
ssa->vars[v].definition = -1;
1143+
ssa->vars[v].use_chain = -1;
1144+
1145+
ssa->ops[op_1].op1_def = -1;
1146+
ssa->ops[op_1].op1_use = -1;
1147+
1148+
MAKE_NOP(opline);
1149+
remove_nops = 1;
1150+
}
11231151
}
11241152
}
11251153

@@ -1242,34 +1270,6 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
12421270
opline->extended_value = 0;
12431271
SET_UNUSED(opline->op2);
12441272

1245-
} else if (opline->opcode == ZEND_VERIFY_RETURN_TYPE
1246-
&& ssa->ops[op_1].op1_def == v
1247-
&& ssa->ops[op_1].op1_use >= 0
1248-
&& ssa->ops[op_1].op1_use_chain == -1
1249-
&& ssa->vars[v].use_chain >= 0
1250-
&& can_elide_return_type_check(op_array, ssa, &ssa->ops[op_1])) {
1251-
1252-
// op_1: VERIFY_RETURN_TYPE #orig_var.CV [T] -> #v.CV [T] => NOP
1253-
1254-
int orig_var = ssa->ops[op_1].op1_use;
1255-
if (zend_ssa_unlink_use_chain(ssa, op_1, orig_var)) {
1256-
1257-
int ret = ssa->vars[v].use_chain;
1258-
1259-
ssa->ops[ret].op1_use = orig_var;
1260-
ssa->ops[ret].op1_use_chain = ssa->vars[orig_var].use_chain;
1261-
ssa->vars[orig_var].use_chain = ret;
1262-
1263-
ssa->vars[v].definition = -1;
1264-
ssa->vars[v].use_chain = -1;
1265-
1266-
ssa->ops[op_1].op1_def = -1;
1267-
ssa->ops[op_1].op1_use = -1;
1268-
1269-
MAKE_NOP(opline);
1270-
remove_nops = 1;
1271-
}
1272-
12731273
} else if (ssa->ops[op_1].op1_def == v
12741274
&& !RETURN_VALUE_USED(opline)
12751275
&& ssa->ops[op_1].op1_use >= 0

0 commit comments

Comments
 (0)