[php-src] PHP-8.5: IR: Backport fix for incorrect operand copy in AND/OR/MIN/MAX folding
| From: | ndossche | Date: | Sun, 08 Nov 2026 10:32:55 +0000 |
| Subject: | [php-src] PHP-8.5: IR: Backport fix for incorrect operand copy in AND/OR/MIN/MAX folding | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143420@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-11-08T11:26:49+01:00
Commit: https://github.com/php/php-src/commit/43b1015f7569b26f504240709b137616df35684e
Raw diff: https://github.com/php/php-src/commit/43b1015f7569b26f504240709b137616df35684e.diff
IR: Backport fix for incorrect operand copy in AND/OR/MIN/MAX folding
The shared IR_FOLD(AND(AND, _)) / OR / MIN / MAX rule folded
(a op b) op a to a instead of a op b, e.g.
$b | ($b | 7) evaluated to
$b under the function JIT.
Cherry-picks https://github.com/dstogov/ir/commit/62214815bc0fd9bc29d5e628178a5281baaec592
Changed paths:
A ext/opcache/tests/jit/bw_and_or_fold.phpt
M ext/opcache/jit/ir/ir_fold.h
Diff:
diff --git a/ext/opcache/jit/ir/ir_fold.h b/ext/opcache/jit/ir/ir_fold.h
index cbe049be932c..a50b2ebdc0c0 100644
--- a/ext/opcache/jit/ir/ir_fold.h
+++ b/ext/opcache/jit/ir/ir_fold.h
@@ -3333,7 +3333,7 @@ IR_FOLD(MIN(MIN, _))
IR_FOLD(MAX(MAX, _))
{
if (op1_insn->op1 == op2 || op1_insn->op2 == op2) {
- IR_FOLD_COPY(op2);
+ IR_FOLD_COPY(op1);
}
IR_FOLD_NEXT;
}
diff --git a/ext/opcache/tests/jit/bw_and_or_fold.phpt b/ext/opcache/tests/jit/bw_and_or_fold.phpt
new file mode 100644
index 000000000000..654da1a0a5ee
--- /dev/null
+++ b/ext/opcache/tests/jit/bw_and_or_fold.phpt
@@ -0,0 +1,24 @@
+--TEST--
+JIT: IR folding of (a op b) op a for BW_AND and BW_OR
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit_buffer_size=64M
+opcache.jit=function
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+function or1(int $b) { return $b | ($b | 7); }
+function or2(int $b) { return ($b | 7) | $b; }
+function and1(int $b) { return $b & ($b & 7); }
+function and2(int $b) { return ($b & 7) & $b; }
+
+var_dump(or1(2), or2(2), and1(10), and2(10));
+?>
+--EXPECT--
+int(7)
+int(7)
+int(2)
+int(2)