From aaec739250b1b148f7db5aa86719fe76645efc06 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Fri, 15 Jan 2021 19:26:01 +0100
Subject: [PATCH] testsuite: Add testcase coverage for already fixed [PR96671]

The fix for this PR didn't come with any test coverage, I've added
tests that make sure we optimize it no matter what order of the x ^ y ^ z
operands is used.

2021-01-15  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/96671
	* gcc.dg/tree-ssa/pr96671-1.c: New test.
	* gcc.dg/tree-ssa/pr96671-2.c: New test.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr96671-1.c | 51 +++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/pr96671-2.c | 51 +++++++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr96671-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr96671-2.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96671-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr96671-1.c
new file mode 100644
index 000000000000..42c5b27b53fa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96671-1.c
@@ -0,0 +1,51 @@
+/* PR tree-optimization/96671 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " \\^ " 6 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " ~" 6 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " & " 6 "optimized" } } */
+
+int
+foo (int a, int b, int c)
+{
+  return (a ^ b) & ((b ^ c) ^ a);
+}
+
+int
+bar (int a, int b, int c)
+{
+  return (a ^ b) & ((b ^ a) ^ c);
+}
+
+int
+baz (int a, int b, int c)
+{
+  return (a ^ b) & ((a ^ c) ^ b);
+}
+
+int
+qux (int a, int b, int c)
+{
+  int d = a ^ b;
+  int e = b ^ c;
+  int f = e ^ a;
+  return d & f;
+}
+
+int
+corge (int a, int b, int c)
+{
+  int d = a ^ b;
+  int e = b ^ a;
+  int f = c ^ e;
+  return d & f;
+}
+
+int
+garply (int a, int b, int c)
+{
+  int d = a ^ b;
+  int e = a ^ c;
+  int f = b ^ e;
+  return d & f;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96671-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr96671-2.c
new file mode 100644
index 000000000000..185fd1149e2f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96671-2.c
@@ -0,0 +1,51 @@
+/* PR tree-optimization/96671 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " \\^ " 6 "optimized" } } */
+/* { dg-final { scan-tree-dump-not " ~" "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \\| " 6 "optimized" } } */
+
+int
+foo (int a, int b, int c)
+{
+  return (a ^ b) | ((b ^ c) ^ a);
+}
+
+int
+bar (int a, int b, int c)
+{
+  return (a ^ b) | ((b ^ a) ^ c);
+}
+
+int
+baz (int a, int b, int c)
+{
+  return (a ^ b) | ((a ^ c) ^ b);
+}
+
+int
+qux (int a, int b, int c)
+{
+  int d = a ^ b;
+  int e = b ^ c;
+  int f = e ^ a;
+  return d | f;
+}
+
+int
+corge (int a, int b, int c)
+{
+  int d = a ^ b;
+  int e = b ^ a;
+  int f = c ^ e;
+  return d | f;
+}
+
+int
+garply (int a, int b, int c)
+{
+  int d = a ^ b;
+  int e = a ^ c;
+  int f = b ^ e;
+  return d | f;
+}
-- 
GitLab