public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] reassoc: Fold some statements [PR108819]
@ 2023-02-18 10:40 Jakub Jelinek
  2023-02-18 11:21 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-02-18 10:40 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

This spot in update_ops can replace one or both of the assign operands with
constants, creating 1 & 1 and similar expressions which can confuse later
passes until they are folded.  Rather than folding both constants by hand
and also handling swapping of operands for commutative ops if the first one
is constant and second one is not, the following patch just uses
fold_stmt_inplace to do that.  I think we shouldn't fold more than the
single statement because that could screw up the rest of the pass, we'd have
to mark all those with uids, visited and the like.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-02-18  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/108819
	* tree-ssa-reassoc.cc (update_ops): Fold new stmt in place.

	* gcc.dg/pr108819.c: New test.

--- gcc/tree-ssa-reassoc.cc.jj	2023-02-16 10:41:11.000000000 +0100
+++ gcc/tree-ssa-reassoc.cc	2023-02-17 22:43:18.949984553 +0100
@@ -4687,6 +4687,9 @@ update_ops (tree var, enum tree_code cod
       gimple_set_uid (g, gimple_uid (stmt));
       gimple_set_visited (g, true);
       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+      gimple_stmt_iterator gsi2 = gsi_for_stmt (g);
+      if (fold_stmt_inplace (&gsi2))
+	update_stmt (g);
     }
   return var;
 }
--- gcc/testsuite/gcc.dg/pr108819.c.jj	2023-02-17 17:50:10.084914418 +0100
+++ gcc/testsuite/gcc.dg/pr108819.c	2023-02-17 17:48:30.765369964 +0100
@@ -0,0 +1,19 @@
+/* PR tree-optimization/108819 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-ccp -fno-tree-forwprop" } */
+
+int a, b;
+
+int
+main ()
+{
+  int d = 1;
+  for (; b; b++)
+    if (a < 1)
+      while (d <= a && a <= 0UL)
+	{
+	  int *e = &d;
+	  *e = 0;
+	}
+  return 0;
+}

	Jakub


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

* Re: [PATCH] reassoc: Fold some statements [PR108819]
  2023-02-18 10:40 [PATCH] reassoc: Fold some statements [PR108819] Jakub Jelinek
@ 2023-02-18 11:21 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-02-18 11:21 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches



> Am 18.02.2023 um 11:41 schrieb Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org>:
> 
> Hi!
> 
> This spot in update_ops can replace one or both of the assign operands with
> constants, creating 1 & 1 and similar expressions which can confuse later
> passes until they are folded.  Rather than folding both constants by hand
> and also handling swapping of operands for commutative ops if the first one
> is constant and second one is not, the following patch just uses
> fold_stmt_inplace to do that.  I think we shouldn't fold more than the
> single statement because that could screw up the rest of the pass, we'd have
> to mark all those with uids, visited and the like.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok

Richard 
> 2023-02-18  Jakub Jelinek  <jakub@redhat.com>
> 
>    PR tree-optimization/108819
>    * tree-ssa-reassoc.cc (update_ops): Fold new stmt in place.
> 
>    * gcc.dg/pr108819.c: New test.
> 
> --- gcc/tree-ssa-reassoc.cc.jj    2023-02-16 10:41:11.000000000 +0100
> +++ gcc/tree-ssa-reassoc.cc    2023-02-17 22:43:18.949984553 +0100
> @@ -4687,6 +4687,9 @@ update_ops (tree var, enum tree_code cod
>       gimple_set_uid (g, gimple_uid (stmt));
>       gimple_set_visited (g, true);
>       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
> +      gimple_stmt_iterator gsi2 = gsi_for_stmt (g);
> +      if (fold_stmt_inplace (&gsi2))
> +    update_stmt (g);
>     }
>   return var;
> }
> --- gcc/testsuite/gcc.dg/pr108819.c.jj    2023-02-17 17:50:10.084914418 +0100
> +++ gcc/testsuite/gcc.dg/pr108819.c    2023-02-17 17:48:30.765369964 +0100
> @@ -0,0 +1,19 @@
> +/* PR tree-optimization/108819 */
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -fno-tree-ccp -fno-tree-forwprop" } */
> +
> +int a, b;
> +
> +int
> +main ()
> +{
> +  int d = 1;
> +  for (; b; b++)
> +    if (a < 1)
> +      while (d <= a && a <= 0UL)
> +    {
> +      int *e = &d;
> +      *e = 0;
> +    }
> +  return 0;
> +}
> 
>    Jakub
> 

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

end of thread, other threads:[~2023-02-18 11:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 10:40 [PATCH] reassoc: Fold some statements [PR108819] Jakub Jelinek
2023-02-18 11:21 ` 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).