public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Jeff Law <jeffreyalaw@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] match.pd: Add bitwise and pattern [PR106243]
Date: Thu, 4 Aug 2022 09:08:59 +0200	[thread overview]
Message-ID: <CAFiYyc2FFnrHZa0HueQDoH+u=ikb_-sAWi1MzMwtAi-J5SfBtw@mail.gmail.com> (raw)
In-Reply-To: <527a41b9-92a1-e662-da89-3176b77524fe@gmail.com>

On Thu, Aug 4, 2022 at 12:40 AM Jeff Law via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
>
>
> On 8/3/2022 2:44 PM, Prathamesh Kulkarni via Gcc-patches wrote:
> > On Thu, 4 Aug 2022 at 00:41, Sam Feifer via Gcc-patches
> > <gcc-patches@gcc.gnu.org> wrote:
> >> This patch adds a new optimization to match.pd. The pattern, -x & 1,
> >> now gets simplified to x & 1, reducing the number of instructions
> >> produced.
> > Hi Sam,
> > No comments on patch, but wondering if we can similarly add another pattern to
> > simplify abs(x) & 1 -> x & 1 ?
> > Currently we don't appear to do it on GIMPLE:
> >
> > __attribute__((noipa))
> > int f1 (int x)
> > {
> >    return __builtin_abs (x) & 1;
> > }
> >
> > .optimized dump shows:
> >    _1 = ABS_EXPR <x_2(D)>;
> >    _3 = _1 & 1;
> >    return _3;
> >
> > altho combine simplifies it to x & 1 on RTL, resulting in code-gen:
> > f1:
> >          and     w0, w0, 1
> >          ret
> Doesn't the abs(x) & mask simplify to x & mask for any mask where the
> sign bit of x is off -- including cases where mask isn't necessarily a
> compile-time constant, but we have range data which allows us to know
> that x's sign bit is off in mask.

You can use tree_expr_nonnegative_p but then that does simplify
abs(x) to x already.  But sure, handling abs() like negate sounds it
should work.

Richard,

> jeff
>
>
>

  reply	other threads:[~2022-08-04  7:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03 19:10 Sam Feifer
2022-08-03 20:44 ` Prathamesh Kulkarni
2022-08-03 22:39   ` Jeff Law
2022-08-04  7:08     ` Richard Biener [this message]
2022-08-04 12:34     ` Michael Matz
2022-08-04  7:06 ` 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='CAFiYyc2FFnrHZa0HueQDoH+u=ikb_-sAWi1MzMwtAi-J5SfBtw@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@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).