Skip to content

Commit 50c972c

Browse files
committed
Cleanup and fixes
1 parent 27bb786 commit 50c972c

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

Zend/Optimizer/dfa_pass.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,11 +1067,10 @@ static bool zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ss
10671067
}
10681068

10691069
/* Sets a flag on SEND ops when a copy can be a avoided. */
1070-
static void zend_dfa_optimize_send_copies(zend_op_array *op_array, zend_ssa *ssa)
1070+
static void zend_dfa_optimize_send_copies(zend_op_array *op_array, zend_ssa *ssa, zend_call_info **call_map)
10711071
{
10721072
for (int v = 0; v < ssa->vars_count; v++) {
1073-
int var = ssa->vars[v].var;
1074-
if (var >= op_array->last_var) {
1073+
if (ssa->vars[v].var >= op_array->last_var) {
10751074
continue;
10761075
}
10771076

@@ -1080,33 +1079,21 @@ static void zend_dfa_optimize_send_copies(zend_op_array *op_array, zend_ssa *ssa
10801079
continue;
10811080
}
10821081

1083-
#if 0
1084-
fprintf(stderr, "cv %d: ", v);
1085-
zend_dump_var(op_array, IS_CV, v);
1086-
fprintf(stderr, "\n");
1087-
fprintf(stderr, "type %x\n", type);
1088-
#endif
1089-
10901082
int use = ssa->vars[v].use_chain;
10911083
if (use >= 0
10921084
&& op_array->opcodes[use].opcode == ZEND_SEND_VAR
10931085
&& op_array->opcodes[use].op2_type == IS_UNUSED) {
10941086
int next_use = zend_ssa_next_use(ssa->ops, v, use);
1095-
#if 0
1096-
if (next_use >= 0 && op_array->opcodes[next_use].opcode == ZEND_ASSIGN) {
1097-
fprintf(stderr, "v=%d next_use %d (%d, %d, %d, %d)\n", v, next_use, ssa->ops[next_use].result_def, ssa->ops[next_use].result_use, ssa->ops[next_use].op1_use, ssa->ops[next_use].op2_use);
1098-
fprintf(stderr, "next_use var: %d (var=%d)\n", ssa->vars[next_use].var, var);
1099-
fprintf(stderr, "OP1: %d (var=%d)\n", ssa->vars[ssa->ops[next_use].op1_def].var, var);
1100-
}
1101-
#endif
1102-
/* The next use must be an assignment, and there should be no uses after that.
1087+
1088+
/* The next use must be an assignment of the call result, and there should be no other uses.
11031089
* If there is no next use or the next use is not an assignment, then we cannot safely
1104-
* perform the operation without a copy because the nullified value would be observable indirectly
1090+
* perform the operation without a copy because the undef value would be observable indirectly
11051091
* through compact(), func_get_args(), ... */
11061092
if (next_use >= 0
11071093
&& op_array->opcodes[next_use].opcode == ZEND_ASSIGN
11081094
&& ssa->ops[next_use].op1_use == v
1109-
&& ssa->vars[v].var == var
1095+
&& ssa->ops[next_use].op2_use >= 0
1096+
&& ssa->ops[call_map[use]->caller_call_opline - op_array->opcodes].result_def == ssa->ops[next_use].op2_use
11101097
&& zend_ssa_next_use(ssa->ops, v, next_use) < 0) {
11111098
ZEND_ASSERT(op_array->opcodes[use].extended_value == 0);
11121099
op_array->opcodes[use].extended_value = 1;
@@ -1175,7 +1162,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
11751162

11761163
/* Optimization should not be done on main because of globals */
11771164
if (op_array->function_name) {
1178-
zend_dfa_optimize_send_copies(op_array, ssa);
1165+
zend_dfa_optimize_send_copies(op_array, ssa, call_map);
11791166
}
11801167

11811168
for (v = op_array->last_var; v < ssa->vars_count; v++) {

Zend/zend_vm_def.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9926,8 +9926,7 @@ ZEND_VM_HOT_TYPE_SPEC_HANDLER(ZEND_SEND_VAR, op->op2_type == IS_UNUSED && op->ex
99269926
arg = ZEND_CALL_VAR(EX(call), opline->result.var);
99279927

99289928
ZVAL_COPY_VALUE(arg, varptr);
9929-
ZVAL_NULL(varptr);//TODO: what if this is uninit?
9930-
//fprintf(stderr, "Hello world, %d\n", Z_REFCOUNTED_P(arg));
9929+
ZVAL_UNDEF(varptr);
99319930

99329931
ZEND_VM_NEXT_OPCODE();
99339932
}

Zend/zend_vm_execute.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)