Commit 43b1015f756 for php

commit 43b1015f7569b26f504240709b137616df35684e
Author: ndossche <7771979+ndossche@users.noreply.github.com>
Date:   Wed Nov 4 21:41:27 2026 +0100

    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

diff --git a/ext/opcache/jit/ir/ir_fold.h b/ext/opcache/jit/ir/ir_fold.h
index cbe049be932..a50b2ebdc0c 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 00000000000..654da1a0a5e
--- /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)