Skip to content

Commit 0f9aefa

Browse files
committed
Fixed incorrect live-range construction
1 parent 23429b5 commit 0f9aefa

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,17 @@ static uint32_t zend_jit_trace_get_exit_point(const zend_op *to_opline, uint32_t
120120
static const void *zend_jit_trace_get_exit_addr(uint32_t n);
121121
static void zend_jit_trace_add_code(const void *start, uint32_t size);
122122

123+
static zend_bool dominates(const zend_basic_block *blocks, int a, int b) {
124+
while (blocks[b].level > blocks[a].level) {
125+
b = blocks[b].idom;
126+
}
127+
return a == b;
128+
}
129+
123130
static zend_bool zend_ssa_is_last_use(const zend_op_array *op_array, const zend_ssa *ssa, int var, int use)
124131
{
132+
int next_use;
133+
125134
if (ssa->vars[var].phi_use_chain) {
126135
zend_ssa_phi *phi = ssa->vars[var].phi_use_chain;
127136
do {
@@ -132,8 +141,24 @@ static zend_bool zend_ssa_is_last_use(const zend_op_array *op_array, const zend_
132141
} while (phi);
133142
}
134143

135-
use = zend_ssa_next_use(ssa->ops, var, use);
136-
return use < 0 || zend_ssa_is_no_val_use(op_array->opcodes + use, ssa->ops + use, var);
144+
next_use = zend_ssa_next_use(ssa->ops, var, use);
145+
if (next_use < 0) {
146+
int b = ssa->cfg.map[use];
147+
int prev_use = ssa->vars[var].use_chain;
148+
149+
while (prev_use >= 0 && prev_use != use) {
150+
if (b != ssa->cfg.map[prev_use]
151+
&& dominates(ssa->cfg.blocks, b, ssa->cfg.map[prev_use])
152+
&& !zend_ssa_is_no_val_use(op_array->opcodes + prev_use, ssa->ops + prev_use, var)) {
153+
return 0;
154+
}
155+
prev_use = zend_ssa_next_use(ssa->ops, var, prev_use);
156+
}
157+
return 1;
158+
} else if (zend_ssa_is_no_val_use(op_array->opcodes + next_use, ssa->ops + next_use, var)) {
159+
return 1;
160+
}
161+
return 0;
137162
}
138163

139164
static zend_bool zend_ival_is_last_use(const zend_lifetime_interval *ival, int use)

0 commit comments

Comments
 (0)