From 0f770b013e710f7225ddb1f75a0fb28bcf8ebf31 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Fri, 1 May 2015 20:25:12 +0200 Subject: [PATCH] match.pd: New simplification patterns. * 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 --- gcc/ChangeLog | 7 +++++ gcc/match.pd | 14 +++++++++ gcc/testsuite/ChangeLog | 6 ++++ gcc/testsuite/gcc.dg/20150120-1.c | 51 +++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/20150120-2.c | 32 +++++++++++++++++++ gcc/testsuite/gcc.dg/20150120-3.c | 32 +++++++++++++++++++ 6 files changed, 142 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/20150120-1.c create mode 100644 gcc/testsuite/gcc.dg/20150120-2.c create mode 100644 gcc/testsuite/gcc.dg/20150120-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 65816c75f69..e006b26fee9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-05-01 Rasmus Villemoes + + * 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 * target.def (attribute_table): Mention that struct attribute_spec diff --git a/gcc/match.pd b/gcc/match.pd index fc374de4121..87ecaf10140 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -255,6 +255,20 @@ along with GCC; see the file COPYING3. If not see (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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bfdde3b87ba..2aedc46e74d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-05-01 Rasmus Villemoes + + * 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 * gcc.dg/debug/pr65771.c: Add "dg-add-options tls". diff --git a/gcc/testsuite/gcc.dg/20150120-1.c b/gcc/testsuite/gcc.dg/20150120-1.c new file mode 100644 index 00000000000..18906c47a09 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20150120-1.c @@ -0,0 +1,51 @@ +/* { 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" } } */ diff --git a/gcc/testsuite/gcc.dg/20150120-2.c b/gcc/testsuite/gcc.dg/20150120-2.c new file mode 100644 index 00000000000..976b6548e27 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20150120-2.c @@ -0,0 +1,32 @@ +/* { 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" } } */ diff --git a/gcc/testsuite/gcc.dg/20150120-3.c b/gcc/testsuite/gcc.dg/20150120-3.c new file mode 100644 index 00000000000..322556f4add --- /dev/null +++ b/gcc/testsuite/gcc.dg/20150120-3.c @@ -0,0 +1,32 @@ +/* { 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" } } */ -- 2.30.2