public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v2 1/2] match.pd: reassociate multiplications
Date: Tue, 25 Jul 2017 14:18:00 -0000	[thread overview]
Message-ID: <CAFiYyc1TMdT9w_gvcU4Skd3zk1bbdVwy6Arfm6eyspNxv3FUOg@mail.gmail.com> (raw)
In-Reply-To: <20170721155550.5846-1-amonakov@ispras.ru>

On Fri, Jul 21, 2017 at 5:55 PM, Alexander Monakov <amonakov@ispras.ru> wrote:
> Previous revision here: https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00889.html
>
> Reassociate (X * CST) * Y to (X * Y) * CST, this pushes constants in
> multiplication chains to outermost factors, where they can be combined.
>
> Changed in this revision:
> - remove !TYPE_OVERFLOW_SANITIZED and !TYPE_SATURATING checks;
>  (in previous discussion Richard indicated that introducing false negatives
>   in UBSAN by concealing signed overflow is not a concern, and saturating
>   types shouldn't appear here because the constant operand should be FIXED_CST)
>
> The checks for @1 being 0 or -1 remain as they are required for correctness,
> but since this rule is ordered after the simpler rules that fold X * {0, -1},
> those checks are always false at runtime.

Ok.

Thanks,
Richard.

>
>         * match.pd ((X * CST) * Y): Reassociate to (X * Y) * CST.
> testsuite/
>         * gcc.dg/tree-ssa/assoc-2.c: New testcase.
>
> ---
>  gcc/match.pd                            | 8 ++++++++
>  gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c | 8 ++++++++
>  2 files changed, 16 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 7f5807c..39e1e5c 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -2213,6 +2213,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   (mult @0 integer_minus_onep)
>   (negate @0))
>
> +/* Reassociate (X * CST) * Y to (X * Y) * CST.  This does not introduce
> +   signed overflow for CST != 0 && CST != -1.  */
> +(simplify
> + (mult:c (mult:s @0 INTEGER_CST@1) @2)
> + (if (TREE_CODE (@2) != INTEGER_CST
> +      && !integer_zerop (@1) && !integer_minus_onep (@1))
> +  (mult (mult @0 @2) @1)))
> +
>  /* True if we can easily extract the real and imaginary parts of a complex
>     number.  */
>  (match compositional_complex
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c b/gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c
> new file mode 100644
> index 0000000..a92c882
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-gimple-raw -fdump-tree-optimized-raw" } */
> +
> +int f0(int a, int b){
> +  return a * 33 * b * 55;
> +}
> +
> +/* { dg-final { scan-tree-dump-times "mult_expr" 2 "gimple" } } */
> --
> 1.8.3.1
>

      parent reply	other threads:[~2017-07-25 14:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21 15:56 Alexander Monakov
2017-07-21 15:56 ` [PATCH v2 2/2] combine successive multiplications by constants Alexander Monakov
2017-07-25 14:19   ` Richard Biener
2017-07-25 14:18 ` 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=CAFiYyc1TMdT9w_gvcU4Skd3zk1bbdVwy6Arfm6eyspNxv3FUOg@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=amonakov@ispras.ru \
    --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).