[php-src] PR #25085: opcache: preserve loop-carried cv values across trace guards
| From: | aasul | Date: | Sat, 31 Oct 2026 13:49:15 +0000 |
| Subject: | [php-src] PR #25085: opcache: preserve loop-carried cv values across trace guards | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40135@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25085
Author: aasul
this fixes the remaining stale
$x issue from the first follow-up in GH-24683.
the tracing jit can move a cv-bound copy for a transient assignment before the loop guards. if that
copy spills into the cv's vm slot, it overwrites the incoming value before the assignment
should actually run. a side exit can then resume with the wrong value.
the change makes zend_jit_var_supports_reg() reject register allocation for this
specific kind of assignment when the previous value is still live and comes from a loop-header phi.
the arithmetic can still be optimized, but the assignment itself uses an explicit store that stays
after the relevant guards.
i added two phpt tests: one with the original B reproducer and another smaller loop-entry case that
fails naturally on x86_64.
on my linux x86_64 builds, the smaller case goes from 501 wrong results to 0, and a varied-input
test goes from 2335 wrong to 0. the relevant traces still compile and execute.
i also ran five complete jit test configurations across php 8.4 and 8.5, with 2531 passes, 50 skips
and no failures.
on the current php-8.4 submission branch, a fresh debug build passed the complete jit directory with
513 passes, 11 skips and no failures. both B phpts also passed separately, and the original, smaller
loop and varied-input runs returned 0 wrong with tracing active.
@ChrisOrlando [independently tested the
patch](https://github.com/php/php-src/issues/24683#issuecomment-6472781501) on an apple m1 using
native arm64 builds of php 8.5.12. the original B reproducer went from 252 wrong results to 0, with
the same relevant traces compiling before and after. both new phpt tests passed on the patched
builds.
there's still one initial trace compilation abort in the original reproducer on my x86_64 setup
due to the existing fixed spill-frame limit. the relevant case-2 trace compiles afterward. the
reporter also observed the initial abort with and without the patch on arm64.
this is separate from the A+C changes in #24762. B-only fixes the original B case but doesn't
replace the CSE correction, and the larger workload tested by the reporter still needs A+C.
refs GH-24683.