Skip to content

Improve SSA representation of FE_FETCH #5040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -3285,7 +3285,7 @@ static int zend_update_type_info(const zend_op_array *op_array,
break;
case ZEND_FE_FETCH_R:
case ZEND_FE_FETCH_RW:
tmp = t2;
tmp = t2 & MAY_BE_REF;
if (t1 & MAY_BE_OBJECT) {
if (opline->opcode == ZEND_FE_FETCH_RW) {
tmp |= MAY_BE_REF | MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
Expand Down
8 changes: 8 additions & 0 deletions ext/opcache/Optimizer/zend_ssa.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,10 @@ static int zend_ssa_rename(const zend_op_array *op_array, uint32_t build_flags,
}
}

zend_ssa_op *fe_fetch_ssa_op = blocks[n].len != 0
&& ((end-1)->opcode == ZEND_FE_FETCH_R || (end-1)->opcode == ZEND_FE_FETCH_RW)
&& (end-1)->op2_type == IS_CV
? &ssa_ops[blocks[n].start + blocks[n].len - 1] : NULL;
for (i = 0; i < blocks[n].successors_count; i++) {
int succ = blocks[n].successors[i];
zend_ssa_phi *p;
Expand Down Expand Up @@ -801,6 +805,10 @@ static int zend_ssa_rename(const zend_op_array *op_array, uint32_t build_flags,
}
ZEND_ASSERT(j < blocks[succ].predecessors_count);
p->sources[j] = var[p->var];
if (fe_fetch_ssa_op && i == 0 && p->sources[j] == fe_fetch_ssa_op->op2_def) {
/* On the exit edge of an FE_FETCH, use the pre-modification value instead. */
p->sources[j] = fe_fetch_ssa_op->op2_use;
}
}
}
for (p = ssa_blocks[succ].phis; p && (p->pi >= 0); p = p->next) {
Expand Down
5 changes: 2 additions & 3 deletions ext/opcache/Optimizer/zend_ssa.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,9 @@ static zend_always_inline zend_bool zend_ssa_is_no_val_use(const zend_op *opline
if (opline->opcode == ZEND_ASSIGN || opline->opcode == ZEND_UNSET_CV) {
return ssa_op->op1_use == var && ssa_op->op2_use != var;
}
// TODO: Reenable this after changing the SSA structure.
/*if (opline->opcode == ZEND_FE_FETCH_R) {
if (opline->opcode == ZEND_FE_FETCH_R || opline->opcode == ZEND_FE_FETCH_RW) {
return ssa_op->op2_use == var && ssa_op->op1_use != var;
}*/
}
if (ssa_op->result_use == var
&& opline->opcode != ZEND_ADD_ARRAY_ELEMENT
&& opline->opcode != ZEND_ADD_ARRAY_UNPACK) {
Expand Down