expr: Fix up VEC_PACK_TRUNC_EXPR expansion [PR101046]

Message ID 20210615083013.GL7746@tucnak
State New
Headers show
Series
  • expr: Fix up VEC_PACK_TRUNC_EXPR expansion [PR101046]
Related show

Commit Message

Andrew Pinski via Gcc-patches June 15, 2021, 8:30 a.m.
Hi!

The following testcase ICEs, because we have a mode mismatch.
VEC_PACK_TRUNC_EXPR's operands have different modes from the result
(same vector mode size but twice as large element),
but we were passing non-NULL subtarget with the mode of the result
to the expansion of its arguments, so the VEC_PERM_EXPR in one of the
operands which had V8SImode operands and result had V16HImode target.

Fixed by clearing the subtarget if we are changing mode.

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

2021-06-15  Jakub Jelinek  <jakub@redhat.com>

	PR target/101046
	* expr.c (expand_expr_real_2) <case VEC_PACK_FIX_TRUNC_EXPR,
	case VEC_PACK_TRUNC_EXPR>: Clear subtarget when changing mode.

	* gcc.target/i386/pr101046.c: New test.


	Jakub

Comments

Richard Biener June 15, 2021, 8:57 a.m. | #1
On Tue, 15 Jun 2021, Jakub Jelinek wrote:

> Hi!

> 

> The following testcase ICEs, because we have a mode mismatch.

> VEC_PACK_TRUNC_EXPR's operands have different modes from the result

> (same vector mode size but twice as large element),

> but we were passing non-NULL subtarget with the mode of the result

> to the expansion of its arguments, so the VEC_PERM_EXPR in one of the

> operands which had V8SImode operands and result had V16HImode target.

> 

> Fixed by clearing the subtarget if we are changing mode.

> 

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


OK.

Thanks,
Richard.

> 2021-06-15  Jakub Jelinek  <jakub@redhat.com>

> 

> 	PR target/101046

> 	* expr.c (expand_expr_real_2) <case VEC_PACK_FIX_TRUNC_EXPR,

> 	case VEC_PACK_TRUNC_EXPR>: Clear subtarget when changing mode.

> 

> 	* gcc.target/i386/pr101046.c: New test.

> 

> --- gcc/expr.c.jj	2021-05-21 21:09:08.000000000 +0200

> +++ gcc/expr.c	2021-06-14 11:02:28.821342367 +0200

> @@ -9998,6 +9998,7 @@ expand_expr_real_2 (sepops ops, rtx targ

>      case VEC_PACK_SAT_EXPR:

>      case VEC_PACK_FIX_TRUNC_EXPR:

>        mode = TYPE_MODE (TREE_TYPE (treeop0));

> +      subtarget = NULL_RTX;

>        goto binop;

>  

>      case VEC_PACK_TRUNC_EXPR:

> @@ -10021,6 +10022,7 @@ expand_expr_real_2 (sepops ops, rtx targ

>  	  return eops[0].value;

>  	}

>        mode = TYPE_MODE (TREE_TYPE (treeop0));

> +      subtarget = NULL_RTX;

>        goto binop;

>  

>      case VEC_PACK_FLOAT_EXPR:

> --- gcc/testsuite/gcc.target/i386/pr101046.c.jj	2021-06-14 11:10:18.661701929 +0200

> +++ gcc/testsuite/gcc.target/i386/pr101046.c	2021-06-14 11:09:26.439439991 +0200

> @@ -0,0 +1,15 @@

> +/* PR target/101046 */

> +/* { dg-do compile } */

> +/* { dg-options "-ftree-ter -mavx512bw -mavx512vl" } */

> +

> +typedef unsigned short __attribute__((__vector_size__(16))) U;

> +typedef unsigned int __attribute__((__vector_size__(16))) V;

> +typedef unsigned int __attribute__((__vector_size__(32))) W;

> +

> +U

> +foo (void)

> +{

> +  return __builtin_convertvector (__builtin_shufflevector ((V){}, (W){},

> +							   0, 0, 1, 0,

> +							   5, 5, 0, 2), U);

> +}

> 

> 	Jakub

> 

> 


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

Patch

--- gcc/expr.c.jj	2021-05-21 21:09:08.000000000 +0200
+++ gcc/expr.c	2021-06-14 11:02:28.821342367 +0200
@@ -9998,6 +9998,7 @@  expand_expr_real_2 (sepops ops, rtx targ
     case VEC_PACK_SAT_EXPR:
     case VEC_PACK_FIX_TRUNC_EXPR:
       mode = TYPE_MODE (TREE_TYPE (treeop0));
+      subtarget = NULL_RTX;
       goto binop;
 
     case VEC_PACK_TRUNC_EXPR:
@@ -10021,6 +10022,7 @@  expand_expr_real_2 (sepops ops, rtx targ
 	  return eops[0].value;
 	}
       mode = TYPE_MODE (TREE_TYPE (treeop0));
+      subtarget = NULL_RTX;
       goto binop;
 
     case VEC_PACK_FLOAT_EXPR:
--- gcc/testsuite/gcc.target/i386/pr101046.c.jj	2021-06-14 11:10:18.661701929 +0200
+++ gcc/testsuite/gcc.target/i386/pr101046.c	2021-06-14 11:09:26.439439991 +0200
@@ -0,0 +1,15 @@ 
+/* PR target/101046 */
+/* { dg-do compile } */
+/* { dg-options "-ftree-ter -mavx512bw -mavx512vl" } */
+
+typedef unsigned short __attribute__((__vector_size__(16))) U;
+typedef unsigned int __attribute__((__vector_size__(16))) V;
+typedef unsigned int __attribute__((__vector_size__(32))) W;
+
+U
+foo (void)
+{
+  return __builtin_convertvector (__builtin_shufflevector ((V){}, (W){},
+							   0, 0, 1, 0,
+							   5, 5, 0, 2), U);
+}