public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/79333 - fold stmts following SSA edges in VN
@ 2021-05-05  7:55 Richard Biener
  2021-05-07 14:12 ` Christophe Lyon
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2021-05-05  7:55 UTC (permalink / raw)
  To: gcc-patches

This makes sure to follow SSA edges when folding eliminated stmts.
This reaps the same benefit as forwprop folding all stmts, not
waiting for one to produce copysign in the new testcase.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

2021-05-04  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/79333
	* tree-ssa-sccvn.c (eliminate_dom_walker::eliminate_stmt):
	Fold stmt following SSA edges.

	* gcc.dg/tree-ssa/ssa-fre-94.c: New testcase.
	* gcc.dg/graphite/fuse-1.c: Adjust.
	* gcc.dg/pr43864-4.c: Likewise.
---
 gcc/testsuite/gcc.dg/graphite/fuse-1.c     |  4 ++--
 gcc/testsuite/gcc.dg/pr43864-4.c           |  6 +++---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c | 16 ++++++++++++++++
 gcc/tree-ssa-sccvn.c                       |  2 +-
 4 files changed, 22 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c

diff --git a/gcc/testsuite/gcc.dg/graphite/fuse-1.c b/gcc/testsuite/gcc.dg/graphite/fuse-1.c
index 204d3b20703..527b6e5c415 100644
--- a/gcc/testsuite/gcc.dg/graphite/fuse-1.c
+++ b/gcc/testsuite/gcc.dg/graphite/fuse-1.c
@@ -1,6 +1,6 @@
 /* Check that the two loops are fused and that we manage to fold the two xor
    operations.  */
-/* { dg-options "-O2 -floop-nest-optimize -fdump-tree-forwprop-all -fdump-tree-graphite-all" } */
+/* { dg-options "-O2 -floop-nest-optimize -fdump-tree-forwprop4 -fdump-tree-graphite-all" } */
 
 /* Make sure we fuse the loops like this:
 AST generated by isl:
@@ -12,7 +12,7 @@ for (int c0 = 0; c0 <= 99; c0 += 1) {
 /* { dg-final { scan-tree-dump-times "AST generated by isl:.*for \\(int c0 = 0; c0 <= 99; c0 \\+= 1\\) \\{.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*\\}" 1 "graphite" } } */
 
 /* Check that after fusing the loops, the scalar computation is also fused.  */
-/* { dg-final { scan-tree-dump-times "gimple_simplified to\[^\\n\]*\\^ 12" 1 "forwprop4" } } */
+/* { dg-final { scan-tree-dump-times " \\^ 12;" 2 "forwprop4" } } */
 
 #define MAX 100
 int A[MAX];
diff --git a/gcc/testsuite/gcc.dg/pr43864-4.c b/gcc/testsuite/gcc.dg/pr43864-4.c
index 3c6cc50c5b8..8a25b0fd8ef 100644
--- a/gcc/testsuite/gcc.dg/pr43864-4.c
+++ b/gcc/testsuite/gcc.dg/pr43864-4.c
@@ -22,7 +22,7 @@ int f(int c, int b, int d)
   return r - r2;
 }
 
-/* { dg-final { scan-tree-dump-times "if " 0 "pre"} } */
-/* { dg-final { scan-tree-dump-times "(?n)_.*\\+.*_" 1 "pre"} } */
-/* { dg-final { scan-tree-dump-times "(?n)_.*-.*_" 2 "pre"} } */
+/* During PRE elimination we should simplify this to return b * 2.  */
+/* { dg-final { scan-tree-dump-times "if " 0 "pre" } } */
+/* { dg-final { scan-tree-dump "_\[0-9\]+ = b_\[0-9\]+\\(D\\) \\* 2;\[\\r\\n\]\[^\\r\\n\]*return _\[0-9\]+;" "pre" } } */
 /* { dg-final { scan-tree-dump-not "Invalid sum" "pre"} } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
new file mode 100644
index 00000000000..92eebf636c6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
@@ -0,0 +1,16 @@
+/* PR tree-optimization/79333 */
+/* { dg-do compile } */
+/* { dg-options "-O -ffinite-math-only -fdump-tree-fre1" } */
+
+extern __inline __attribute__ ((__always_inline__,__gnu_inline__))
+double __attribute__ ((__nothrow__ , __leaf__))
+fabs (double __x) { return __builtin_fabs (__x); }
+
+double f(float f)
+{
+  double t1 = fabs(f);
+  double t2 = f / t1;
+  return t2;
+}
+
+/* { dg-final { scan-tree-dump "copysign" "fre1" } } */
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index ca0974d72b8..e54a0c9065c 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -6362,7 +6362,7 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
 	recompute_tree_invariant_for_addr_expr (gimple_assign_rhs1 (stmt));
       gimple_stmt_iterator prev = *gsi;
       gsi_prev (&prev);
-      if (fold_stmt (gsi))
+      if (fold_stmt (gsi, follow_all_ssa_edges))
 	{
 	  /* fold_stmt may have created new stmts inbetween
 	     the previous stmt and the folded stmt.  Mark
-- 
2.26.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tree-optimization/79333 - fold stmts following SSA edges in VN
  2021-05-05  7:55 [PATCH] tree-optimization/79333 - fold stmts following SSA edges in VN Richard Biener
@ 2021-05-07 14:12 ` Christophe Lyon
  2021-05-07 15:45   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe Lyon @ 2021-05-07 14:12 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc Patches

On Wed, 5 May 2021 at 09:56, Richard Biener <rguenther@suse.de> wrote:
>
> This makes sure to follow SSA edges when folding eliminated stmts.
> This reaps the same benefit as forwprop folding all stmts, not
> waiting for one to produce copysign in the new testcase.
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
>
> 2021-05-04  Richard Biener  <rguenther@suse.de>
>
>         PR tree-optimization/79333
>         * tree-ssa-sccvn.c (eliminate_dom_walker::eliminate_stmt):
>         Fold stmt following SSA edges.
>
>         * gcc.dg/tree-ssa/ssa-fre-94.c: New testcase.
>         * gcc.dg/graphite/fuse-1.c: Adjust.
>         * gcc.dg/pr43864-4.c: Likewise.
> ---
>  gcc/testsuite/gcc.dg/graphite/fuse-1.c     |  4 ++--
>  gcc/testsuite/gcc.dg/pr43864-4.c           |  6 +++---
>  gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c | 16 ++++++++++++++++
>  gcc/tree-ssa-sccvn.c                       |  2 +-
>  4 files changed, 22 insertions(+), 6 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>
> diff --git a/gcc/testsuite/gcc.dg/graphite/fuse-1.c b/gcc/testsuite/gcc.dg/graphite/fuse-1.c
> index 204d3b20703..527b6e5c415 100644
> --- a/gcc/testsuite/gcc.dg/graphite/fuse-1.c
> +++ b/gcc/testsuite/gcc.dg/graphite/fuse-1.c
> @@ -1,6 +1,6 @@
>  /* Check that the two loops are fused and that we manage to fold the two xor
>     operations.  */
> -/* { dg-options "-O2 -floop-nest-optimize -fdump-tree-forwprop-all -fdump-tree-graphite-all" } */
> +/* { dg-options "-O2 -floop-nest-optimize -fdump-tree-forwprop4 -fdump-tree-graphite-all" } */
>
>  /* Make sure we fuse the loops like this:
>  AST generated by isl:
> @@ -12,7 +12,7 @@ for (int c0 = 0; c0 <= 99; c0 += 1) {
>  /* { dg-final { scan-tree-dump-times "AST generated by isl:.*for \\(int c0 = 0; c0 <= 99; c0 \\+= 1\\) \\{.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*\\}" 1 "graphite" } } */
>
>  /* Check that after fusing the loops, the scalar computation is also fused.  */
> -/* { dg-final { scan-tree-dump-times "gimple_simplified to\[^\\n\]*\\^ 12" 1 "forwprop4" } } */
> +/* { dg-final { scan-tree-dump-times " \\^ 12;" 2 "forwprop4" } } */
>
>  #define MAX 100
>  int A[MAX];
> diff --git a/gcc/testsuite/gcc.dg/pr43864-4.c b/gcc/testsuite/gcc.dg/pr43864-4.c
> index 3c6cc50c5b8..8a25b0fd8ef 100644
> --- a/gcc/testsuite/gcc.dg/pr43864-4.c
> +++ b/gcc/testsuite/gcc.dg/pr43864-4.c
> @@ -22,7 +22,7 @@ int f(int c, int b, int d)
>    return r - r2;
>  }
>
> -/* { dg-final { scan-tree-dump-times "if " 0 "pre"} } */
> -/* { dg-final { scan-tree-dump-times "(?n)_.*\\+.*_" 1 "pre"} } */
> -/* { dg-final { scan-tree-dump-times "(?n)_.*-.*_" 2 "pre"} } */
> +/* During PRE elimination we should simplify this to return b * 2.  */
> +/* { dg-final { scan-tree-dump-times "if " 0 "pre" } } */
> +/* { dg-final { scan-tree-dump "_\[0-9\]+ = b_\[0-9\]+\\(D\\) \\* 2;\[\\r\\n\]\[^\\r\\n\]*return _\[0-9\]+;" "pre" } } */
>  /* { dg-final { scan-tree-dump-not "Invalid sum" "pre"} } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
> new file mode 100644
> index 00000000000..92eebf636c6
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
> @@ -0,0 +1,16 @@
> +/* PR tree-optimization/79333 */
> +/* { dg-do compile } */
> +/* { dg-options "-O -ffinite-math-only -fdump-tree-fre1" } */
> +
> +extern __inline __attribute__ ((__always_inline__,__gnu_inline__))
> +double __attribute__ ((__nothrow__ , __leaf__))
> +fabs (double __x) { return __builtin_fabs (__x); }
> +
> +double f(float f)
> +{
> +  double t1 = fabs(f);
> +  double t2 = f / t1;
> +  return t2;
> +}
> +
> +/* { dg-final { scan-tree-dump "copysign" "fre1" } } */

This new testcase fails on aarch64-elf / arm-eabi with newlib.

Is that OK:
===========================
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
index 92eebf636c6..99c737562bb 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
@@ -1,5 +1,6 @@
 /* PR tree-optimization/79333 */
 /* { dg-do compile } */
+/* { dg-require-effective-target c99_runtime } */
 /* { dg-options "-O -ffinite-math-only -fdump-tree-fre1" } */

 extern __inline __attribute__ ((__always_inline__,__gnu_inline__))
===========================

Thanks,

Christophe




> diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
> index ca0974d72b8..e54a0c9065c 100644
> --- a/gcc/tree-ssa-sccvn.c
> +++ b/gcc/tree-ssa-sccvn.c
> @@ -6362,7 +6362,7 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
>         recompute_tree_invariant_for_addr_expr (gimple_assign_rhs1 (stmt));
>        gimple_stmt_iterator prev = *gsi;
>        gsi_prev (&prev);
> -      if (fold_stmt (gsi))
> +      if (fold_stmt (gsi, follow_all_ssa_edges))
>         {
>           /* fold_stmt may have created new stmts inbetween
>              the previous stmt and the folded stmt.  Mark
> --
> 2.26.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tree-optimization/79333 - fold stmts following SSA edges in VN
  2021-05-07 14:12 ` Christophe Lyon
@ 2021-05-07 15:45   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2021-05-07 15:45 UTC (permalink / raw)
  To: Christophe Lyon; +Cc: gcc Patches

On May 7, 2021 4:12:02 PM GMT+02:00, Christophe Lyon <christophe.lyon@linaro.org> wrote:
>On Wed, 5 May 2021 at 09:56, Richard Biener <rguenther@suse.de> wrote:
>>
>> This makes sure to follow SSA edges when folding eliminated stmts.
>> This reaps the same benefit as forwprop folding all stmts, not
>> waiting for one to produce copysign in the new testcase.
>>
>> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
>>
>> 2021-05-04  Richard Biener  <rguenther@suse.de>
>>
>>         PR tree-optimization/79333
>>         * tree-ssa-sccvn.c (eliminate_dom_walker::eliminate_stmt):
>>         Fold stmt following SSA edges.
>>
>>         * gcc.dg/tree-ssa/ssa-fre-94.c: New testcase.
>>         * gcc.dg/graphite/fuse-1.c: Adjust.
>>         * gcc.dg/pr43864-4.c: Likewise.
>> ---
>>  gcc/testsuite/gcc.dg/graphite/fuse-1.c     |  4 ++--
>>  gcc/testsuite/gcc.dg/pr43864-4.c           |  6 +++---
>>  gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c | 16 ++++++++++++++++
>>  gcc/tree-ssa-sccvn.c                       |  2 +-
>>  4 files changed, 22 insertions(+), 6 deletions(-)
>>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>>
>> diff --git a/gcc/testsuite/gcc.dg/graphite/fuse-1.c
>b/gcc/testsuite/gcc.dg/graphite/fuse-1.c
>> index 204d3b20703..527b6e5c415 100644
>> --- a/gcc/testsuite/gcc.dg/graphite/fuse-1.c
>> +++ b/gcc/testsuite/gcc.dg/graphite/fuse-1.c
>> @@ -1,6 +1,6 @@
>>  /* Check that the two loops are fused and that we manage to fold the
>two xor
>>     operations.  */
>> -/* { dg-options "-O2 -floop-nest-optimize -fdump-tree-forwprop-all
>-fdump-tree-graphite-all" } */
>> +/* { dg-options "-O2 -floop-nest-optimize -fdump-tree-forwprop4
>-fdump-tree-graphite-all" } */
>>
>>  /* Make sure we fuse the loops like this:
>>  AST generated by isl:
>> @@ -12,7 +12,7 @@ for (int c0 = 0; c0 <= 99; c0 += 1) {
>>  /* { dg-final { scan-tree-dump-times "AST generated by isl:.*for
>\\(int c0 = 0; c0 <= 99; c0 \\+= 1\\)
>\\{.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*\\}" 1 "graphite" } }
>*/
>>
>>  /* Check that after fusing the loops, the scalar computation is also
>fused.  */
>> -/* { dg-final { scan-tree-dump-times "gimple_simplified
>to\[^\\n\]*\\^ 12" 1 "forwprop4" } } */
>> +/* { dg-final { scan-tree-dump-times " \\^ 12;" 2 "forwprop4" } } */
>>
>>  #define MAX 100
>>  int A[MAX];
>> diff --git a/gcc/testsuite/gcc.dg/pr43864-4.c
>b/gcc/testsuite/gcc.dg/pr43864-4.c
>> index 3c6cc50c5b8..8a25b0fd8ef 100644
>> --- a/gcc/testsuite/gcc.dg/pr43864-4.c
>> +++ b/gcc/testsuite/gcc.dg/pr43864-4.c
>> @@ -22,7 +22,7 @@ int f(int c, int b, int d)
>>    return r - r2;
>>  }
>>
>> -/* { dg-final { scan-tree-dump-times "if " 0 "pre"} } */
>> -/* { dg-final { scan-tree-dump-times "(?n)_.*\\+.*_" 1 "pre"} } */
>> -/* { dg-final { scan-tree-dump-times "(?n)_.*-.*_" 2 "pre"} } */
>> +/* During PRE elimination we should simplify this to return b * 2. 
>*/
>> +/* { dg-final { scan-tree-dump-times "if " 0 "pre" } } */
>> +/* { dg-final { scan-tree-dump "_\[0-9\]+ = b_\[0-9\]+\\(D\\) \\*
>2;\[\\r\\n\]\[^\\r\\n\]*return _\[0-9\]+;" "pre" } } */
>>  /* { dg-final { scan-tree-dump-not "Invalid sum" "pre"} } */
>> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>> new file mode 100644
>> index 00000000000..92eebf636c6
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>> @@ -0,0 +1,16 @@
>> +/* PR tree-optimization/79333 */
>> +/* { dg-do compile } */
>> +/* { dg-options "-O -ffinite-math-only -fdump-tree-fre1" } */
>> +
>> +extern __inline __attribute__ ((__always_inline__,__gnu_inline__))
>> +double __attribute__ ((__nothrow__ , __leaf__))
>> +fabs (double __x) { return __builtin_fabs (__x); }
>> +
>> +double f(float f)
>> +{
>> +  double t1 = fabs(f);
>> +  double t2 = f / t1;
>> +  return t2;
>> +}
>> +
>> +/* { dg-final { scan-tree-dump "copysign" "fre1" } } */
>
>This new testcase fails on aarch64-elf / arm-eabi with newlib.
>
>Is that OK:

Yes, OK. 

Thanks, 
Richard. 

>===========================
>diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>index 92eebf636c6..99c737562bb 100644
>--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-94.c
>@@ -1,5 +1,6 @@
> /* PR tree-optimization/79333 */
> /* { dg-do compile } */
>+/* { dg-require-effective-target c99_runtime } */
> /* { dg-options "-O -ffinite-math-only -fdump-tree-fre1" } */
>
> extern __inline __attribute__ ((__always_inline__,__gnu_inline__))
>===========================
>
>Thanks,
>
>Christophe
>
>
>
>
>> diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
>> index ca0974d72b8..e54a0c9065c 100644
>> --- a/gcc/tree-ssa-sccvn.c
>> +++ b/gcc/tree-ssa-sccvn.c
>> @@ -6362,7 +6362,7 @@ eliminate_dom_walker::eliminate_stmt
>(basic_block b, gimple_stmt_iterator *gsi)
>>         recompute_tree_invariant_for_addr_expr (gimple_assign_rhs1
>(stmt));
>>        gimple_stmt_iterator prev = *gsi;
>>        gsi_prev (&prev);
>> -      if (fold_stmt (gsi))
>> +      if (fold_stmt (gsi, follow_all_ssa_edges))
>>         {
>>           /* fold_stmt may have created new stmts inbetween
>>              the previous stmt and the folded stmt.  Mark
>> --
>> 2.26.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-07 15:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05  7:55 [PATCH] tree-optimization/79333 - fold stmts following SSA edges in VN Richard Biener
2021-05-07 14:12 ` Christophe Lyon
2021-05-07 15:45   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).