public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] gimple-ssa-warn-restrict: Only use type range from NOP_EXPR for non-narrowing conversions [PR113463]
@ 2024-01-19  8:51 Jakub Jelinek
  2024-01-19  8:55 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-01-19  8:51 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

builtin_memref::extend_offset_range when it sees a NOP_EXPR from
INTEGRAL_TYPE (to INTEGRAL_TYPE of sizetype/ptrdifftype precision
given the callers) uses wi::to_offset on TYPE_{MIN,MAX}_VALUE
of the rhs1 type.  This ICEs with large BITINT_TYPEs - to_offset
is only supported for precisions up to the offset_int precision
- but it even doesn't make any sense to do such thing for narrowing
conversions, their range means the whole sizetype/ptrdifftype range
and so the normal handling done later on (largest sized supported object)
is the way to go in that case.

So, the following patch just restrict this to non-narrowing conversions.

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

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

	PR tree-optimization/113463
	* gimple-ssa-warn-restrict.cc (builtin_memref::extend_offset_range):
	Only look through NOP_EXPRs if rhs1 doesn't have wider type than
	lhs.

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

--- gcc/gimple-ssa-warn-restrict.cc.jj	2024-01-03 11:51:27.705784291 +0100
+++ gcc/gimple-ssa-warn-restrict.cc	2024-01-18 16:00:02.519483821 +0100
@@ -391,7 +391,8 @@ builtin_memref::extend_offset_range (tre
       tree type;
       if (is_gimple_assign (stmt)
 	  && (type = TREE_TYPE (gimple_assign_rhs1 (stmt)))
-	  && INTEGRAL_TYPE_P (type))
+	  && INTEGRAL_TYPE_P (type)
+	  && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (offset)))
 	{
 	  tree_code code = gimple_assign_rhs_code (stmt);
 	  if (code == NOP_EXPR)
--- gcc/testsuite/gcc.dg/bitint-74.c.jj	2024-01-18 16:14:05.523599054 +0100
+++ gcc/testsuite/gcc.dg/bitint-74.c	2024-01-18 16:13:30.150099638 +0100
@@ -0,0 +1,16 @@
+/* PR tree-optimization/113463 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+extern char *a, *b;
+#if __BITINT_MAXWIDTH__ >= 129
+_BitInt(129) o;
+#else
+_BitInt(63) o;
+#endif
+
+void
+foo (void)
+{
+  __builtin_memcpy (a + o, b, 4);
+}

	Jakub


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

* Re: [PATCH] gimple-ssa-warn-restrict: Only use type range from NOP_EXPR for non-narrowing conversions [PR113463]
  2024-01-19  8:51 [PATCH] gimple-ssa-warn-restrict: Only use type range from NOP_EXPR for non-narrowing conversions [PR113463] Jakub Jelinek
@ 2024-01-19  8:55 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-01-19  8:55 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, gcc-patches

On Fri, 19 Jan 2024, Jakub Jelinek wrote:

> Hi!
> 
> builtin_memref::extend_offset_range when it sees a NOP_EXPR from
> INTEGRAL_TYPE (to INTEGRAL_TYPE of sizetype/ptrdifftype precision
> given the callers) uses wi::to_offset on TYPE_{MIN,MAX}_VALUE
> of the rhs1 type.  This ICEs with large BITINT_TYPEs - to_offset
> is only supported for precisions up to the offset_int precision
> - but it even doesn't make any sense to do such thing for narrowing
> conversions, their range means the whole sizetype/ptrdifftype range
> and so the normal handling done later on (largest sized supported object)
> is the way to go in that case.
> 
> So, the following patch just restrict this to non-narrowing conversions.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2024-01-19  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/113463
> 	* gimple-ssa-warn-restrict.cc (builtin_memref::extend_offset_range):
> 	Only look through NOP_EXPRs if rhs1 doesn't have wider type than
> 	lhs.
> 
> 	* gcc.dg/bitint-74.c: New test.
> 
> --- gcc/gimple-ssa-warn-restrict.cc.jj	2024-01-03 11:51:27.705784291 +0100
> +++ gcc/gimple-ssa-warn-restrict.cc	2024-01-18 16:00:02.519483821 +0100
> @@ -391,7 +391,8 @@ builtin_memref::extend_offset_range (tre
>        tree type;
>        if (is_gimple_assign (stmt)
>  	  && (type = TREE_TYPE (gimple_assign_rhs1 (stmt)))
> -	  && INTEGRAL_TYPE_P (type))
> +	  && INTEGRAL_TYPE_P (type)
> +	  && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (offset)))
>  	{
>  	  tree_code code = gimple_assign_rhs_code (stmt);
>  	  if (code == NOP_EXPR)
> --- gcc/testsuite/gcc.dg/bitint-74.c.jj	2024-01-18 16:14:05.523599054 +0100
> +++ gcc/testsuite/gcc.dg/bitint-74.c	2024-01-18 16:13:30.150099638 +0100
> @@ -0,0 +1,16 @@
> +/* PR tree-optimization/113463 */
> +/* { dg-do compile { target bitint } } */
> +/* { dg-options "-std=c23 -O2" } */
> +
> +extern char *a, *b;
> +#if __BITINT_MAXWIDTH__ >= 129
> +_BitInt(129) o;
> +#else
> +_BitInt(63) o;
> +#endif
> +
> +void
> +foo (void)
> +{
> +  __builtin_memcpy (a + o, b, 4);
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

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

end of thread, other threads:[~2024-01-19  8:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-19  8:51 [PATCH] gimple-ssa-warn-restrict: Only use type range from NOP_EXPR for non-narrowing conversions [PR113463] Jakub Jelinek
2024-01-19  8:55 ` 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).