public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marc Glisse <marc.glisse@inria.fr>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: Simple reassoc transforms in match.pd
Date: Wed, 28 Jun 2017 07:51:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.20.1706271148460.1823@stedding.saclay.inria.fr> (raw)
In-Reply-To: <CAFiYyc256MHzqBj4dNDeO_s96DNNZSQHFY-vsVnKDQO65SN1Ow@mail.gmail.com>

On Mon, 26 Jun 2017, Richard Biener wrote:

> On Fri, Jun 23, 2017 at 3:12 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
>> Hello,
>>
>> here are a few simple transformations, mostly useful for types with
>> undefined overflow where we do not have reassoc.
>>
>> I did not name the testcase reassoc-* to leave that namespace to the realloc
>> pass, and -fno-tree-reassoc is just in case someone ever enhances that
>> pass...
>
> You probably saw
>
>  /* (T)(P + A) - (T)(P + B) -> (T)A - (T)B */
>  (for add (plus pointer_plus)
>   (simplify
>    (minus (convert (add @@0 @1))
>     (convert (add @0 @2)))

And

/* X + Z < Y + Z is the same as X < Y when there is no overflow.  */
[...]
/* For equality and subtraction, this is also true with wrapping overflow.  */
(for op (eq ne minus)
  (simplify
   (op (plus:c @0 @2) (plus:c @1 @2))
   (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
        && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
            || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))))
    (op @0 @1))))

> as you didn't duplicate its functionality.  It misses a :c in one of
> the adds for the

For some other transform, I was tempted to write
(for op (plus:c minus) ...
i.e. use a different commutativity for different operations, but that's
not supported.

> PLUS_EXPR case though so it might be worth splitting that out near to your
> added cases?  Which then raises the question of handling conversions around
> the inner ops in your patterns?

It is probably possible to merge / generalize some of those transforms 
(although we sometimes do strange assumptions about overflow with pointers 
that may not match with the usual integer case). In this case, I was 
interested in the undefined-overflow case (more precisely the sum of 2 
pointer_diff), and as soon as one operation is done in a wrapping type, 
the result has to be as well (which could still be handled in the same 
transformation).

-- 
Marc Glisse

      reply	other threads:[~2017-06-28  7:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23 13:12 Marc Glisse
2017-06-26 10:16 ` Richard Biener
2017-06-28  7:51   ` Marc Glisse [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=alpine.DEB.2.20.1706271148460.1823@stedding.saclay.inria.fr \
    --to=marc.glisse@inria.fr \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.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).