public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Christophe Lyon <christophe.lyon@linaro.org>
To: Richard Biener <rguenther@suse.de>
Cc: gcc Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] CSE negated multiplications and divisions
Date: Fri, 18 Sep 2020 14:39:43 +0200	[thread overview]
Message-ID: <CAKdteOYMHroXy0uLWMzr8DyDTy3wszhdMudP1+QgTK5AOA1LAA@mail.gmail.com> (raw)
In-Reply-To: <nycvar.YFH.7.76.2009171320180.3323@elmra>

On Thu, 17 Sep 2020 at 13:20, Richard Biener <rguenther@suse.de> wrote:
>
> This adds the capability to look for available negated multiplications
> and divisions, replacing them with cheaper negates.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
>

This patch caused a regression in fortran, I filed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97109


> 2020-09-17  Richard Biener  <rguenther@suse.de>
>
>         * tree-ssa-sccvn.c (visit_nary_op): Value-number multiplications
>         and divisions to negates of available negated forms.
>
>         * gcc.dg/tree-ssa/ssa-fre-88.c: New testcase.
> ---
>  gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c | 18 +++++++++++
>  gcc/tree-ssa-sccvn.c                       | 35 ++++++++++++++++++++++
>  2 files changed, 53 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c
>
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c
> new file mode 100644
> index 00000000000..15d2ca05e65
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c
> @@ -0,0 +1,18 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-fre1" } */
> +
> +double y[2];
> +void foo (double x)
> +{
> +  y[0] = x * -3.;
> +  y[1] = x * 3.;
> +}
> +void bar (double x, double z)
> +{
> +  y[0] = -z / x;
> +  y[1] = z / x;
> +}
> +
> +/* { dg-final { scan-tree-dump-times " \\* " 1 "fre1" } } */
> +/* { dg-final { scan-tree-dump-times " / " 1 "fre1" } } */
> +/* { dg-final { scan-tree-dump-times "= -_" 2 "fre1" } } */
> diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
> index 8fbb1dd46d1..64f1e8c9160 100644
> --- a/gcc/tree-ssa-sccvn.c
> +++ b/gcc/tree-ssa-sccvn.c
> @@ -4824,6 +4824,40 @@ visit_nary_op (tree lhs, gassign *stmt)
>             }
>         }
>        break;
> +    case RDIV_EXPR:
> +    case TRUNC_DIV_EXPR:
> +    case MULT_EXPR:
> +      /* Match up ([-]a){/,*}([-])b with v=a{/,*}b, replacing it with -v.  */
> +      if (! HONOR_SIGN_DEPENDENT_ROUNDING (type))
> +       {
> +         tree rhs[2];
> +         rhs[0] = rhs1;
> +         rhs[1] = gimple_assign_rhs2 (stmt);
> +         for (unsigned i = 0; i <= 1; ++i)
> +           {
> +             unsigned j = i == 0 ? 1 : 0;
> +             tree ops[2];
> +             gimple_match_op match_op (gimple_match_cond::UNCOND,
> +                                       NEGATE_EXPR, type, rhs[i]);
> +             ops[i] = vn_nary_build_or_lookup_1 (&match_op, false);
> +             ops[j] = rhs[j];
> +             if (ops[i]
> +                 && (ops[0] = vn_nary_op_lookup_pieces (2, code,
> +                                                        type, ops, NULL)))
> +               {
> +                 gimple_match_op match_op (gimple_match_cond::UNCOND,
> +                                           NEGATE_EXPR, type, ops[0]);
> +                 result = vn_nary_build_or_lookup (&match_op);
> +                 if (result)
> +                   {
> +                     bool changed = set_ssa_val_to (lhs, result);
> +                     vn_nary_op_insert_stmt (stmt, result);
> +                     return changed;
> +                   }
> +               }
> +           }
> +       }
> +      break;
>      default:
>        break;
>      }
> @@ -5739,6 +5773,7 @@ eliminate_dom_walker::eliminate_insert (basic_block bb,
>    if (!stmt
>        || (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
>           && gimple_assign_rhs_code (stmt) != VIEW_CONVERT_EXPR
> +         && gimple_assign_rhs_code (stmt) != NEGATE_EXPR
>           && gimple_assign_rhs_code (stmt) != BIT_FIELD_REF
>           && (gimple_assign_rhs_code (stmt) != BIT_AND_EXPR
>               || TREE_CODE (gimple_assign_rhs2 (stmt)) != INTEGER_CST)))
> --
> 2.26.2

  reply	other threads:[~2020-09-18 12:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17 11:20 Richard Biener
2020-09-18 12:39 ` Christophe Lyon [this message]
2020-09-18 23:43 ` Segher Boessenkool
2020-09-21  7:16   ` Richard Biener

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=CAKdteOYMHroXy0uLWMzr8DyDTy3wszhdMudP1+QgTK5AOA1LAA@mail.gmail.com \
    --to=christophe.lyon@linaro.org \
    --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).