diff mbox

[3/4] match.pd: Add x | ~(x | y) -> x | ~y pattern

Message ID 1421837394-7619-4-git-send-email-rv@rasmusvillemoes.dk
State New
Headers show

Commit Message

Rasmus Villemoes Jan. 21, 2015, 10:49 a.m. UTC
gcc.dg/20150120-3.c: New test

This is simply the 'dual' of the previous pattern, added for
completeness.

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
---
 gcc/match.pd                      |  6 ++++++
 gcc/testsuite/gcc.dg/20150120-3.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/20150120-3.c

Comments

Marek Polacek Jan. 21, 2015, 10:58 a.m. UTC | #1
On Wed, Jan 21, 2015 at 11:49:53AM +0100, Rasmus Villemoes wrote:
> gcc.dg/20150120-3.c: New test
> 
> This is simply the 'dual' of the previous pattern, added for
> completeness.

If this is dual, I think you could make use of
(for op (bit_ior bit_and)
 ...
and do the simplification in one hunk.

	Marek
diff mbox

Patch

diff --git gcc/match.pd gcc/match.pd
index d25fc3a..47865f1 100644
--- gcc/match.pd
+++ gcc/match.pd
@@ -267,6 +267,12 @@  along with GCC; see the file COPYING3.  If not see
  (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
   (bit_and @0 (bit_not @1))))
 
+/* x | ~(x | y) -> x | ~y */
+(simplify
+ (bit_ior:c @0 (bit_not (bit_ior:c@2 @0 @1)))
+ (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
+  (bit_ior @0 (bit_not @1))))
+
 (simplify
  (abs (negate @0))
  (abs @0))
diff --git gcc/testsuite/gcc.dg/20150120-3.c gcc/testsuite/gcc.dg/20150120-3.c
new file mode 100644
index 0000000..322556f
--- /dev/null
+++ 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" } } */