<?php
function f(array $meta, int $n): int {
$s = 0; $i = 0; $sink = 0;
while ($i < $n) {
$copy = $s; // QM_ASSIGN, op1_def on $s under RC inference
$sink += $copy; // keep ASSIGN past DCE
$m = (int) $meta[$s]; // FETCH_DIM_R use of $s, ZREG_LAST_USE
if (($m & 0xFF) === 1) { // IS_IDENTICAL guard, side-exit's SNAPSHOT misses $s
$i++;
$s = ($m >> 32) & 0xFFFFFF;
continue;
}
return $s;
}
return $s;
}
$meta = [0 => 1 | (1 << 32), 1 => 2 | (2 << 32)];
for ($w = 0; $w < 2000; $w++) f($meta, 3);
var_dump(f($meta, 3));
$ php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M -d opcache.jit=tracing repro.php
int(0)
$ php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M -d opcache.jit=function repro.php
int(1)
Description
Tracing JIT returns wrong values from hot loops!
Results in:
Expected:
PHP Version
PHP 8.4 and above