public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Paulo J. Matos" <paulo@matos-sorge.com>
To: gcc@gcc.gnu.org
Subject: Re: Expanding instructions with condition codes inter-deps
Date: Mon, 24 Oct 2011 12:07:00 -0000	[thread overview]
Message-ID: <j83c2v$vl$1@dough.gmane.org> (raw)
In-Reply-To: <4EA1E726.6090204@redhat.com>

On 21/10/11 22:41, Richard Henderson wrote:
> On 10/21/2011 10:15 AM, Paulo J. Matos wrote:
>> So I have implemented the nadd and addc as:
>>
>> (define_insn "negqi2"
>>    [(set (match_operand:QI 0 "register_operand" "=c")
>>          (neg:QI (match_operand:QI 1 "register_operand" "0")))
>>     (set (reg:CC_C RCC) (eq (match_dup 1) (const_int 0)))
>>     (clobber (reg:CC RCC))]
>>    ""
>> {
>>      operands[2] = const0_rtx;
>>      return  "nadd\\t%0,%2";
>> })
>
> There are lots of parts of the compiler that don't optimize well when an
> insn has more than one output.  For the normal insn, just clobber the flags;
> don't include a second SET.
>

But this case is not a normal insn per se, I did this to negqi2 because 
I need GCC to know that this instruction explicitly changes RCC and that 
the following instruction will use the carry flag (addc).

The reason I say it is not a normal insn is because it comes often in a 
pair negqi2 / addc_internal, like for example addqi3 / addc_internal or 
subqi3 / subc_internal.

>> (define_insn "addc_internal"
>>    [(set (match_operand:QI 0 "nonimmediate_operand" "=c")
>>          (plus:QI
>>            (plus:QI
>>              (ltu:QI (reg:CC RCC) (const_int 0))
>>              (match_operand:QI 1 "nonimmediate_operand" "%0"))
>>            (match_operand:QI 2 "general_operand" "cwmi")))
>>     (use (reg:CC_C RCC))
>>     (clobber (reg:CC RCC))]
>>    ""
>>    "addc\\t%0,%f2")
>
> You don't need the USE, because you mention RCC inside the LTU.
>
>> (define_insn "*addc_internal_flags"
>
> Likewise.
>

Got it, thanks.

>> A couple of things to note:
>> * negqi (which generates the nadd x, y equivalent to -x + y) has a
>> set RCC in C mode followed by a clobber. The set in C mode doesn't
>> show up in the _flags variant which is used only for the compare-elim
>> since it doesn't really matter and it already contains a set RCC
>> anyway.
>
> Surely the NADD insn is simply a normal subtract (with reversed operands).
> You shouldn't *need* to implement NEG at all, as the middle-end will let
> NEG expand via MINUS.
>
> Just so you know...
>

But it is not exactly the same thing in this arch because:
subqi3 generates a
sub <register>, <data> == <register> = <register> - <data>

to represent negqi2 of register R with a nadd I just do:
nadd R,#0

to represent it using a sub I require more moves:
ld R1, #0
sub R1, @R ; @R is memory mapped R
ld R, @R1

>> * is this enough for GCC to understand that anything that clobbers
>> RCC or specifically touches the RCC in C mode shouldn't go in between
>> these two instructions?
>
> Yes.
>
>> Also, do I need to specify in the RCC
>> clobber, exactly which flags are clobbered, or should I use a set
>> instead?
>
> No, the compiler will assume the entire register is changed, no matter
> what CCmode you place there.
>

Got it, so the only way to deal with the carry flag by itself would be 
to represent the Carry flag as a separate flags register. Although that 
would require more than one flags register and it feels messy.

-- 
PMatos

  parent reply	other threads:[~2011-10-24  9:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-17 15:58 Paulo J. Matos
2011-10-17 17:23 ` Andrew Pinski
2011-10-18 13:44   ` Paulo J. Matos
2011-10-19  5:22 ` Richard Henderson
2011-10-19  5:45   ` Paul_Koning
     [not found]     ` <CAPOJ94M2XrqM_kG98v1dC1=K2fEkHpuNLSkZBrQyzJ9ncmaQXg@mail.gmail.com>
2011-10-21 20:57       ` Richard Henderson
2011-10-21 21:42     ` Paulo J. Matos
2011-10-22  0:13       ` Richard Henderson
2011-10-22  5:13         ` Peter Bigot
2011-10-22  5:21         ` Paul_Koning
2011-10-24  7:04           ` Richard Henderson
2011-10-24 12:12             ` Paulo J. Matos
2011-10-24 12:07         ` Paulo J. Matos [this message]
2011-10-20 12:46   ` Paulo J. Matos

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='j83c2v$vl$1@dough.gmane.org' \
    --to=paulo@matos-sorge.com \
    --cc=gcc@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).