public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: Optimize combination of comparisons to dec+compare
Date: Thu, 10 Dec 2020 09:21:16 +0100	[thread overview]
Message-ID: <CAFiYyc3f8FonGFLv=ZjK5VryNRbU3cWWVz1Bqys3tjs9maPYAw@mail.gmail.com> (raw)
In-Reply-To: <BYAPR21MB1351C483157540CEAC10F41391CB1@BYAPR21MB1351.namprd21.prod.outlook.com>

On Thu, Dec 10, 2020 at 1:52 AM Eugene Rozenfeld via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This patch adds a pattern for optimizing
> x < y || x == XXX_MIN to x <= y-1
> if y is an integer with TYPE_OVERFLOW_WRAPS.

Do we already handle x < y || x <= CST to x <= y - CST?
That is, the XXX_MIN case is just a special-case of generic
anti-range testing?  For anti-range testing with signed types
we pun to unsigned when possible.

> This fixes pr96674.
>
> Tested on x86_64-pc-linux-gnu.
>
> For this function
>
> bool f(unsigned a, unsigned b)
> {
>     return (b == 0) | (a < b);
> }
>
> the code without the patch is
>
> test   esi,esi
> sete   al
> cmp    esi,edi
> seta   dl
> or     eax,edx
> ret
>
> the code with the patch is
>
> sub    esi,0x1
> cmp    esi,edi
> setae  al
> ret
>
> Eugene
>
> gcc/
> PR tree-optimization/96674
> * match.pd: New pattern x < y || x == XXX_MIN --> x <= y - 1
>
> gcc/testsuite
> * gcc.dg/pr96674.c: New test.
>

  reply	other threads:[~2020-12-10  8:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10  0:51 Eugene Rozenfeld
2020-12-10  8:21 ` Richard Biener [this message]
2020-12-15 22:05 Eugene Rozenfeld
2020-12-22 23:01 ` Eugene Rozenfeld

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='CAFiYyc3f8FonGFLv=ZjK5VryNRbU3cWWVz1Bqys3tjs9maPYAw@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=Eugene.Rozenfeld@microsoft.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).