public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Andrew Pinski <apinski@marvell.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix PR tree-optimization/103228 and 103228: folding of (type) X op CST where type is a nop convert
Date: Tue, 16 Nov 2021 10:52:57 +0100	[thread overview]
Message-ID: <CAFiYyc3Xe9+-9Ksz19CLVWBLra6ixTL28dvVwh0-xy+_edG6dQ@mail.gmail.com> (raw)
In-Reply-To: <1637033711-17785-1-git-send-email-apinski@marvell.com>

On Tue, Nov 16, 2021 at 4:36 AM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> Currently we fold (type) X op CST into (type) (X op ((type-x) CST)) when the conversion widens
> but not when the conversion is a nop. For the same reason why we move the widening conversion
> (the possibility of removing an extra conversion), we should do the same if the conversion is a
> nop.
>
> OK? Boostrapped and tested on x86_64-linux-gnu with no regressions.
>
>         PR tree-optimization/103228
>         PR tree-optimization/55177
>
> gcc/ChangeLog:
>
>         * match.pd ((type) X bitop CST): Also do this
>         transformation for nop conversions.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/tree-ssa/pr103228-1.c: New test.
>         * gcc.dg/tree-ssa/pr55177-1.c: New test.
> ---
>  gcc/match.pd                               |  2 +-
>  gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c | 11 +++++++++++
>  gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c  | 14 ++++++++++++++
>  3 files changed, 26 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index a0e9a82e4c4..dc3d5054583 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1615,7 +1615,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>         && (bitop != BIT_AND_EXPR || GIMPLE)
>         && (/* That's a good idea if the conversion widens the operand, thus
>               after hoisting the conversion the operation will be narrower.  */

Can you please adjust the comment?  OK with that change.

> -          TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type)
> +          TYPE_PRECISION (TREE_TYPE (@0)) <= TYPE_PRECISION (type)
>            /* It's also a good idea if the conversion is to a non-integer
>               mode.  */
>            || GET_MODE_CLASS (TYPE_MODE (type)) != MODE_INT
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c
> new file mode 100644
> index 00000000000..a7539819cf2
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +int f(int a, int b)
> +{
> +  b|=1u;
> +  b|=2;
> +  return b;
> +}
> +/* { dg-final { scan-tree-dump-times "\\\| 3" 1 "optimized"} } */
> +/* { dg-final { scan-tree-dump-times "\\\| 1" 0 "optimized"} } */
> +/* { dg-final { scan-tree-dump-times "\\\| 2" 0 "optimized"} } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c
> new file mode 100644
> index 00000000000..de1a264345c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +extern int x;
> +
> +void foo(void)
> +{
> +  int a = __builtin_bswap32(x);
> +  a &= 0x5a5b5c5d;
> +  x = __builtin_bswap32(a);
> +}
> +
> +/* { dg-final { scan-tree-dump-times "__builtin_bswap32" 0 "optimized"} } */
> +/* { dg-final { scan-tree-dump-times "& 1566333786" 1 "optimized"} } */
> +/* { dg-final { scan-tree-dump-times "& 1515936861" 0 "optimized"} } */
> --
> 2.17.1
>

      reply	other threads:[~2021-11-16  9:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16  3:35 apinski
2021-11-16  9:52 ` Richard Biener [this message]

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=CAFiYyc3Xe9+-9Ksz19CLVWBLra6ixTL28dvVwh0-xy+_edG6dQ@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=apinski@marvell.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).