Hi,
Please find attached the patch "PR23664.patch" that converts the pattern:-
(a & C1) + (b & C2) into (a & C1) | (b & C2) iff (C1 & C2) == 0.
Please review and let me know if its okay.
Regression tested on AARH64 and x86_64.
Thanks,
Naveen
gcc/testsuite/ChangeLog:
2015-07-07 Naveen H.S <naveen.hurugalaw...@caviumnetworks.com>
PR middle-end/23664
* gcc.dg/pr23664.c: New test.
gcc/ChangeLog:
2015-07-07 Naveen H.S <naveen.hurugalaw...@caviumnetworks.com>
PR middle-end/23664
* match.pd ((plus (bit_and @0 INTEGER_CST@1)
(bit_and @2 INTEGER_CST@3)) : New simplifier.
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -529,6 +529,12 @@ along with GCC; see the file COPYING3. If not see
(bitop (bit_and:c @0 @1) (bit_and @2 @1))
(bit_and (bitop @0 @2) @1)))
+/* Simplify (a & C1) + (b & C2) to (a & C1) | (b & C2) iff (C1 & C2) == 0. */
+(simplify
+ (plus (bit_and @0 INTEGER_CST@1) (bit_and @2 INTEGER_CST@3))
+ (if (wi::bit_and (@1, @3) == 0)
+ (bit_ior (bit_and @0 @1) (bit_and @2 @3))))
+
/* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
(simplify
(bit_and (bit_ior @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr23664.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+/* Testcase for PR23664. */
+
+int
+f (int a, int b)
+{
+ return (a & 0xF) + (b & 0xF0);
+}
+
+/* { dg-final { scan-tree-dump "\|" "optimized" } } */