public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] middle-end/105049 - fix uniform_vector_p and vector CTOR gimplification
Date: Fri, 25 Mar 2022 13:15:00 +0100 (CET)	[thread overview]
Message-ID: <15128pq9-98p-6n1q-855r-3q515071324@fhfr.qr> (raw)

On Fri, 25 Mar 2022, Richard Biener wrote:

> We have
> 
>   return VIEW_CONVERT_EXPR<U>( VEC_PERM_EXPR < {<<< Unknown tree: compound_literal_expr
>         V D.1984 = { 0 }; >>>, { 0 }} , {<<< Unknown tree: compound_literal_expr
>         V D.1985 = { 0 }; >>>, { 0 }} , { 0, 0 } >  & {(short int) SAVE_EXPR <c>, (short int) SAVE_EXPR <c>});
> 
> where we gimplify the init CTORs to
> 
>   _1 = {{ 0 }, { 0 }};
>   _2 = {{ 0 }, { 0 }};
> 
> instead of to vector constants.  That later runs into a bug in
> uniform_vector_p which doesn't handle CTORs of vector elements
> correctly.
> 
> The following adjusts uniform_vector_p to handle CTORs of vector
> elements and also makes sure to simplify the CTORs to VECTOR_CSTs
> during gimplification by re-ordering the simplification to after
> CTOR flag recomputation.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu.  At this
> point I'm leaning towards delaying the gimplification change
> to stage1 - do you agree?

I have now pushed the variant with just the tree.cc hunk.

Richard.

> Thanks,
> Richard.
> 
> 2022-03-25  Richard Biener  <rguenther@suse.de>
> 
> 	PR middle-end/105049
> 	* gimplify.cc (gimplify_init_constructor): First gimplify,
> 	then simplify the result to a VECTOR_CST.
> 	* tree.cc (uniform_vector_p): Recurse for VECTOR_CST or
> 	CONSTRUCTOR first elements.
> 
> 	* gcc/testsuite/gcc.dg/pr105049.c: New testcase.
> ---
>  gcc/gimplify.cc                 | 33 ++++++++++++++++-----------------
>  gcc/testsuite/gcc.dg/pr105049.c | 12 ++++++++++++
>  gcc/tree.cc                     |  2 ++
>  3 files changed, 30 insertions(+), 17 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/pr105049.c
> 
> diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
> index f62f150fc08..a866d4e6f56 100644
> --- a/gcc/gimplify.cc
> +++ b/gcc/gimplify.cc
> @@ -5390,6 +5390,22 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
>  	if (notify_temp_creation)
>  	  return GS_OK;
>  
> +	/* Vector types use CONSTRUCTOR all the way through gimple
> +	   compilation as a general initializer.  */
> +	FOR_EACH_VEC_SAFE_ELT (elts, ix, ce)
> +	  {
> +	    enum gimplify_status tret;
> +	    tret = gimplify_expr (&ce->value, pre_p, post_p, is_gimple_val,
> +				  fb_rvalue);
> +	    if (tret == GS_ERROR)
> +	      ret = GS_ERROR;
> +	    else if (TREE_STATIC (ctor)
> +		     && !initializer_constant_valid_p (ce->value,
> +						       TREE_TYPE (ce->value)))
> +	      TREE_STATIC (ctor) = 0;
> +	  }
> +	recompute_constructor_flags (ctor);
> +
>  	/* Go ahead and simplify constant constructors to VECTOR_CST.  */
>  	if (TREE_CONSTANT (ctor))
>  	  {
> @@ -5412,25 +5428,8 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
>  		TREE_OPERAND (*expr_p, 1) = build_vector_from_ctor (type, elts);
>  		break;
>  	      }
> -
> -	    TREE_CONSTANT (ctor) = 0;
>  	  }
>  
> -	/* Vector types use CONSTRUCTOR all the way through gimple
> -	   compilation as a general initializer.  */
> -	FOR_EACH_VEC_SAFE_ELT (elts, ix, ce)
> -	  {
> -	    enum gimplify_status tret;
> -	    tret = gimplify_expr (&ce->value, pre_p, post_p, is_gimple_val,
> -				  fb_rvalue);
> -	    if (tret == GS_ERROR)
> -	      ret = GS_ERROR;
> -	    else if (TREE_STATIC (ctor)
> -		     && !initializer_constant_valid_p (ce->value,
> -						       TREE_TYPE (ce->value)))
> -	      TREE_STATIC (ctor) = 0;
> -	  }
> -	recompute_constructor_flags (ctor);
>  	if (!is_gimple_reg (TREE_OPERAND (*expr_p, 0)))
>  	  TREE_OPERAND (*expr_p, 1) = get_formal_tmp_var (ctor, pre_p);
>        }
> diff --git a/gcc/testsuite/gcc.dg/pr105049.c b/gcc/testsuite/gcc.dg/pr105049.c
> new file mode 100644
> index 00000000000..b0518c6a181
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr105049.c
> @@ -0,0 +1,12 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fno-tree-forwprop" } */
> +
> +typedef short __attribute__((__vector_size__ (sizeof(short)))) V;
> +typedef short __attribute__((__vector_size__ (2*sizeof(short)))) U;
> +char c;
> +
> +U
> +foo (void)
> +{
> +  return __builtin_shufflevector ((V){}, (V){}, 0, 0) & c;
> +}
> diff --git a/gcc/tree.cc b/gcc/tree.cc
> index b8017af6cfc..ec200e9a7eb 100644
> --- a/gcc/tree.cc
> +++ b/gcc/tree.cc
> @@ -10266,6 +10266,8 @@ uniform_vector_p (const_tree vec)
>        if (i != nelts)
>  	return NULL_TREE;
>  
> +      if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
> +	return uniform_vector_p (first);
>        return first;
>      }
>  
> 

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

             reply	other threads:[~2022-03-25 12:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 12:15 Richard Biener [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-03-25  9:51 Richard Biener
2022-04-06 15:31 ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15128pq9-98p-6n1q-855r-3q515071324@fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).