Skip to content

Tracing JIT drops loop-PHI CV register from SNAPSHOT after intermediate op1_def #22115

@wilaak

Description

@wilaak

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions