public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/108949] New: Optimize shift counts
Date: Mon, 27 Feb 2023 12:36:00 +0000	[thread overview]
Message-ID: <bug-108949-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108949
           Summary: Optimize shift counts
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

From https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108941#c13 :
Because various backends support shift count truncation or have patterns that
recognize it in certain cases, I wonder if middle-end couldn't canonicalize
shift count (N + x)
where N is multiple of shift first operand's bitsize B to x & (B - 1) where the
latter
is often optimized away while the former is not.
For similar N - x it is more questionable because N - x is a single GIMPLE
statement while -y & (B - 1) are two; perhaps it could be done at expansion
time though.
In generic code at least for SHIFT_COUNT_TRUNCATED targets, otherwise maybe if
one can easily detect negation optab and subtraction instruction not accepting
immediate for the minuend.  Or handle all this in each of the backends?

int
foo (int x, int y)
{
  return x << (y & 31);
}

int
bar (int x, int y)
{
  return x << (32 + y);
}

int
baz (int x, int y)
{
  return x << (-y & 31);
}

int
qux (int x, int y)
{
  return x << (32 - y);
}

             reply	other threads:[~2023-02-27 12:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27 12:36 jakub at gcc dot gnu.org [this message]
2023-02-27 16:28 ` [Bug tree-optimization/108949] " pinskia at gcc dot gnu.org
2023-02-28 10:39 ` rguenth 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-108949-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).