public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Thomas dot Koenig at online dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/20517] New: bit shift/mask optimization potential
Date: Thu, 17 Mar 2005 13:17:00 -0000	[thread overview]
Message-ID: <20050317131718.20517.Thomas.Koenig@online.de> (raw)

$ cat shift.c
#include <stdio.h>

#define OFFSET 4
#define MASK 0xf0

int main()
{
    unsigned int f,g;
    scanf("%u",&f);
    if ((f & MASK) >> OFFSET == 1) {
        printf("success\n");
    }
    return 0;
}
$ gcc -S -O2 -fdump-tree-optimized shift.c
$ tail -20 shift.c.t66.optimized
  unsigned int g;
  unsigned int f;
  int D.1807;
  unsigned int D.1806;
  unsigned int D.1805;
  unsigned int f.10;

<bb 0>:
  scanf (&"%u"[0], &f);
  if ((f & 240) >> 4 == 1) goto <L0>; else goto <L1>;

<L0>:;
  printf (&"success\n"[0]);

<L1>:;
  return 0;

}


$ gcc -v
Using built-in specs.
Target: ia64-unknown-linux-gnu
Configured with: ../gcc-4.1-20050306/configure --prefix=/home/zfkts
--enable-languages=c,f95 --disable-optimization
Thread model: posix
gcc version 4.1.0 20050306 (experimental)

The expression (f & 0xf0) >> 4 == 1 could be optimized
to f & 0xf == 1 << 4.

Code like that occurs in the libgfortan library.

-- 
           Summary: bit shift/mask optimization potential
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Thomas dot Koenig at online dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20517


             reply	other threads:[~2005-03-17 13:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-17 13:17 Thomas dot Koenig at online dot de [this message]
2005-03-17 13:34 ` [Bug middle-end/20517] " Thomas dot Koenig at online dot de
2005-03-17 17:21 ` [Bug tree-optimization/20517] " pinskia at gcc dot gnu dot org
2005-07-23 21:07 ` phython at gcc dot gnu dot 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=20050317131718.20517.Thomas.Koenig@online.de \
    --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).