public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] rtlanal: Fix up replace_rtx [PR105333]
@ 2022-04-22  7:30 Jakub Jelinek
  2022-04-22 11:22 ` Richard Biener
  2022-04-22 16:54 ` Eric Botcazou
  0 siblings, 2 replies; 3+ messages in thread
From: Jakub Jelinek @ 2022-04-22  7:30 UTC (permalink / raw)
  To: Richard Biener, Jeff Law, Eric Botcazou; +Cc: gcc-patches

Hi!

The following testcase FAILs, because replace_rtx replaces a REG with
CONST_WIDE_INT inside of a SUBREG, which is an invalid transformation
because a SUBREG relies on SUBREG_REG having non-VOIDmode but
CONST_WIDE_INT has VOIDmode.

replace_rtx already has code to deal with it, but it was doing
it only for CONST_INTs.  The following patch does it also for
VOIDmode CONST_DOUBLE or CONST_WIDE_INT.

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

2022-04-22  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/105333
	* rtlanal.cc (replace_rtx): Use simplify_subreg or
	simplify_unary_operation if CONST_SCALAR_INT_P rather than just
	CONST_INT_P.

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

--- gcc/rtlanal.cc.jj	2022-02-08 20:08:03.912540713 +0100
+++ gcc/rtlanal.cc	2022-04-21 15:45:23.219769629 +0200
@@ -3390,7 +3390,7 @@ replace_rtx (rtx x, rtx from, rtx to, bo
     {
       rtx new_rtx = replace_rtx (SUBREG_REG (x), from, to, all_regs);
 
-      if (CONST_INT_P (new_rtx))
+      if (CONST_SCALAR_INT_P (new_rtx))
 	{
 	  x = simplify_subreg (GET_MODE (x), new_rtx,
 			       GET_MODE (SUBREG_REG (x)),
@@ -3406,7 +3406,7 @@ replace_rtx (rtx x, rtx from, rtx to, bo
     {
       rtx new_rtx = replace_rtx (XEXP (x, 0), from, to, all_regs);
 
-      if (CONST_INT_P (new_rtx))
+      if (CONST_SCALAR_INT_P (new_rtx))
 	{
 	  x = simplify_unary_operation (ZERO_EXTEND, GET_MODE (x),
 					new_rtx, GET_MODE (XEXP (x, 0)));
--- gcc/testsuite/gcc.dg/pr105333.c.jj	2022-04-21 15:48:08.310468926 +0200
+++ gcc/testsuite/gcc.dg/pr105333.c	2022-04-21 15:47:49.578729973 +0200
@@ -0,0 +1,21 @@
+/* PR rtl-optimization/105333 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-Og -fno-tree-coalesce-vars -fno-tree-fre" } */
+
+int g;
+short s;
+
+static inline unsigned short
+bar (short a, __int128 b)
+{
+  b ^= (unsigned long) -a;
+  __builtin_strncpy ((void *) &s, (void *) &a, 1);
+  b *= 14;
+  return b;
+}
+
+void
+foo (void)
+{
+  g *= (__int128) bar (1, 1);
+}

	Jakub


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

* Re: [PATCH] rtlanal: Fix up replace_rtx [PR105333]
  2022-04-22  7:30 [PATCH] rtlanal: Fix up replace_rtx [PR105333] Jakub Jelinek
@ 2022-04-22 11:22 ` Richard Biener
  2022-04-22 16:54 ` Eric Botcazou
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-04-22 11:22 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, Eric Botcazou, gcc-patches

On Fri, 22 Apr 2022, Jakub Jelinek wrote:

> Hi!
> 
> The following testcase FAILs, because replace_rtx replaces a REG with
> CONST_WIDE_INT inside of a SUBREG, which is an invalid transformation
> because a SUBREG relies on SUBREG_REG having non-VOIDmode but
> CONST_WIDE_INT has VOIDmode.
> 
> replace_rtx already has code to deal with it, but it was doing
> it only for CONST_INTs.  The following patch does it also for
> VOIDmode CONST_DOUBLE or CONST_WIDE_INT.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> 2022-04-22  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR rtl-optimization/105333
> 	* rtlanal.cc (replace_rtx): Use simplify_subreg or
> 	simplify_unary_operation if CONST_SCALAR_INT_P rather than just
> 	CONST_INT_P.
> 
> 	* gcc.dg/pr105333.c: New test.
> 
> --- gcc/rtlanal.cc.jj	2022-02-08 20:08:03.912540713 +0100
> +++ gcc/rtlanal.cc	2022-04-21 15:45:23.219769629 +0200
> @@ -3390,7 +3390,7 @@ replace_rtx (rtx x, rtx from, rtx to, bo
>      {
>        rtx new_rtx = replace_rtx (SUBREG_REG (x), from, to, all_regs);
>  
> -      if (CONST_INT_P (new_rtx))
> +      if (CONST_SCALAR_INT_P (new_rtx))
>  	{
>  	  x = simplify_subreg (GET_MODE (x), new_rtx,
>  			       GET_MODE (SUBREG_REG (x)),
> @@ -3406,7 +3406,7 @@ replace_rtx (rtx x, rtx from, rtx to, bo
>      {
>        rtx new_rtx = replace_rtx (XEXP (x, 0), from, to, all_regs);
>  
> -      if (CONST_INT_P (new_rtx))
> +      if (CONST_SCALAR_INT_P (new_rtx))
>  	{
>  	  x = simplify_unary_operation (ZERO_EXTEND, GET_MODE (x),
>  					new_rtx, GET_MODE (XEXP (x, 0)));
> --- gcc/testsuite/gcc.dg/pr105333.c.jj	2022-04-21 15:48:08.310468926 +0200
> +++ gcc/testsuite/gcc.dg/pr105333.c	2022-04-21 15:47:49.578729973 +0200
> @@ -0,0 +1,21 @@
> +/* PR rtl-optimization/105333 */
> +/* { dg-do compile { target int128 } } */
> +/* { dg-options "-Og -fno-tree-coalesce-vars -fno-tree-fre" } */
> +
> +int g;
> +short s;
> +
> +static inline unsigned short
> +bar (short a, __int128 b)
> +{
> +  b ^= (unsigned long) -a;
> +  __builtin_strncpy ((void *) &s, (void *) &a, 1);
> +  b *= 14;
> +  return b;
> +}
> +
> +void
> +foo (void)
> +{
> +  g *= (__int128) bar (1, 1);
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)

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

* Re: [PATCH] rtlanal: Fix up replace_rtx [PR105333]
  2022-04-22  7:30 [PATCH] rtlanal: Fix up replace_rtx [PR105333] Jakub Jelinek
  2022-04-22 11:22 ` Richard Biener
@ 2022-04-22 16:54 ` Eric Botcazou
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Botcazou @ 2022-04-22 16:54 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Biener, Jeff Law, gcc-patches

> 2022-04-22  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR rtl-optimization/105333
> 	* rtlanal.cc (replace_rtx): Use simplify_subreg or
> 	simplify_unary_operation if CONST_SCALAR_INT_P rather than just
> 	CONST_INT_P.
> 
> 	* gcc.dg/pr105333.c: New test.

OK, thanks.

-- 
Eric Botcazou



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

end of thread, other threads:[~2022-04-22 16:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22  7:30 [PATCH] rtlanal: Fix up replace_rtx [PR105333] Jakub Jelinek
2022-04-22 11:22 ` Richard Biener
2022-04-22 16:54 ` Eric Botcazou

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).