public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Arjun Shankar <arjun@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] tree-optimization/94899: Remove "+ 0x80000000" in int comparisons
Date: Tue, 1 Feb 2022 08:18:49 +0100	[thread overview]
Message-ID: <CAFiYyc0J20qJ9bgQRoZ74in_yZO+Qs8fUaB+oZO5ksp1xicV_A@mail.gmail.com> (raw)
In-Reply-To: <CAG_osabNsrTv3OrgNFP=BH6BdxT3PJ+GZSOrcrwOFwUbSyLvCA@mail.gmail.com>

On Tue, Feb 1, 2022 at 5:54 AM Arjun Shankar via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Expressions of the form "X + CST < Y + CST" where X and Y are of int
> type and CST is of unsigned type with only the MSB on can be simplified
> to "X < Y" because "X + 0x80000000" increases monotonically with X.

+/* As a special case, X + C < Y + C is the same as X < Y even with wrapping
+   overflow if X and Y are signed integers of the same size, and C is an
+   unsigned constant with all bits except MSB set to 0 and size >= that of
+   X/Y.  */
+(for op (lt le ge gt)
+ (simplify
+  (op (plus:c (convert@0 @1) @4) (plus:c (convert@2 @3) @4))
+  (if (CONSTANT_CLASS_P (@4)
+       && TYPE_UNSIGNED (TREE_TYPE (@4))

why include (convert ..) here?  It looks like you could do without,
merging the special case with the preceding pattern and let a followup
pattern simplify (lt (convert @1) (convert @2)) instead?

> gcc/
>         * match.pd (X + C < Y + C -> X < Y, if C is 0x80000000): New
>         simplification.
> gcc/testsuite/
>         * gcc.dg/pr94899.c: New test.
> ---
>  gcc/match.pd                   | 18 ++++++++++++++++++
>  gcc/testsuite/gcc.dg/pr94899.c | 28 ++++++++++++++++++++++++++++
>  2 files changed, 46 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/pr94899.c

  reply	other threads:[~2022-02-01  7:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01  4:53 Arjun Shankar
2022-02-01  7:18 ` Richard Biener [this message]
2022-02-01 15:21   ` Arjun Shankar
2022-02-02  9:20     ` Richard Biener
2022-02-02 15:55       ` Arjun Shankar
2022-02-03  3:50       ` [PATCH v2] " Arjun Shankar
2022-02-04 11:14         ` Richard Biener
2022-02-04 11:50           ` Jakub Jelinek
2022-02-04 13:21             ` 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=CAFiYyc0J20qJ9bgQRoZ74in_yZO+Qs8fUaB+oZO5ksp1xicV_A@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=arjun@redhat.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).