* match.pd: New simplification patterns.
(x + (x & 1)) -> ((x + 1) & ~1)
(x & ~(x & y)) -> ((x & ~y))
(x | ~(x | y)) -> ((x | ~y))
* gcc.dg/
20150120-1.c: New test.
* gcc.dg/
20150120-2.c: New test.
* gcc.dg/
20150120-3.c: New test.
From-SVN: r222697
+2015-05-01 Rasmus Villemoes <rv@rasmusvillemoes.dk>
+
+ * match.pd: New simplification patterns.
+ (x + (x & 1)) -> ((x + 1) & ~1)
+ (x & ~(x & y)) -> ((x & ~y))
+ (x | ~(x | y)) -> ((x | ~y))
+
2015-05-01 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* target.def (attribute_table): Mention that struct attribute_spec
(bitop @0 @0)
(non_lvalue @0)))
+/* x + (x & 1) -> (x + 1) & ~1 */
+(simplify
+ (plus:c @0 (bit_and@2 @0 integer_onep@1))
+ (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
+ (bit_and (plus @0 @1) (bit_not @1))))
+
+/* x & ~(x & y) -> x & ~y */
+/* x | ~(x | y) -> x | ~y */
+(for bitop (bit_and bit_ior)
+ (simplify
+ (bitop:c @0 (bit_not (bitop:c@2 @0 @1)))
+ (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
+ (bitop @0 (bit_not @1)))))
+
(simplify
(abs (negate @0))
(abs @0))
+2015-05-01 Rasmus Villemoes <rv@rasmusvillemoes.dk>
+
+ * gcc.dg/20150120-1.c: New test.
+ * gcc.dg/20150120-2.c: New test.
+ * gcc.dg/20150120-3.c: New test.
+
2015-05-01 David Edelsohn <dje.gcc@gmail.com>
* gcc.dg/debug/pr65771.c: Add "dg-add-options tls".
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+
+/* x + (x & 1) -> (x + 1) & ~1 */
+int
+fn1 (int x)
+{
+ return x + (x & 1);
+}
+int
+fn2 (int x)
+{
+ return (x & 1) + x;
+}
+int
+fn3 (int x)
+{
+ return x + (1 & x);
+}
+int
+fn4 (int x)
+{
+ return (1 & x) + x;
+}
+unsigned int
+fn5 (unsigned int x)
+{
+ return x + (x & 1);
+}
+unsigned int
+fn6 (unsigned int x)
+{
+ return (x & 1) + x;
+}
+unsigned int
+fn7 (unsigned int x)
+{
+ return x + (x % 2);
+}
+unsigned int
+fn8 (unsigned int x)
+{
+ return (x % 2) + x;
+}
+unsigned int
+fn9 (unsigned int x)
+{
+ return (1LL & x) + x;
+}
+
+/* { dg-final { scan-tree-dump-times "x \\+ 1" 9 "original" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+
+/* x & ~(x & y) -> x & ~y */
+int fn1 (int x, int y)
+{
+ return x & ~(x & y);
+}
+int fn2 (int x, int y)
+{
+ return ~(x & y) & x;
+}
+int fn3 (int x, int y)
+{
+ return x & ~(y & x);
+}
+int fn4 (int x, int y)
+{
+ return ~(y & x) & x;
+}
+int fn5 (int z)
+{
+ return z & ~(z & 3);
+}
+int fn6 (int z)
+{
+ return ~(z & 3) & z;
+}
+
+
+/* { dg-final { scan-tree-dump-times "~y & x" 4 "original" } } */
+/* { dg-final { scan-tree-dump-times "z & -4" 2 "original" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+
+/* x | ~(x | y) -> x | ~y */
+int fn1 (int x, int y)
+{
+ return x | ~(x | y);
+}
+int fn2 (int x, int y)
+{
+ return ~(x | y) | x;
+}
+int fn3 (int x, int y)
+{
+ return x | ~(y | x);
+}
+int fn4 (int x, int y)
+{
+ return ~(y | x) | x;
+}
+int fn5 (int z)
+{
+ return z | ~(z | 3);
+}
+int fn6 (int z)
+{
+ return ~(z | 3) | z;
+}
+
+
+/* { dg-final { scan-tree-dump-times "~y \\| x" 4 "original" } } */
+/* { dg-final { scan-tree-dump-times "z \\| -4" 2 "original" } } */