Skip to content

Commit 52ab97c

Browse files
committed
Fix GH-22115: Tracing JIT drops loop-PHI CV register from SNAPSHOT
1 parent b0ef5fc commit 52ab97c

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

ext/opcache/jit/zend_jit_trace.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,10 +3215,16 @@ static zend_jit_reg_var* zend_jit_trace_allocate_registers(zend_jit_trace_rec *t
32153215
zend_ssa_phi *phi = ssa->blocks[1].phis;
32163216

32173217
while (phi) {
3218-
i = phi->sources[1];
3219-
if (RA_HAS_IVAL(i) && !ssa->vars[phi->ssa_var].no_val) {
3220-
RA_IVAL_END(i, idx);
3221-
RA_IVAL_FLAGS(i) &= ~ZREG_LAST_USE;
3218+
if (RA_HAS_IVAL(phi->sources[1]) && !ssa->vars[phi->ssa_var].no_val) {
3219+
int cv = ssa->vars[phi->ssa_var].var;
3220+
int k;
3221+
3222+
/* All SSA versions of a loop-carried CV share the same register */
3223+
for (k = 0; k < ssa->vars_count; k++) {
3224+
if (ssa->vars[k].var == cv && RA_HAS_IVAL(k)) {
3225+
RA_IVAL_FLAGS(k) &= ~ZREG_LAST_USE;
3226+
}
3227+
}
32223228
}
32233229
phi = phi->next;
32243230
}

ext/opcache/tests/jit/gh22115.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-22115: Tracing JIT drops loop-PHI CV register from SNAPSHOT after intermediate op1_def
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.file_update_protection=0
9+
opcache.jit_buffer_size=32M
10+
opcache.jit=tracing
11+
--FILE--
12+
<?php
13+
function f(array $meta, int $n): int {
14+
$s = 0;
15+
$i = 0;
16+
$sink = 0;
17+
while ($i < $n) {
18+
$copy = $s;
19+
$sink += $copy;
20+
$m = (int) $meta[$s];
21+
if (($m & 0xFF) === 1) {
22+
$i++;
23+
$s = ($m >> 16) & 0xFFFF;
24+
continue;
25+
}
26+
return $s;
27+
}
28+
return $s;
29+
}
30+
$meta = [0 => 1 | (1 << 16), 1 => 2 | (2 << 16)];
31+
for ($w = 0; $w < 2000; $w++) f($meta, 3);
32+
var_dump(f($meta, 3));
33+
?>
34+
--EXPECT--
35+
int(1)

0 commit comments

Comments
 (0)