https://gcc.gnu.org/g:ad8e1fbd322b089d0cf0ebac12b1398861926c1e
commit r17-4980-gad8e1fbd322b089d0cf0ebac12b1398861926c1e Author: Richard Biener <[email protected]> Date: Fri Sep 25 14:13:39 2026 +0200 Simplify (xor (ior A B) B) to (and (not B) A)) The following complements the existing (xor (and A B) B) to (and (not A) B) transform. I've seen this candidate when analyzing PR127606. * simplify-rtx.cc (simplify_context::simplify_binary_operation_1): Also simplify (xor (ior A B) B) to (and (not B) A). Diff: --- gcc/simplify-rtx.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index 90c37cff088e..42838cf0cdb5 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -4119,6 +4119,22 @@ simplify_context::simplify_binary_operation_1 (rtx_code code, XEXP (op0, 1), mode), op1); + /* Similarly, convert (xor (ior A B) B) to (and (not B) A). */ + else if (GET_CODE (op0) == IOR + && rtx_equal_p (XEXP (op0, 1), op1) + && ! side_effects_p (op1)) + return simplify_gen_binary (AND, mode, + simplify_gen_unary (NOT, mode, + op1, mode), + XEXP (op0, 0)); + else if (GET_CODE (op0) == IOR + && rtx_equal_p (XEXP (op0, 0), op1) + && ! side_effects_p (op1)) + return simplify_gen_binary (AND, mode, + simplify_gen_unary (NOT, mode, + op1, mode), + XEXP (op0, 1)); + /* Given (xor (ior (xor A B) C) D), where B, C and D are constants, simplify to (xor (ior A C) (B&~C)^D), canceling out bits inverted twice and not set by C. Similarly, given
