Skip to content

opcache: preserve loop-carried cv values across trace guards - #25085

Open
aasul wants to merge 1 commit into
php:PHP-8.4from
aasul:fix/gh24683-b-loop-cv
Open

aasul wants to merge 1 commit into
php:PHP-8.4from
aasul:fix/gh24683-b-loop-cv

Conversation

@aasul

@aasul aasul commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant