public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@airs.com>
To: "Matt Lee" <reachmatt.lee@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Question about RTL for bitwise AND
Date: Thu, 13 Apr 2006 20:29:00 -0000	[thread overview]
Message-ID: <m3mzepkyn7.fsf@gossamer.airs.com> (raw)
In-Reply-To: <e94302560604130957y4241c76cp48ffafbe7150af81@mail.gmail.com>

"Matt Lee" <reachmatt.lee@gmail.com> writes:

>  I am using powerpc-eabi-gcc (version 3.4.1) and I have a question
> about the RTL that is produced for,
> 
>  test.c
>  int a;
> 
>  if (a & 2) {
>   // Do something
>  } else
>   // Do something else
>  }
> 
> 
>  I see in test.c.01.rtl,
> 
>  (insn 12 11 13 (set (reg:SI 122)
>          (lshiftrt:SI (reg:SI 121)
>              (const_int 1 [0x1]))) -1 (nil)
>      (nil))
> 
>  (insn 13 12 14 (parallel [
>              (set (reg:SI 123)
>                  (and:SI (reg:SI 122)
>                      (const_int 1 [0x1])))
>              (clobber (scratch:CC))
>          ]) -1 (nil)
>      (nil))
> 
> 
>  My question is, why is a logical shift right required? Wouldn't a
> direct bit-wise AND with const_int 2 suffice?

In general this kind of decision is made based on target specific
costs.  See prefer_and_bit_test in dojump.c.

For the PowerPC, you should look at later optimization passes.  It
seems possible that the two instructions above will get combined into
a single rlwinm instruction.  Although I haven't tried it.

>  This is causing problems in my (other) port where I can do only
> single-bit shifts. In the worst case, a & 0x80000000 the final
> assembly contains 31 right shifts. This is a big optimization problem.

Fix your costs to indicate this.

Ian

  reply	other threads:[~2006-04-13 20:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-13 16:57 Matt Lee
2006-04-13 20:29 ` Ian Lance Taylor [this message]
2006-04-13 23:31   ` Matt Lee
2006-04-14  3:21     ` Ian Lance Taylor
2006-04-14 21:49       ` Matt Lee
2006-04-18  4:33         ` Ian Lance Taylor

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=m3mzepkyn7.fsf@gossamer.airs.com \
    --to=ian@airs.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=reachmatt.lee@gmail.com \
    /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).