lower-bitint: Handle uninitialized large/huge SSA_NAMEs as inline asm inputs [PR113699]

Message ID Zby4nivs7X3vurkq@tucnak
State Unresolved
Headers
Series lower-bitint: Handle uninitialized large/huge SSA_NAMEs as inline asm inputs [PR113699] |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jakub Jelinek Feb. 2, 2024, 9:40 a.m. UTC
  Hi!

Similar problem to calls with uninitialized large/huge _BitInt SSA_NAME
arguments, var_to_partition will not work for those, but unlike calls
where we just create a new uninitialized SSA_NAME here we need to change
the inline asm input to be an uninitialized VAR_DECL.

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

2024-02-02  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/113699
	* gimple-lower-bitint.cc (bitint_large_huge::lower_asm): Handle
	uninitialized large/huge _BitInt SSA_NAME inputs.

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


	Jakub
  

Comments

Richard Biener Feb. 2, 2024, 10:20 a.m. UTC | #1
> Am 02.02.2024 um 10:41 schrieb Jakub Jelinek <jakub@redhat.com>:
> 
> Hi!
> 
> Similar problem to calls with uninitialized large/huge _BitInt SSA_NAME
> arguments, var_to_partition will not work for those, but unlike calls
> where we just create a new uninitialized SSA_NAME here we need to change
> the inline asm input to be an uninitialized VAR_DECL.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok

Richard 

> 2024-02-02  Jakub Jelinek  <jakub@redhat.com>
> 
>    PR middle-end/113699
>    * gimple-lower-bitint.cc (bitint_large_huge::lower_asm): Handle
>    uninitialized large/huge _BitInt SSA_NAME inputs.
> 
>    * gcc.dg/bitint-81.c: New test.
> 
> --- gcc/gimple-lower-bitint.cc.jj    2024-01-31 10:55:42.677095630 +0100
> +++ gcc/gimple-lower-bitint.cc    2024-02-01 10:36:08.408867602 +0100
> @@ -5200,9 +5200,18 @@ bitint_large_huge::lower_asm (gimple *st
>      && TREE_CODE (TREE_TYPE (s)) == BITINT_TYPE
>      && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large)
>    {
> -      int part = var_to_partition (m_map, s);
> -      gcc_assert (m_vars[part] != NULL_TREE);
> -      TREE_VALUE (t) = m_vars[part];
> +      if (SSA_NAME_IS_DEFAULT_DEF (s)
> +          && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s))))
> +        {
> +          TREE_VALUE (t) = create_tmp_var (TREE_TYPE (s), "bitint");
> +          mark_addressable (TREE_VALUE (t));
> +        }
> +      else
> +        {
> +          int part = var_to_partition (m_map, s);
> +          gcc_assert (m_vars[part] != NULL_TREE);
> +          TREE_VALUE (t) = m_vars[part];
> +        }
>    }
>     }
>   update_stmt (stmt);
> --- gcc/testsuite/gcc.dg/bitint-81.c.jj    2024-02-01 10:38:26.132937531 +0100
> +++ gcc/testsuite/gcc.dg/bitint-81.c    2024-02-01 10:38:01.628280939 +0100
> @@ -0,0 +1,12 @@
> +/* PR middle-end/113699 */
> +/* { dg-do compile { target bitint } } */
> +/* { dg-options "-O2 -std=c23" } */
> +
> +void
> +foo (void)
> +{
> +#if __BITINT_MAXWIDTH__ >= 129
> +  _BitInt(129) i;
> +  __asm__ ("" : : "rm" (i));
> +#endif
> +}
> 
>    Jakub
>
  

Patch

--- gcc/gimple-lower-bitint.cc.jj	2024-01-31 10:55:42.677095630 +0100
+++ gcc/gimple-lower-bitint.cc	2024-02-01 10:36:08.408867602 +0100
@@ -5200,9 +5200,18 @@  bitint_large_huge::lower_asm (gimple *st
 	  && TREE_CODE (TREE_TYPE (s)) == BITINT_TYPE
 	  && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large)
 	{
-	  int part = var_to_partition (m_map, s);
-	  gcc_assert (m_vars[part] != NULL_TREE);
-	  TREE_VALUE (t) = m_vars[part];
+	  if (SSA_NAME_IS_DEFAULT_DEF (s)
+	      && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s))))
+	    {
+	      TREE_VALUE (t) = create_tmp_var (TREE_TYPE (s), "bitint");
+	      mark_addressable (TREE_VALUE (t));
+	    }
+	  else
+	    {
+	      int part = var_to_partition (m_map, s);
+	      gcc_assert (m_vars[part] != NULL_TREE);
+	      TREE_VALUE (t) = m_vars[part];
+	    }
 	}
     }
   update_stmt (stmt);
--- gcc/testsuite/gcc.dg/bitint-81.c.jj	2024-02-01 10:38:26.132937531 +0100
+++ gcc/testsuite/gcc.dg/bitint-81.c	2024-02-01 10:38:01.628280939 +0100
@@ -0,0 +1,12 @@ 
+/* PR middle-end/113699 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2 -std=c23" } */
+
+void
+foo (void)
+{
+#if __BITINT_MAXWIDTH__ >= 129
+  _BitInt(129) i;
+  __asm__ ("" : : "rm" (i));
+#endif
+}