public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] lower-bitint: Handle unreleased SSA_NAMEs from earlier passes gracefully [PR113102]
@ 2023-12-22  8:17 Jakub Jelinek
  2023-12-22 10:08 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-12-22  8:17 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

On the following testcase earlier passes leave around an unreleased
SSA_NAME - non-GIMPLE_NOP SSA_NAME_DEF_STMT which isn't in any bb.
The following patch makes bitint lowering resistent against those,
the first hunk is where we'd for certain kinds of stmts try to ammend
them and the latter is where we'd otherwise try to remove them,
neither of which works.  The other loops over all SSA_NAMEs either
already also check gimple_bb (SSA_NAME_DEF_STMT (s)) or it doesn't
matter that much if we process it or not (worst case it means e.g.
the pass wouldn't return early even when it otherwise could).

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

2023-12-22  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/113102
	* gimple-lower-bitint.cc (gimple_lower_bitint): Handle unreleased
	large/huge _BitInt SSA_NAMEs.

	* gcc.dg/bitint-59.c: New test.

--- gcc/gimple-lower-bitint.cc.jj	2023-12-21 13:28:56.953120687 +0100
+++ gcc/gimple-lower-bitint.cc	2023-12-21 14:08:00.199704511 +0100
@@ -5827,7 +5827,7 @@ gimple_lower_bitint (void)
 	  tree_code rhs_code;
 	  /* Unoptimize certain constructs to simpler alternatives to
 	     avoid having to lower all of them.  */
-	  if (is_gimple_assign (stmt))
+	  if (is_gimple_assign (stmt) && gimple_bb (stmt))
 	    switch (rhs_code = gimple_assign_rhs_code (stmt))
 	      {
 	      default:
@@ -6690,6 +6690,11 @@ gimple_lower_bitint (void)
 		  release_ssa_name (s);
 		  continue;
 		}
+	      if (gimple_bb (g) == NULL)
+		{
+		  release_ssa_name (s);
+		  continue;
+		}
 	      if (gimple_code (g) != GIMPLE_ASM)
 		{
 		  gimple_stmt_iterator gsi = gsi_for_stmt (g);
--- gcc/testsuite/gcc.dg/bitint-59.c.jj	2023-12-21 14:12:01.860350727 +0100
+++ gcc/testsuite/gcc.dg/bitint-59.c	2023-12-21 14:11:54.766449179 +0100
@@ -0,0 +1,14 @@
+/* PR tree-optimization/113102 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+unsigned x;
+
+#if __BITINT_MAXWIDTH__ >= 191
+void
+foo (void)
+{
+  unsigned _BitInt(191) b = x;
+  ~(b >> x) % 3;
+}
+#endif

	Jakub


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

* Re: [PATCH] lower-bitint: Handle unreleased SSA_NAMEs from earlier passes gracefully [PR113102]
  2023-12-22  8:17 [PATCH] lower-bitint: Handle unreleased SSA_NAMEs from earlier passes gracefully [PR113102] Jakub Jelinek
@ 2023-12-22 10:08 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-12-22 10:08 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches



> Am 22.12.2023 um 09:17 schrieb Jakub Jelinek <jakub@redhat.com>:
> 
> Hi!
> 
> On the following testcase earlier passes leave around an unreleased
> SSA_NAME - non-GIMPLE_NOP SSA_NAME_DEF_STMT which isn't in any bb.
> The following patch makes bitint lowering resistent against those,
> the first hunk is where we'd for certain kinds of stmts try to ammend
> them and the latter is where we'd otherwise try to remove them,
> neither of which works.  The other loops over all SSA_NAMEs either
> already also check gimple_bb (SSA_NAME_DEF_STMT (s)) or it doesn't
> matter that much if we process it or not (worst case it means e.g.
> the pass wouldn't return early even when it otherwise could).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok

> 2023-12-22  Jakub Jelinek  <jakub@redhat.com>
> 
>    PR tree-optimization/113102
>    * gimple-lower-bitint.cc (gimple_lower_bitint): Handle unreleased
>    large/huge _BitInt SSA_NAMEs.
> 
>    * gcc.dg/bitint-59.c: New test.
> 
> --- gcc/gimple-lower-bitint.cc.jj    2023-12-21 13:28:56.953120687 +0100
> +++ gcc/gimple-lower-bitint.cc    2023-12-21 14:08:00.199704511 +0100
> @@ -5827,7 +5827,7 @@ gimple_lower_bitint (void)
>      tree_code rhs_code;
>      /* Unoptimize certain constructs to simpler alternatives to
>         avoid having to lower all of them.  */
> -      if (is_gimple_assign (stmt))
> +      if (is_gimple_assign (stmt) && gimple_bb (stmt))
>        switch (rhs_code = gimple_assign_rhs_code (stmt))
>          {
>          default:
> @@ -6690,6 +6690,11 @@ gimple_lower_bitint (void)
>          release_ssa_name (s);
>          continue;
>        }
> +          if (gimple_bb (g) == NULL)
> +        {
> +          release_ssa_name (s);
> +          continue;
> +        }
>          if (gimple_code (g) != GIMPLE_ASM)
>        {
>          gimple_stmt_iterator gsi = gsi_for_stmt (g);
> --- gcc/testsuite/gcc.dg/bitint-59.c.jj    2023-12-21 14:12:01.860350727 +0100
> +++ gcc/testsuite/gcc.dg/bitint-59.c    2023-12-21 14:11:54.766449179 +0100
> @@ -0,0 +1,14 @@
> +/* PR tree-optimization/113102 */
> +/* { dg-do compile { target bitint } } */
> +/* { dg-options "-std=c23 -O2" } */
> +
> +unsigned x;
> +
> +#if __BITINT_MAXWIDTH__ >= 191
> +void
> +foo (void)
> +{
> +  unsigned _BitInt(191) b = x;
> +  ~(b >> x) % 3;
> +}
> +#endif
> 
>    Jakub
> 

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

end of thread, other threads:[~2023-12-22 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-22  8:17 [PATCH] lower-bitint: Handle unreleased SSA_NAMEs from earlier passes gracefully [PR113102] Jakub Jelinek
2023-12-22 10:08 ` 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).