public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Richard Biener <rguenther@suse.de>
Subject: Re: [PATCH] tree-optimization/105250 - adjust fold_convertible_p PR105140 fix
Date: Wed, 13 Apr 2022 09:04:02 +0100	[thread overview]
Message-ID: <mptzgkpo1e5.fsf@arm.com> (raw)
In-Reply-To: <20220413074636.9269E13A91@imap2.suse-dmz.suse.de> (Richard Biener via Gcc-patches's message of "Wed, 13 Apr 2022 09:46:36 +0200 (CEST)")

Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> The following reverts the original PR105140 fix and goes for instead
> applying the additional fold_convert constraint for VECTOR_TYPE
> conversions also to fold_convertible_p.  I did not try sanitizing
> all of this at this point.
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
>
> 2022-04-13  Richard Biener  <rguenther@suse.de>
>
> 	PR tree-optimization/105250
> 	* fold-const.cc (fold_convertible_p): Revert
> 	r12-7979-geaaf77dd85c333, instead check for size equality
> 	of the vector types involved.

This doesn't look right, and I think it'll break SVE.  For one
thing, the tree_int_cst_equal check is bound to fail for
variable-length vectors.

But also, the idea was to allow element-wise conversions between
different vector sizes.  For example, you can do a nop/convert
from V4SI to V4DI, which converts 4 SIs to 4 DIs.  This is used
a lot for conversions to and from “partial” SVE vectors, where smaller
elements are stored in wider containers.

Thanks,
Richard

>
> 	* gcc.dg/pr105250.c: New testcase.
> ---
>  gcc/fold-const.cc               |  7 +++----
>  gcc/testsuite/gcc.dg/pr105250.c | 29 +++++++++++++++++++++++++++++
>  2 files changed, 32 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/pr105250.c
>
> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
> index 7226bc5af01..a57ad0739fb 100644
> --- a/gcc/fold-const.cc
> +++ b/gcc/fold-const.cc
> @@ -2379,13 +2379,12 @@ build_zero_vector (tree type)
>    return build_vector_from_val (type, t);
>  }
>  
> -/* Returns true, if ARG, an operand or a type, is convertible to TYPE
> -   using a NOP_EXPR.  */
> +/* Returns true, if ARG is convertible to TYPE using a NOP_EXPR.  */
>  
>  bool
>  fold_convertible_p (const_tree type, const_tree arg)
>  {
> -  const_tree orig = TYPE_P (arg) ? arg : TREE_TYPE (arg);
> +  const_tree orig = TREE_TYPE (arg);
>  
>    if (type == orig)
>      return true;
> @@ -2417,7 +2416,7 @@ fold_convertible_p (const_tree type, const_tree arg)
>        return (VECTOR_TYPE_P (orig)
>  	      && known_eq (TYPE_VECTOR_SUBPARTS (type),
>  			   TYPE_VECTOR_SUBPARTS (orig))
> -	      && fold_convertible_p (TREE_TYPE (type), TREE_TYPE (orig)));
> +	      && tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
>  
>      default:
>        return false;
> diff --git a/gcc/testsuite/gcc.dg/pr105250.c b/gcc/testsuite/gcc.dg/pr105250.c
> new file mode 100644
> index 00000000000..665dd95d8cb
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr105250.c
> @@ -0,0 +1,29 @@
> +/* { dg-do compile } */
> +/* { dg-options "-w -Wno-psabi -O2" } */
> +
> +typedef int __attribute__((__vector_size__(4))) T;
> +typedef int __attribute__((__vector_size__(8))) U;
> +typedef int __attribute__((__vector_size__(16))) V;
> +typedef int __attribute__((__vector_size__(32))) W;
> +typedef _Float32 __attribute__((__vector_size__(16))) F;
> +typedef _Float64 __attribute__((__vector_size__(32))) G;
> +void foo();
> +
> +foo(int, int, int, int, U, U, V, V, W, W, int,
> +     T, int, U, U, V, V, W, W, T,
> +     T, int, U, U, V, V, W, W, T,
> +     T, int, W, W, T, T, int, int, int,
> +     int, int, int, W, int, int, int, int, int, int,
> +     V, W, T, int, int, U, F, int, int, int,
> +     int, int, int, G)
> +{
> +  foo(0, 0, 0, 0, (U){}, (U){}, (V){}, (V){}, (W){},
> +       (W){}, 2, (T){}, 0, 0, 0, 0, (U){}, (U){},
> +       (V){}, (V){}, (W){}, (W){}, (T){},
> +       (T){}, 0, 0, 0, 0, (U){}, (U){}, (V){},
> +       (V){}, (W){}, (W){}, (T){}, (T){}, 0, 0, 0,
> +       0, 0, 0, (T){},
> +       (T){}, (W){},
> +       (W){}, (T){}, (T){}, 0, 0, 0, 0, 0, 0, (W){},
> +       (V){}, (W){}, (T){}, 0, 0, (U){}, (F){});
> +}

  reply	other threads:[~2022-04-13  8:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-13  7:46 Richard Biener
2022-04-13  8:04 ` Richard Sandiford [this message]
2022-04-13  8:48   ` Richard Biener
2022-04-13  8:55     ` Richard Biener
2022-04-13  9:06       ` Richard Biener
2022-04-13 10:59     ` Richard Sandiford

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=mptzgkpo1e5.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /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).