public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-ssa-math-opts: Fix up gsi_remove order in match_uaddc_usubc [PR112430]
@ 2023-11-11  8:27 Jakub Jelinek
  2023-11-11 13:16 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-11-11  8:27 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

The following testcase ICEs, because the temp_stmts were removed in
wrong order, from the ones appearing earlier in the IL to the later ones,
so insert_debug_temps_for_defs can reintroduce dead SSA_NAMEs back into the
IL.

The following patch fixes that by removing them in the order they were
pushed into the vector, which is from later ones to earlier ones.
Additionally, I've noticed I forgot to call release_defs on the removed
stmts.

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

2023-11-11  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/112430
	* tree-ssa-math-opts.cc (match_uaddc_usubc): Remove temp_stmts in the
	order they were pushed rather than in reverse order.  Call
	release_defs after gsi_remove.

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

--- gcc/tree-ssa-math-opts.cc.jj	2023-11-02 07:49:20.699815089 +0100
+++ gcc/tree-ssa-math-opts.cc	2023-11-10 13:43:13.059912310 +0100
@@ -5047,11 +5047,11 @@ match_uaddc_usubc (gimple_stmt_iterator
       gsi_insert_before (gsi, g, GSI_SAME_STMT);
       /* Remove some further statements which can't be kept in the IL because
 	 they can use SSA_NAMEs whose setter is going to be removed too.  */
-      while (temp_stmts.length ())
+      for (gimple *g2 : temp_stmts)
 	{
-	  g = temp_stmts.pop ();
-	  gsi2 = gsi_for_stmt (g);
+	  gsi2 = gsi_for_stmt (g2);
 	  gsi_remove (&gsi2, true);
+	  release_defs (g2);
 	}
     }
   else
@@ -5068,10 +5068,12 @@ match_uaddc_usubc (gimple_stmt_iterator
 	rhs1 = gimple_assign_rhs1 (g);
 	gsi2 = gsi_for_stmt (g);
 	gsi_remove (&gsi2, true);
+	release_defs (g);
       }
   gcc_checking_assert (rhs1 == gimple_assign_lhs (im2));
   gsi2 = gsi_for_stmt (im2);
   gsi_remove (&gsi2, true);
+  release_defs (im2);
   /* Replace the re2 statement with __real__ of the newly added
      .UADDC/.USUBC call.  */
   if (re2)
--- gcc/testsuite/gcc.dg/pr112430.c.jj	2023-11-10 13:45:18.707163791 +0100
+++ gcc/testsuite/gcc.dg/pr112430.c	2023-11-10 13:45:04.523361174 +0100
@@ -0,0 +1,30 @@
+/* PR middle-end/112430 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g" } */
+
+int a, b, c, d, e;
+unsigned int f;
+
+static void
+foo (unsigned int x)
+{
+  unsigned int g = x < c;
+  int h = f < b;
+  x += h;
+  g += x < h;
+  f = x;
+  x = g;
+  g = f += a;
+  h = f < a;
+  x += h;
+  c += f < d;
+  x += c;
+  g += x < c;
+  e = g;
+}
+
+void
+bar (unsigned int x)
+{
+  foo (x);
+}

	Jakub


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

* Re: [PATCH] tree-ssa-math-opts: Fix up gsi_remove order in match_uaddc_usubc [PR112430]
  2023-11-11  8:27 [PATCH] tree-ssa-math-opts: Fix up gsi_remove order in match_uaddc_usubc [PR112430] Jakub Jelinek
@ 2023-11-11 13:16 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-11-11 13:16 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches



> Am 11.11.2023 um 09:27 schrieb Jakub Jelinek <jakub@redhat.com>:
> 
> Hi!
> 
> The following testcase ICEs, because the temp_stmts were removed in
> wrong order, from the ones appearing earlier in the IL to the later ones,
> so insert_debug_temps_for_defs can reintroduce dead SSA_NAMEs back into the
> IL.
> 
> The following patch fixes that by removing them in the order they were
> pushed into the vector, which is from later ones to earlier ones.
> Additionally, I've noticed I forgot to call release_defs on the removed
> stmts.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok

Richard 

> 2023-11-11  Jakub Jelinek  <jakub@redhat.com>
> 
>    PR middle-end/112430
>    * tree-ssa-math-opts.cc (match_uaddc_usubc): Remove temp_stmts in the
>    order they were pushed rather than in reverse order.  Call
>    release_defs after gsi_remove.
> 
>    * gcc.dg/pr112430.c: New test.
> 
> --- gcc/tree-ssa-math-opts.cc.jj    2023-11-02 07:49:20.699815089 +0100
> +++ gcc/tree-ssa-math-opts.cc    2023-11-10 13:43:13.059912310 +0100
> @@ -5047,11 +5047,11 @@ match_uaddc_usubc (gimple_stmt_iterator
>       gsi_insert_before (gsi, g, GSI_SAME_STMT);
>       /* Remove some further statements which can't be kept in the IL because
>     they can use SSA_NAMEs whose setter is going to be removed too.  */
> -      while (temp_stmts.length ())
> +      for (gimple *g2 : temp_stmts)
>    {
> -      g = temp_stmts.pop ();
> -      gsi2 = gsi_for_stmt (g);
> +      gsi2 = gsi_for_stmt (g2);
>      gsi_remove (&gsi2, true);
> +      release_defs (g2);
>    }
>     }
>   else
> @@ -5068,10 +5068,12 @@ match_uaddc_usubc (gimple_stmt_iterator
>    rhs1 = gimple_assign_rhs1 (g);
>    gsi2 = gsi_for_stmt (g);
>    gsi_remove (&gsi2, true);
> +    release_defs (g);
>       }
>   gcc_checking_assert (rhs1 == gimple_assign_lhs (im2));
>   gsi2 = gsi_for_stmt (im2);
>   gsi_remove (&gsi2, true);
> +  release_defs (im2);
>   /* Replace the re2 statement with __real__ of the newly added
>      .UADDC/.USUBC call.  */
>   if (re2)
> --- gcc/testsuite/gcc.dg/pr112430.c.jj    2023-11-10 13:45:18.707163791 +0100
> +++ gcc/testsuite/gcc.dg/pr112430.c    2023-11-10 13:45:04.523361174 +0100
> @@ -0,0 +1,30 @@
> +/* PR middle-end/112430 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -g" } */
> +
> +int a, b, c, d, e;
> +unsigned int f;
> +
> +static void
> +foo (unsigned int x)
> +{
> +  unsigned int g = x < c;
> +  int h = f < b;
> +  x += h;
> +  g += x < h;
> +  f = x;
> +  x = g;
> +  g = f += a;
> +  h = f < a;
> +  x += h;
> +  c += f < d;
> +  x += c;
> +  g += x < c;
> +  e = g;
> +}
> +
> +void
> +bar (unsigned int x)
> +{
> +  foo (x);
> +}
> 
>    Jakub
> 

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

end of thread, other threads:[~2023-11-11 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-11  8:27 [PATCH] tree-ssa-math-opts: Fix up gsi_remove order in match_uaddc_usubc [PR112430] Jakub Jelinek
2023-11-11 13:16 ` 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).