public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/107881] (a <= b) == (b >= a) should be optimized to (a == b)
Date: Mon, 11 Sep 2023 21:45:35 +0000	[thread overview]
Message-ID: <bug-107881-4-cfVXwi2Fj9@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107881-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107881

--- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For the ^/!= case here are the missing optimizations (note == can be handled
too):
```
int ltgtxor(int a, int b)
{
        _Bool c = a < b;
        _Bool d = a > b;
        return c ^ d; // a != b
}

int lteqxor(int a, int b)
{
        _Bool c = a < b;
        _Bool d = a == b;
        return c ^ d; // a <= b (basically | here)
}

int ltnexor(int a, int b)
{
        _Bool c = a < b;
        _Bool d = a != b;
        return c ^ d; // a > b
}
int legexor(int a, int b)
{
        _Bool c = a <= b;
        _Bool d = a >= b;
        return c ^ d; // a != b
}

int leeqxor(int a, int b)
{
        _Bool c = a <= b;
        _Bool d = a == b;
        return c ^ d; // a < b
}

int lenexor(int a, int b)
{
        _Bool c = a <= b;
        _Bool d = a != b;
        return c ^ d; // a >= b
}

```

Match pattern I think:
```
(for op (bit_xor ne)
 (for cmp1 (lt lt lt le le le)
      cmp2 (gt eq ne ge eq ne)
      rcmp (ne le gt ne lt ge)
  (simplify
   (op:c (cmp1:c @0 @1) (cmp2:c @0 @1))
   (rcmp @0 @1))))
```

For eq:
```
(for cmp1 (lt lt lt le le le)
     cmp2 (gt eq ne ge eq ne)
     rcmp (eq ge le eq ge lt)
 (simplify
  (eq:c (cmp1:c @0 @1) (cmp2:c @0 @1))
  (rcmp @0 @1)))
```

Both of these this check though:
(INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))

  parent reply	other threads:[~2023-09-11 21:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-26 18:18 [Bug tree-optimization/107881] New: " pinskia at gcc dot gnu.org
2022-11-26 18:20 ` [Bug tree-optimization/107881] " pinskia at gcc dot gnu.org
2022-11-26 19:51 ` pinskia at gcc dot gnu.org
2022-11-26 19:56 ` pinskia at gcc dot gnu.org
2022-11-26 19:57 ` pinskia at gcc dot gnu.org
2022-11-26 20:26 ` pinskia at gcc dot gnu.org
2022-11-28  2:22 ` pinskia at gcc dot gnu.org
2022-11-28  2:33 ` pinskia at gcc dot gnu.org
2022-11-28  2:50 ` pinskia at gcc dot gnu.org
2023-01-19 15:00 ` pinskia at gcc dot gnu.org
2023-08-28 20:35 ` pinskia at gcc dot gnu.org
2023-08-28 20:36 ` pinskia at gcc dot gnu.org
2023-08-28 21:30 ` pinskia at gcc dot gnu.org
2023-08-28 21:31 ` pinskia at gcc dot gnu.org
2023-08-29  4:07 ` pinskia at gcc dot gnu.org
2023-09-11 21:45 ` pinskia at gcc dot gnu.org [this message]
2023-09-12  4:23 ` pinskia at gcc dot gnu.org
2023-09-12 15:02 ` cvs-commit at gcc dot gnu.org
2023-09-12 15:03 ` pinskia at gcc dot gnu.org

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=bug-107881-4-cfVXwi2Fj9@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).