Tracing JIT drops loop-PHI CV register from SNAPSHOT after intermediate op1_def
Open
Nobody has claimed this yet.
Bug
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
Tracing JIT returns wrong values from hot loops!
<?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));
Results in:
$ php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M -d opcache.jit=tracing repro.php
int(0)
Expected:
$ php -d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M -d opcache.jit=function repro.php
int(1)
PHP Version
PHP 8.4 and above
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied repro.php with the tracing and function JIT settings, then compare the resulting values and inspect the loop's snapshot behavior around the intermediate operation and side exit. Done means the tracing JIT returns int(1), matching the function JIT result, without regressing the provided hot-loop case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100