From f52baa7b6e1c62c273a2f1ffe045640ec90d6e6a Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 17 Dec 2014 11:48:33 +0000 Subject: [PATCH] re PR middle-end/63568 (Missed optimization (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)) PR middle-end/63568 * match.pd: Add (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x pattern. * gcc.dg/pr63568.c: New test. From-SVN: r218816 --- gcc/ChangeLog | 5 ++++ gcc/match.pd | 7 +++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/pr63568.c | 54 ++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr63568.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 631d7268013..7b3c4aa6f75 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2014-12-17 Marek Polacek + + PR middle-end/63568 + * match.pd: Add (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x pattern. + 2014-12-17 Jakub Jelinek PR tree-optimization/64322 diff --git a/gcc/match.pd b/gcc/match.pd index dbca99efb01..4d4bc9fac8e 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -382,6 +382,13 @@ along with GCC; see the file COPYING3. If not see (bit_not (bit_not @0)) @0) +/* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */ +(simplify + (bit_ior:c (bit_and:c@3 @0 (bit_not @2)) (bit_and:c@4 @1 @2)) + (if ((TREE_CODE (@3) != SSA_NAME || has_single_use (@3)) + && (TREE_CODE (@4) != SSA_NAME || has_single_use (@4))) + (bit_xor (bit_and (bit_xor @0 @1) @2) @0))) + /* Associate (p +p off1) +p off2 as (p +p (off1 + off2)). */ (simplify diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fbafb565dac..7049260ccad 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-12-17 Marek Polacek + + PR middle-end/63568 + * gcc.dg/pr63568.c: New test. + 2014-12-17 Jakub Jelinek PR tree-optimization/64322 diff --git a/gcc/testsuite/gcc.dg/pr63568.c b/gcc/testsuite/gcc.dg/pr63568.c new file mode 100644 index 00000000000..fb42bea6fcf --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr63568.c @@ -0,0 +1,54 @@ +/* PR middle-end/63568 */ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-original" } */ + +int +fn1 (int a, int b, int m) +{ + return (a & ~m) | (b & m); +} + +int +fn2 (int a, int b, int m) +{ + return (a & ~m) | (m & b); +} + +int +fn3 (int a, int b, int m) +{ + return (~m & a) | (m & b); +} + +int +fn4 (int a, int b, int m) +{ + return (~m & a) | (b & m); +} + +int +fn5 (int a, int b, int m) +{ + return (b & m) | (a & ~m); +} + +int +fn6 (int a, int b, int m) +{ + return (m & b) | (a & ~m); +} + +int +fn7 (int a, int b, int m) +{ + return (m & b) | (~m & a); +} + +int +fn8 (int a, int b, int m) +{ + return (b & m) | (~m & a); +} + +/* { dg-final { scan-tree-dump-not " \\| " "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */ -- 2.30.2