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/110010] New: (a>>N) != (b>>N) is not optimized to (a^b) >= (1<<N)
Date: Sun, 28 May 2023 00:31:46 +0000	[thread overview]
Message-ID: <bug-110010-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110010
           Summary: (a>>N) != (b>>N) is not optimized to (a^b) >= (1<<N)
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
#define N 5
unsigned f(unsigned a, unsigned b)
{
  return (a>>N) != (b>>N);
}
```
This could be optimized down to just `return (a^b) <= (1<<N)`.

This shows up in the testsuite as a pr94718-5.c failure when you add the
following 2 match patterns:
(simplify
 (negate (convert (lt @0 integer_zerop)))
 (if (!TYPE_UNSIGNED (TREE_TYPE (@0)))
  (with { tree type_unsigned = unsigned_type_for (TREE_TYPE (@0)); }
   (if (types_match (type, TREE_TYPE (@0)) || types_match (type_unsigned,
type))
    (convert (rshift @0
                     { build_int_cst (integer_type_node,
                                      element_precision (type) - 1); }))))))
(simplify
 (convert (lt @0 integer_zerop))
 (if (!TYPE_UNSIGNED (TREE_TYPE (@0)))
  (with { tree type_unsigned = unsigned_type_for (TREE_TYPE (@0)); }
   (if (types_match (type, TREE_TYPE (@0)) || types_match (type_unsigned,
type))
   (convert (rshift (convert:type_unsigned @0)
                    { build_int_cst (integer_type_node,
                                     element_precision (type) - 1); }))))))

             reply	other threads:[~2023-05-28  0:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-28  0:31 pinskia at gcc dot gnu.org [this message]
2023-05-28  0:37 ` [Bug tree-optimization/110010] " pinskia at gcc dot gnu.org
2023-09-04  7:57 ` 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-110010-4@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).