public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* pb expanding insn with "use"
@ 2012-01-03 10:01 Aurelien Buhrig
  2012-01-03 19:49 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Aurelien Buhrig @ 2012-01-03 10:01 UTC (permalink / raw)
  To: gcc-help

Hi all,
And happy new year!


I'm trying to optimize rotations for my target by expanding it into
several smaller rotates (let's say by rotate 1).

I defined this insn which uses a "temporary" register whose value is
used for next rotation by 1:

(define_insn "rotrhi3_cst1"
  [(set (match_operand:HI 0 "d_operand" "=d")
        (rotatert:HI (match_operand:HI 1 "d_operand" "0")
                   (const_int 1)))
   (use (match_operand:HI 2 "d_operand" "+&d"))]
  ""
  "rrc.w\t%2\t| \trrc.w\t%0 ; rotr1")

My problem is that such an expand:

(insn 14 13 15 2 (set (reg:HI 25 [ globHI.1 ])
        (reg:HI 22 [ globHI.1 ])) rotate.c:77 22 {movhi}
     (nil))
(insn 15 14 16 2 (parallel [
            (set (reg:HI 22 [ globHI.1 ])
                (rotatert:HI (reg:HI 22 [ globHI.1 ])
                    (const_int 1 [0x1])))
            (use (reg:HI 25 [ globHI.1 ]))
        ]) rotate.c:77 105 {rotrhi3_cst1}
     (nil))

is transformed during CSE pass into:
(insn 14 13 15 2 (set (reg:HI 25 [ globHI.1 ])
        (reg:HI 22 [ globHI.1 ])) rotate.c:77 22 {movhi}
     (nil))
(insn 15 14 16 2 (parallel [
            (set (reg:HI 22 [ globHI.1 ])
                (rotatert:HI (reg:HI 22 [ globHI.1 ])
                    (const_int 1 [0x1])))
            (use (reg:HI 22 [ globHI.1 ]))
        ]) rotate.c:77 105 {rotrhi3_cst1}
     (nil))

So it uses the same register for the use operand %2 and for the operands
%0/%1 despite the +& modifers...

How can I tell gcc not to use the same register for operands 2 and
operand 0?

The doc says about use:
"use can only be used to describe that the register is live. You
should think twice before adding use statements, more often you will
want to use unspec instead."

Does it mean that it's not possible using "use" and the only way to do
this is to create an unspec insn ?

Thank you by advance,
Aurélien

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: pb expanding insn with "use"
  2012-01-03 10:01 pb expanding insn with "use" Aurelien Buhrig
@ 2012-01-03 19:49 ` Ian Lance Taylor
  2012-01-04  9:01   ` Aurelien Buhrig
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2012-01-03 19:49 UTC (permalink / raw)
  To: Aurelien Buhrig; +Cc: gcc-help

Aurelien Buhrig <aurelien.buhrig.gcc@gmail.com> writes:

> I defined this insn which uses a "temporary" register whose value is
> used for next rotation by 1:
>
> (define_insn "rotrhi3_cst1"
>   [(set (match_operand:HI 0 "d_operand" "=d")
>         (rotatert:HI (match_operand:HI 1 "d_operand" "0")
>                    (const_int 1)))
>    (use (match_operand:HI 2 "d_operand" "+&d"))]
>   ""
>   "rrc.w\t%2\t| \trrc.w\t%0 ; rotr1")

I don't know what these instructions do, but if the temporary register
is only used by this insn you should use match_scratch.  If the register
is used by other subsequent instructions then you need to set it, not
just use it.

> So it uses the same register for the use operand %2 and for the operands
> %0/%1 despite the +& modifers...

It's a bit confusing, but the +& modifiers are only for register
allocation.  The CSE pass is before register allocation, and it is only
looking at what the RTL says.  The RTL says that the register is used
but not set, so the compiler feels free to feed in the same register.

> The doc says about use:
> "use can only be used to describe that the register is live. You
> should think twice before adding use statements, more often you will
> want to use unspec instead."
>
> Does it mean that it's not possible using "use" and the only way to do
> this is to create an unspec insn ?

You can use a "use" statement as long as you know what it means.  The
comment in the doc is there because what it means is not what most
people actually want.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: pb expanding insn with "use"
  2012-01-03 19:49 ` Ian Lance Taylor
@ 2012-01-04  9:01   ` Aurelien Buhrig
  0 siblings, 0 replies; 3+ messages in thread
From: Aurelien Buhrig @ 2012-01-04  9:01 UTC (permalink / raw)
  To: gcc-help


> Aurelien Buhrig <aurelien.buhrig.gcc@gmail.com> writes:
> 
>> I defined this insn which uses a "temporary" register whose value is
>> used for next rotation by 1:
>>
>> (define_insn "rotrhi3_cst1"
>>   [(set (match_operand:HI 0 "d_operand" "=d")
>>         (rotatert:HI (match_operand:HI 1 "d_operand" "0")
>>                    (const_int 1)))
>>    (use (match_operand:HI 2 "d_operand" "+&d"))]
>>   ""
>>   "rrc.w\t%2\t| \trrc.w\t%0 ; rotr1")
> 
> I don't know what these instructions do, but if the temporary register
> is only used by this insn you should use match_scratch.  If the register
> is used by other subsequent instructions then you need to set it, not
> just use it.
> 
>> So it uses the same register for the use operand %2 and for the operands
>> %0/%1 despite the +& modifers...
> 
> It's a bit confusing, but the +& modifiers are only for register
> allocation.  The CSE pass is before register allocation, and it is only
> looking at what the RTL says.  The RTL says that the register is used
> but not set, so the compiler feels free to feed in the same register.
> 
>> The doc says about use:
>> "use can only be used to describe that the register is live. You
>> should think twice before adding use statements, more often you will
>> want to use unspec instead."
>>
>> Does it mean that it's not possible using "use" and the only way to do
>> this is to create an unspec insn ?
> 
> You can use a "use" statement as long as you know what it means.  The
> comment in the doc is there because what it means is not what most
> people actually want.
> 
> Ian

Ok, it's very clear.

In my case, the %2 reg is used by other subsequent insn, but some bits
in this reg clobber (the MSB for a rotatert in fact), or set wrt the
cc0. I think I need to set it with an unspec.

Thanks for your help !

Aurélien

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-04  9:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-03 10:01 pb expanding insn with "use" Aurelien Buhrig
2012-01-03 19:49 ` Ian Lance Taylor
2012-01-04  9:01   ` Aurelien Buhrig

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).