The following complements the existing (xor (and A B) B) to (and (not A) B)
transform. I've seen this candidate when analyzing PR127606.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
OK?
Thanks,
Richard.
* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
Also simplify (xor (ior A B) B) to (and (not B) A).
---
gcc/simplify-rtx.cc | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 38c8abfe3e7..e74f241c7cd 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
--
2.51.0