[v2,3/3] reassoc: Test rank biasing

Message ID 20210921225429.326017-4-iii@linux.ibm.com
State New
Headers
Series reassoc: Propagate PHI_LOOP_BIAS along single uses |

Commit Message

Ilya Leoshkevich Sept. 21, 2021, 10:54 p.m. UTC
  Add both positive and negative tests.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/reassoc-46.c: New test.
	* gcc.dg/tree-ssa/reassoc-46.h: Common code for new tests.
	* gcc.dg/tree-ssa/reassoc-47.c: New test.
	* gcc.dg/tree-ssa/reassoc-48.c: New test.
	* gcc.dg/tree-ssa/reassoc-49.c: New test.
	* gcc.dg/tree-ssa/reassoc-50.c: New test.
	* gcc.dg/tree-ssa/reassoc-51.c: New test.
---
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c |  7 +++++
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h | 33 ++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c |  9 ++++++
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c |  9 ++++++
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c | 11 ++++++++
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c | 10 +++++++
 gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c | 11 ++++++++
 7 files changed, 90 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c
  

Comments

Richard Biener Sept. 23, 2021, 11:57 a.m. UTC | #1
On Wed, 22 Sep 2021, Ilya Leoshkevich wrote:

> Add both positive and negative tests.

OK I guess (you might want to check with -ftree-vectorize given
that's going to be enabled at -O2)

Richard.

> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/tree-ssa/reassoc-46.c: New test.
> 	* gcc.dg/tree-ssa/reassoc-46.h: Common code for new tests.
> 	* gcc.dg/tree-ssa/reassoc-47.c: New test.
> 	* gcc.dg/tree-ssa/reassoc-48.c: New test.
> 	* gcc.dg/tree-ssa/reassoc-49.c: New test.
> 	* gcc.dg/tree-ssa/reassoc-50.c: New test.
> 	* gcc.dg/tree-ssa/reassoc-51.c: New test.
> ---
>  gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c |  7 +++++
>  gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h | 33 ++++++++++++++++++++++
>  gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c |  9 ++++++
>  gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c |  9 ++++++
>  gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c | 11 ++++++++
>  gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c | 10 +++++++
>  gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c | 11 ++++++++
>  7 files changed, 90 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c
> 
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c
> new file mode 100644
> index 00000000000..69e02bc4d4a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c
> @@ -0,0 +1,7 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +#include "reassoc-46.h"
> +
> +/* Check that the loop accumulator is added last.  */
> +/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 1 "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h
> new file mode 100644
> index 00000000000..e60b490ea0d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h
> @@ -0,0 +1,33 @@
> +#define M 1024
> +unsigned int arr1[M];
> +unsigned int arr2[M];
> +volatile unsigned int sink;
> +
> +unsigned int
> +test (void)
> +{
> +  unsigned int sum = 0;
> +  for (int i = 0; i < M; i++)
> +    {
> +#ifdef MODIFY
> +      /* Modify the loop accumulator using a chain of operations - this should
> +         not affect its rank biasing.  */
> +      sum |= 1;
> +      sum ^= 2;
> +#endif
> +#ifdef STORE
> +      /* Save the loop accumulator into a global variable - this should not
> +         affect its rank biasing.  */
> +      sink = sum;
> +#endif
> +#ifdef USE
> +      /* Add a tricky use of the loop accumulator - this should prevent its
> +         rank biasing.  */
> +      i = (i + sum) % M;
> +#endif
> +      /* Use addends with different ranks.  */
> +      sum += arr1[i];
> +      sum += arr2[((i ^ 1) + 1) % M];
> +    }
> +  return sum;
> +}
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c
> new file mode 100644
> index 00000000000..84b51ccddb0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +#define MODIFY
> +#include "reassoc-46.h"
> +
> +/* Check that if the loop accumulator is saved into a global variable, it's
> +   still added last.  */
> +/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 1 "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c
> new file mode 100644
> index 00000000000..53ae8820281
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +#define STORE
> +#include "reassoc-46.h"
> +
> +/* Check that if the loop accumulator is modified using a chain of operations
> +   other than addition, its new value is still added last.  */
> +/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 1 "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c
> new file mode 100644
> index 00000000000..a6941d5ac2b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +#define MODIFY
> +#define STORE
> +#include "reassoc-46.h"
> +
> +/* Check that if the loop accumulator is both modified using a chain of
> +   operations other than addition and stored into a global variable, its new
> +   value is still added last.  */
> +/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 1 "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c
> new file mode 100644
> index 00000000000..68cd308c4f1
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c
> @@ -0,0 +1,10 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +#define MODIFY
> +#define USE
> +#include "reassoc-46.h"
> +
> +/* Check that if the loop accumulator has multiple uses inside the loop, it's
> +   not forced to the end of the reassociation chain.  */
> +/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 2 "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c
> new file mode 100644
> index 00000000000..eaf61f82ab4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +#define MODIFY
> +#define STORE
> +#define USE
> +#include "reassoc-46.h"
> +
> +/* Check that if the loop accumulator has multiple uses inside the loop, it's
> +   not forced to the end of the reassociation chain.  */
> +/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 2 "optimized" } } */
>
  

Patch

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c
new file mode 100644
index 00000000000..69e02bc4d4a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.c
@@ -0,0 +1,7 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include "reassoc-46.h"
+
+/* Check that the loop accumulator is added last.  */
+/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 1 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h
new file mode 100644
index 00000000000..e60b490ea0d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-46.h
@@ -0,0 +1,33 @@ 
+#define M 1024
+unsigned int arr1[M];
+unsigned int arr2[M];
+volatile unsigned int sink;
+
+unsigned int
+test (void)
+{
+  unsigned int sum = 0;
+  for (int i = 0; i < M; i++)
+    {
+#ifdef MODIFY
+      /* Modify the loop accumulator using a chain of operations - this should
+         not affect its rank biasing.  */
+      sum |= 1;
+      sum ^= 2;
+#endif
+#ifdef STORE
+      /* Save the loop accumulator into a global variable - this should not
+         affect its rank biasing.  */
+      sink = sum;
+#endif
+#ifdef USE
+      /* Add a tricky use of the loop accumulator - this should prevent its
+         rank biasing.  */
+      i = (i + sum) % M;
+#endif
+      /* Use addends with different ranks.  */
+      sum += arr1[i];
+      sum += arr2[((i ^ 1) + 1) % M];
+    }
+  return sum;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c
new file mode 100644
index 00000000000..84b51ccddb0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-47.c
@@ -0,0 +1,9 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#define MODIFY
+#include "reassoc-46.h"
+
+/* Check that if the loop accumulator is saved into a global variable, it's
+   still added last.  */
+/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 1 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c
new file mode 100644
index 00000000000..53ae8820281
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-48.c
@@ -0,0 +1,9 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#define STORE
+#include "reassoc-46.h"
+
+/* Check that if the loop accumulator is modified using a chain of operations
+   other than addition, its new value is still added last.  */
+/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 1 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c
new file mode 100644
index 00000000000..a6941d5ac2b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-49.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#define MODIFY
+#define STORE
+#include "reassoc-46.h"
+
+/* Check that if the loop accumulator is both modified using a chain of
+   operations other than addition and stored into a global variable, its new
+   value is still added last.  */
+/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 1 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c
new file mode 100644
index 00000000000..68cd308c4f1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-50.c
@@ -0,0 +1,10 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#define MODIFY
+#define USE
+#include "reassoc-46.h"
+
+/* Check that if the loop accumulator has multiple uses inside the loop, it's
+   not forced to the end of the reassociation chain.  */
+/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 2 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c
new file mode 100644
index 00000000000..eaf61f82ab4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/reassoc-51.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#define MODIFY
+#define STORE
+#define USE
+#include "reassoc-46.h"
+
+/* Check that if the loop accumulator has multiple uses inside the loop, it's
+   not forced to the end of the reassociation chain.  */
+/* { dg-final { scan-tree-dump-times {sum_\d+ = (?:_\d+ \+ sum_\d+|sum_\d+ \+ _\d+)} 2 "optimized" } } */