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/113632] New: Range info for a^CST could be improved
Date: Sun, 28 Jan 2024 06:23:30 +0000	[thread overview]
Message-ID: <bug-113632-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 113632
           Summary: Range info for a^CST could be improved
           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:
```
void dummy();
_Bool f(unsigned long a)
{
        _Bool cmp = a > 8192;
        if (cmp) goto then; else goto e;
then:
        unsigned long t = __builtin_clzl(a); // [0,50] 
        t^=63; // [13,63]
        return t >= 13;
e:
  dummy();
  return 0;
}
```

Currently after the t^=63; we get:
```
  # RANGE [irange] int [1, 63] MASK 0x3f VALUE 0x0
  _7 = _1 ^ 63;
```

But this could/should be improved to [13,63].

If we change to using minus instead:
```
t = 63 - t;
```

We get the better range and the comparison (t >= 13) is optimized away.
```
Folding statement: t_10 = 63 - t_9;
Global Exported: t_10 = [irange] long unsigned int [13, 63] MASK 0x3f VALUE 0x0
Not folded
```

Yes this should up in real code, see the LLVM issue for more information on
that.

             reply	other threads:[~2024-01-28  6:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-28  6:23 pinskia at gcc dot gnu.org [this message]
2024-01-28  6:25 ` [Bug tree-optimization/113632] Range info for a^CSTP2-1 could be improved in some cases pinskia at gcc dot gnu.org
2024-03-04 14:53 ` amacleod at redhat dot com

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-113632-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).