public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] expr: Fix up store_expr into SUBREG_PROMOTED_* target [PR108264]
@ 2023-01-03 10:34 Jakub Jelinek
  2023-01-03 11:02 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-01-03 10:34 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

The following testcase ICEs on s390x-linux (e.g. with -march=z13).
The problem is that target is (subreg/s/u:SI (reg/v:DI 66 [ x+-4 ]) 4)
and we call convert_move from temp to the SUBREG_REG of that, expecting
to extend the value properly.  That works nicely if temp has some
scalar integer mode (or partial one), but ICEs when temp has V4QImode
on the assertion that from and to modes have the same bitsize.
store_expr generally allows say store from V4QI to SI target because
they have the same size and if temp is a CONST_INT, we already have code
to convert the constant properly, so the following patch just adds handling
of non-scalar integer modes by converting them to the mode of target
first before convert_move extends them.

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

2023-01-03  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/108264
	* expr.cc (store_expr): For stores into SUBREG_PROMOTED_* targets
	from source which doesn't have scalar integral mode first convert
	it to outer_mode.

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

--- gcc/expr.cc.jj	2023-01-02 09:32:23.000000000 +0100
+++ gcc/expr.cc	2023-01-02 16:48:13.226990815 +0100
@@ -6226,6 +6226,9 @@ store_expr (tree exp, rtx target, int ca
 	  temp = convert_modes (inner_mode, outer_mode, temp,
 				SUBREG_PROMOTED_SIGN (target));
 	}
+      else if (!SCALAR_INT_MODE_P (GET_MODE (temp)))
+	temp = convert_modes (outer_mode, TYPE_MODE (TREE_TYPE (exp)),
+			      temp, SUBREG_PROMOTED_SIGN (target));
 
       convert_move (SUBREG_REG (target), temp,
 		    SUBREG_PROMOTED_SIGN (target));
--- gcc/testsuite/gcc.dg/pr108264.c.jj	2023-01-02 17:01:14.865887522 +0100
+++ gcc/testsuite/gcc.dg/pr108264.c	2023-01-02 17:00:52.238209030 +0100
@@ -0,0 +1,27 @@
+/* PR middle-end/108264 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-fpic" { target fpic } } */
+
+int v;
+extern int bar (void);
+
+static inline void
+foo (char *d)
+{
+  switch (bar ())
+    {
+    case 2:
+      d[0] = d[1] = d[2] = d[3] = v;
+      break;
+    case 4:
+      d[0] = 0;
+    }
+}
+
+int
+baz (int x)
+{
+  foo ((char *) &x);
+  return x;
+}

	Jakub


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

* Re: [PATCH] expr: Fix up store_expr into SUBREG_PROMOTED_* target [PR108264]
  2023-01-03 10:34 [PATCH] expr: Fix up store_expr into SUBREG_PROMOTED_* target [PR108264] Jakub Jelinek
@ 2023-01-03 11:02 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-01-03 11:02 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, gcc-patches



> Am 03.01.2023 um 11:34 schrieb Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org>:
> 
> Hi!
> 
> The following testcase ICEs on s390x-linux (e.g. with -march=z13).
> The problem is that target is (subreg/s/u:SI (reg/v:DI 66 [ x+-4 ]) 4)
> and we call convert_move from temp to the SUBREG_REG of that, expecting
> to extend the value properly.  That works nicely if temp has some
> scalar integer mode (or partial one), but ICEs when temp has V4QImode
> on the assertion that from and to modes have the same bitsize.
> store_expr generally allows say store from V4QI to SI target because
> they have the same size and if temp is a CONST_INT, we already have code
> to convert the constant properly, so the following patch just adds handling
> of non-scalar integer modes by converting them to the mode of target
> first before convert_move extends them.
> 
> Bootstrapped/regtested on x86_64-linux, i686-linux and s390x-linux, ok for
> trunk?

Ok

Richard 

> 2023-01-03  Jakub Jelinek  <jakub@redhat.com>
> 
>    PR middle-end/108264
>    * expr.cc (store_expr): For stores into SUBREG_PROMOTED_* targets
>    from source which doesn't have scalar integral mode first convert
>    it to outer_mode.
> 
>    * gcc.dg/pr108264.c: New test.
> 
> --- gcc/expr.cc.jj    2023-01-02 09:32:23.000000000 +0100
> +++ gcc/expr.cc    2023-01-02 16:48:13.226990815 +0100
> @@ -6226,6 +6226,9 @@ store_expr (tree exp, rtx target, int ca
>      temp = convert_modes (inner_mode, outer_mode, temp,
>                SUBREG_PROMOTED_SIGN (target));
>    }
> +      else if (!SCALAR_INT_MODE_P (GET_MODE (temp)))
> +    temp = convert_modes (outer_mode, TYPE_MODE (TREE_TYPE (exp)),
> +                  temp, SUBREG_PROMOTED_SIGN (target));
> 
>       convert_move (SUBREG_REG (target), temp,
>            SUBREG_PROMOTED_SIGN (target));
> --- gcc/testsuite/gcc.dg/pr108264.c.jj    2023-01-02 17:01:14.865887522 +0100
> +++ gcc/testsuite/gcc.dg/pr108264.c    2023-01-02 17:00:52.238209030 +0100
> @@ -0,0 +1,27 @@
> +/* PR middle-end/108264 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +/* { dg-additional-options "-fpic" { target fpic } } */
> +
> +int v;
> +extern int bar (void);
> +
> +static inline void
> +foo (char *d)
> +{
> +  switch (bar ())
> +    {
> +    case 2:
> +      d[0] = d[1] = d[2] = d[3] = v;
> +      break;
> +    case 4:
> +      d[0] = 0;
> +    }
> +}
> +
> +int
> +baz (int x)
> +{
> +  foo ((char *) &x);
> +  return x;
> +}
> 
>    Jakub
> 

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

end of thread, other threads:[~2023-01-03 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03 10:34 [PATCH] expr: Fix up store_expr into SUBREG_PROMOTED_* target [PR108264] Jakub Jelinek
2023-01-03 11:02 ` 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).