lower-bitint: Fix a typo in a condition [PR113323]

Message ID ZaEIaLhkFP2KOwCC@tucnak
State Unresolved
Headers
Series lower-bitint: Fix a typo in a condition [PR113323] |

Checks

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

Commit Message

Jakub Jelinek Jan. 12, 2024, 9:37 a.m. UTC
  Hi!

The following testcase revealed a typo in condition, as the comment
says the intent is
       /*  If lhs of stmt is large/huge _BitInt SSA_NAME not in m_names
           it means it will be handled in a loop or straight line code
           at the location of its (ultimate) immediate use, so for
           vop checking purposes check these only at the ultimate
           immediate use.  */
but the condition was using != BITINT_TYPE rather than == BITINT_TYPE,
so e.g. it used bitint_precision_kind on non-BITINT_TYPEs (e.g. on vector
types it will crash because TYPE_PRECISION means something different there,
or on say INTEGER_TYPEs the precision will never be large enough to be
>= bitint_prec_large).

The following patch fixes that, bootstrapped/regtested on x86_64-linux and
i686-linux, ok for trunk?

2024-01-12  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/113323
	* gimple-lower-bitint.cc (bitint_dom_walker::before_dom_children): Fix
	check for lhs being large/huge _BitInt not in m_names.

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


	Jakub
  

Comments

Richard Biener Jan. 12, 2024, 9:43 a.m. UTC | #1
On Fri, 12 Jan 2024, Jakub Jelinek wrote:

> Hi!
> 
> The following testcase revealed a typo in condition, as the comment
> says the intent is
>        /*  If lhs of stmt is large/huge _BitInt SSA_NAME not in m_names
>            it means it will be handled in a loop or straight line code
>            at the location of its (ultimate) immediate use, so for
>            vop checking purposes check these only at the ultimate
>            immediate use.  */
> but the condition was using != BITINT_TYPE rather than == BITINT_TYPE,
> so e.g. it used bitint_precision_kind on non-BITINT_TYPEs (e.g. on vector
> types it will crash because TYPE_PRECISION means something different there,
> or on say INTEGER_TYPEs the precision will never be large enough to be
> >= bitint_prec_large).
> 
> The following patch fixes that, bootstrapped/regtested on x86_64-linux and
> i686-linux, ok for trunk?

OK

> 2024-01-12  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/113323
> 	* gimple-lower-bitint.cc (bitint_dom_walker::before_dom_children): Fix
> 	check for lhs being large/huge _BitInt not in m_names.
> 
> 	* gcc.dg/bitint-68.c: New test.
> 
> --- gcc/gimple-lower-bitint.cc.jj	2024-01-11 13:52:46.000000000 +0100
> +++ gcc/gimple-lower-bitint.cc	2024-01-11 14:27:26.011875196 +0100
> @@ -5513,7 +5513,7 @@ bitint_dom_walker::before_dom_children (
>        tree lhs = gimple_get_lhs (stmt);
>        if (lhs
>  	  && TREE_CODE (lhs) == SSA_NAME
> -	  && TREE_CODE (TREE_TYPE (lhs)) != BITINT_TYPE
> +	  && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
>  	  && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large
>  	  && !bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs)))
>  	/* If lhs of stmt is large/huge _BitInt SSA_NAME not in m_names,
> --- gcc/testsuite/gcc.dg/bitint-68.c.jj	2024-01-11 14:41:21.237183889 +0100
> +++ gcc/testsuite/gcc.dg/bitint-68.c	2024-01-11 14:40:35.977814727 +0100
> @@ -0,0 +1,14 @@
> +/* PR tree-optimization/113323 */
> +/* { dg-do compile { target bitint575 } } */
> +/* { dg-options "-std=c23 -O2" } */
> +
> +typedef long __attribute__((__vector_size__ (16))) V;
> +V u, v;
> +_BitInt(535) i;
> +
> +void
> +foo (void)
> +{
> +  while (i)
> +    u = v;
> +}
> 
> 	Jakub
> 
>
  

Patch

--- gcc/gimple-lower-bitint.cc.jj	2024-01-11 13:52:46.000000000 +0100
+++ gcc/gimple-lower-bitint.cc	2024-01-11 14:27:26.011875196 +0100
@@ -5513,7 +5513,7 @@  bitint_dom_walker::before_dom_children (
       tree lhs = gimple_get_lhs (stmt);
       if (lhs
 	  && TREE_CODE (lhs) == SSA_NAME
-	  && TREE_CODE (TREE_TYPE (lhs)) != BITINT_TYPE
+	  && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
 	  && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large
 	  && !bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs)))
 	/* If lhs of stmt is large/huge _BitInt SSA_NAME not in m_names,
--- gcc/testsuite/gcc.dg/bitint-68.c.jj	2024-01-11 14:41:21.237183889 +0100
+++ gcc/testsuite/gcc.dg/bitint-68.c	2024-01-11 14:40:35.977814727 +0100
@@ -0,0 +1,14 @@ 
+/* PR tree-optimization/113323 */
+/* { dg-do compile { target bitint575 } } */
+/* { dg-options "-std=c23 -O2" } */
+
+typedef long __attribute__((__vector_size__ (16))) V;
+V u, v;
+_BitInt(535) i;
+
+void
+foo (void)
+{
+  while (i)
+    u = v;
+}