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: Fri, 14 Apr 2006 03:21:00 -0000	[thread overview]
Message-ID: <m364lclu4a.fsf@gossamer.airs.com> (raw)
In-Reply-To: <e94302560604131631r388a187bv1b8da028812eb15b@mail.gmail.com>

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

> Here is what I have,
> 
>     case AND:
>     case IOR:
>     case XOR:
>         *total = COSTS_N_INSNS (1);
>         return true;
>     case ASHIFT:
>     case ASHIFTRT:
>     case LSHIFTRT:
>          if (GET_CODE (XEXP (x, 1)) == CONST_INT)
>              *total = COSTS_N_INSNS (INTVAL (XEXP (x, 1)));
>          return true;
> 
> 
> This looks quite OK to me. I tried debugging if rtx_costs was doing
> something wrong. I do see rtx_cost being invoked for the lshiftrt
> expressions in question, but never for the "and". Seems like GCC had
> pre-decided to only use lshiftrt even though it is expensive.

Your computations look wrong to me.  You are saying that an AND always
costs 1 instruction.  But you need to actually look at the operands.
Specifically, the compiler is going to compare these two:
    (and (reg ...) (const_int ...)
    (and (ashiftrt (reg ...) (const_int ...)) (const_int 1))

> Any other ideas? Btw, I couldn't find prefer_and_bit_test in dojump.c.

I'm looking at the current version of gcc.  prefer_and_bit_test was
added 2004-03-20, so I guess that just missed 3.4.  I don't have 3.4
sources handy.  In general the decision is made in the do_jump
function.

Ian

  reply	other threads:[~2006-04-14  3:21 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
2006-04-13 23:31   ` Matt Lee
2006-04-14  3:21     ` Ian Lance Taylor [this message]
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=m364lclu4a.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).