[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Ilia Alshanetsky | Date: | Sun, 20 Sep 2026 13:59:36 +0000 |
| Subject: | [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141310@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-09-20T09:53:26-04:00
Commit: https://github.com/php/php-src/commit/80444c531b7ed219b86bd3e225567a75730ff016
Raw diff: https://github.com/php/php-src/commit/80444c531b7ed219b86bd3e225567a75730ff016.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
Fix GH-23693: JIT guard branches on stale flags across basic blocks
Changed paths:
A ext/opcache/tests/jit/gh23693.phpt
M NEWS
M ext/opcache/jit/ir/ir_x86.dasc
Diff:
diff --git a/NEWS b/NEWS
index 41e9dd506996..1c937b7cb017 100644
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,8 @@ PHP NEWS
- Opcache:
. Fixed OSS-Fuzz #546798343 (Heap-buffer-overflow in optimizer with
FCCs and inlining). (ndossche)
+ . Fixed bug GH-23693 (Tracing JIT produces wrong results for a guard on a
+ loop-invariant addition). (Ilia Alshanetsky)
- PDO:
. Fixed PDOStatement::getColumnMeta() reading out of bounds for an invalid
diff --git a/ext/opcache/jit/ir/ir_x86.dasc b/ext/opcache/jit/ir/ir_x86.dasc
index ca42001a8816..f5efb66698da 100644
--- a/ext/opcache/jit/ir/ir_x86.dasc
+++ b/ext/opcache/jit/ir/ir_x86.dasc
@@ -1923,6 +1923,21 @@ static bool ir_match_has_mem_deps(ir_ctx *ctx, ir_ref ref, ir_ref root)
return 0;
}
+/* A naive check if anything that emits code, and so clobbers the flags, is
+ * scheduled between the flags setting instruction and the fusion root */
+static bool ir_match_has_flags_deps(ir_ctx *ctx, ir_ref ref, ir_ref root)
+{
+ ir_ref pos = ctx->prev_ref[root];
+
+ while (pos > ref) {
+ if (ctx->ir_base[pos].op != IR_SNAPSHOT) {
+ return 1;
+ }
+ pos = ctx->prev_ref[pos];
+ }
+ return pos != ref;
+}
+
static void ir_match_fuse_load(ir_ctx *ctx, ir_ref ref, ir_ref root)
{
if (ir_in_same_block(ctx, ref) &&
@@ -3089,7 +3104,9 @@ store_int:
if (IR_IS_CONST_REF(op2_insn->op2)
&& !IR_IS_SYM_CONST(ctx->ir_base[op2_insn->op2].op)
&& ctx->ir_base[op2_insn->op2].val.i64 == 0) {
- if (op2_insn->op1 == insn->op2 - 1) { /* previous instruction */
+ if (op2_insn->op1 == insn->op2 - 1 /* previous instruction */
+ && ir_in_same_block(ctx, op2_insn->op1)
+ && !ir_match_has_flags_deps(ctx, insn->op2, ref)) {
ir_insn *op1_insn = &ctx->ir_base[op2_insn->op1];
if ((op1_insn->op == IR_OR || op1_insn->op == IR_AND || op1_insn->op == IR_XOR) ||
diff --git a/ext/opcache/tests/jit/gh23693.phpt b/ext/opcache/tests/jit/gh23693.phpt
new file mode 100644
index 000000000000..1540f0c1368f
--- /dev/null
+++ b/ext/opcache/tests/jit/gh23693.phpt
@@ -0,0 +1,41 @@
+--TEST--
+GH-23693: Tracing JIT reads stale flags for a guard on a hoisted addition
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.jit_buffer_size=64M
+opcache.jit=tracing
+opcache.jit_hot_func=1
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+function f(int $pos, int $n): int {
+ if ($pos < 0) {
+ return -1;
+ }
+ $y = $pos >> 2;
+ $s = 0;
+ for ($dy = -1; $dy <= 1; ++$dy) {
+ for ($i = 0; $i < $n; ++$i) {
+ $ny = $y + $dy;
+ if ($ny < 0) {
+ continue;
+ }
+ if ($ny >= 4) {
+ continue;
+ }
+ $s += ($ny << 2) | ($i & 3);
+ }
+ }
+ return $s;
+}
+for ($k = 0; $k < 30; ++$k) {
+ f(16, 200);
+}
+var_dump(f(16, 200));
+var_dump(f(0, 200));
+?>
+--EXPECT--
+int(2700)
+int(1400)