public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* reload in incompatible constraints
@ 2011-06-23  8:35 Aurelien Buhrig
  2011-06-23 17:58 ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Aurelien Buhrig @ 2011-06-23  8:35 UTC (permalink / raw)
  To: gcc-help

Hi,

I would like some advice to figure out what is the correct way to
hande my movhi insn.

My target has general registers (natural mode HI, constraint r), and
base registers, which are not GENERAL_REG class(natural mode PSI, may
contain HI, contraint A).

My main problem is when defining a *movhi insn whose
constraints/predicates only support r registers, GCC may reload some r
register into A subreg:HI register, and complains because the insn
*movhi does not satisfy its constraints (r). How to prevent this ?

BTW, to handle movhi from subreg:HI A to subreg:HI A, which is not
supported by the target: should I define a define_expand movhi whose
predicates supports such an operation, and then, provide a
define_split to froce passing through a r reg ? Is there a more
efficient way to do this ?


Thanks
Aurélien

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

* Re: reload in incompatible constraints
  2011-06-23  8:35 reload in incompatible constraints Aurelien Buhrig
@ 2011-06-23 17:58 ` Ian Lance Taylor
  2011-06-27 21:46   ` Aurelien Buhrig
  0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2011-06-23 17:58 UTC (permalink / raw)
  To: Aurelien Buhrig; +Cc: gcc-help

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

> My main problem is when defining a *movhi insn whose
> constraints/predicates only support r registers, GCC may reload some r
> register into A subreg:HI register, and complains because the insn
> *movhi does not satisfy its constraints (r). How to prevent this ?

I assume that the register can in principle hold the value, so changing
HARD_REGNO_MODE_OK would not be appropriate.  What you want here is
REGISTER_MOVE_COST.  However, gcc will try to use all available
registers in some cases, so if you can't move values between the
register classes easily you will need to define TARGET_SECONDARY_RELOAD.


> BTW, to handle movhi from subreg:HI A to subreg:HI A, which is not
> supported by the target: should I define a define_expand movhi whose
> predicates supports such an operation, and then, provide a
> define_split to froce passing through a r reg ? Is there a more
> efficient way to do this ?

This is what TARGET_SECONDARY_RELOAD is for.

Ian

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

* Re: reload in incompatible constraints
  2011-06-23 17:58 ` Ian Lance Taylor
@ 2011-06-27 21:46   ` Aurelien Buhrig
  2011-06-28  6:01     ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Aurelien Buhrig @ 2011-06-27 21:46 UTC (permalink / raw)
  To: Ian Lance Taylor, gcc-help

Thanks for your help.

I'm trying to implement TARGET_SECONDARY_RELOAD but I cannot make it
work properly.
The hook seems to work for preventing from moving from BASE_REG to
BASE_REG in HImode by inserting a GENERAL_REG.
But I also want to insert a GENERAL_REGS intermediate register when
moving between BASE_REGS registers and memory in HImode.

So I wrote something like that in my TARGET_SECONDARY_RELOAD:
if (MEM_P(x) && (reload_mode == HImode) && reload_class == BASE_REGS)
     return GENERAL_REGS;


But it seems this do not work. For instance with DI function parameter
access (movdi reg:DI <-- m) which are (automatically) split into movhi
subreg:HI <-- m; then in movhi reg:HI <- m. But the hook do not seem
to work since the reg:HI is reloaded into a BASE_REG...

So when is this hook called? Is there something specific with spliting
insn? Or just a general thing about TARGET_SECONDARY_RELOAD I missed ?

Aurélien







2011/6/23 Ian Lance Taylor <iant@google.com>:
> Aurelien Buhrig <aurelien.buhrig.gcc@gmail.com> writes:
>
>> My main problem is when defining a *movhi insn whose
>> constraints/predicates only support r registers, GCC may reload some r
>> register into A subreg:HI register, and complains because the insn
>> *movhi does not satisfy its constraints (r). How to prevent this ?
>
> I assume that the register can in principle hold the value, so changing
> HARD_REGNO_MODE_OK would not be appropriate.  What you want here is
> REGISTER_MOVE_COST.  However, gcc will try to use all available
> registers in some cases, so if you can't move values between the
> register classes easily you will need to define TARGET_SECONDARY_RELOAD.
>
>
>> BTW, to handle movhi from subreg:HI A to subreg:HI A, which is not
>> supported by the target: should I define a define_expand movhi whose
>> predicates supports such an operation, and then, provide a
>> define_split to froce passing through a r reg ? Is there a more
>> efficient way to do this ?
>
> This is what TARGET_SECONDARY_RELOAD is for.
>
> Ian
>

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

* Re: reload in incompatible constraints
  2011-06-27 21:46   ` Aurelien Buhrig
@ 2011-06-28  6:01     ` Ian Lance Taylor
  2011-06-28 17:57       ` Aurelien Buhrig
  0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2011-06-28  6:01 UTC (permalink / raw)
  To: Aurelien Buhrig; +Cc: gcc-help

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

> I'm trying to implement TARGET_SECONDARY_RELOAD but I cannot make it
> work properly.
> The hook seems to work for preventing from moving from BASE_REG to
> BASE_REG in HImode by inserting a GENERAL_REG.
> But I also want to insert a GENERAL_REGS intermediate register when
> moving between BASE_REGS registers and memory in HImode.
>
> So I wrote something like that in my TARGET_SECONDARY_RELOAD:
> if (MEM_P(x) && (reload_mode == HImode) && reload_class == BASE_REGS)
>      return GENERAL_REGS;
>
>
> But it seems this do not work. For instance with DI function parameter
> access (movdi reg:DI <-- m) which are (automatically) split into movhi
> subreg:HI <-- m; then in movhi reg:HI <- m. But the hook do not seem
> to work since the reg:HI is reloaded into a BASE_REG...
>
> So when is this hook called? Is there something specific with spliting
> insn? Or just a general thing about TARGET_SECONDARY_RELOAD I missed ?

The hook is called during reload, which is run as part of register
allocation.  When are you splitting the DImode load?

Ian

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

* Re: reload in incompatible constraints
  2011-06-28  6:01     ` Ian Lance Taylor
@ 2011-06-28 17:57       ` Aurelien Buhrig
  2011-06-28 18:55         ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Aurelien Buhrig @ 2011-06-28 17:57 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

2011/6/28 Ian Lance Taylor <iant@google.com>:
> Aurelien Buhrig <aurelien.buhrig.gcc@gmail.com> writes:
>
>> I'm trying to implement TARGET_SECONDARY_RELOAD but I cannot make it
>> work properly.
>> The hook seems to work for preventing from moving from BASE_REG to
>> BASE_REG in HImode by inserting a GENERAL_REG.
>> But I also want to insert a GENERAL_REGS intermediate register when
>> moving between BASE_REGS registers and memory in HImode.
>>
>> So I wrote something like that in my TARGET_SECONDARY_RELOAD:
>> if (MEM_P(x) && (reload_mode == HImode) && reload_class == BASE_REGS)
>>      return GENERAL_REGS;
>>
>>
>> But it seems this do not work. For instance with DI function parameter
>> access (movdi reg:DI <-- m) which are (automatically) split into movhi
>> subreg:HI <-- m; then in movhi reg:HI <- m. But the hook do not seem
>> to work since the reg:HI is reloaded into a BASE_REG...
>>
>> So when is this hook called? Is there something specific with spliting
>> insn? Or just a general thing about TARGET_SECONDARY_RELOAD I missed ?
>
> The hook is called during reload, which is run as part of register
> allocation.  When are you splitting the DImode load?
>
> Ian
>
I have no instruction for it. GCC automatically splits it, and it does
it at the very beginning (131r.expand) by affecting a subreg:HI, and
affects a reg:HI at 139r.subregs, and a hard base_reg at 176r.greg. It
is never changed after.

Would it be a reg class pb ?
For now, I defined BASE_REGS class for address registers which does
not intersect with GENERAL_REGS class (the data registers). Should I
define Address register and data register as general register, with a
class for address register and a new class for data registers (such as
m68k) ?

Does GCC treat GENERALS_REGS differently than other classes ?

Aurélien

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

* Re: reload in incompatible constraints
  2011-06-28 17:57       ` Aurelien Buhrig
@ 2011-06-28 18:55         ` Ian Lance Taylor
  0 siblings, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 2011-06-28 18:55 UTC (permalink / raw)
  To: Aurelien Buhrig; +Cc: gcc-help

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

> 2011/6/28 Ian Lance Taylor <iant@google.com>:
>> Aurelien Buhrig <aurelien.buhrig.gcc@gmail.com> writes:
>>
>>> I'm trying to implement TARGET_SECONDARY_RELOAD but I cannot make it
>>> work properly.
>>> The hook seems to work for preventing from moving from BASE_REG to
>>> BASE_REG in HImode by inserting a GENERAL_REG.
>>> But I also want to insert a GENERAL_REGS intermediate register when
>>> moving between BASE_REGS registers and memory in HImode.
>>>
>>> So I wrote something like that in my TARGET_SECONDARY_RELOAD:
>>> if (MEM_P(x) && (reload_mode == HImode) && reload_class == BASE_REGS)
>>>      return GENERAL_REGS;
>>>
>>>
>>> But it seems this do not work. For instance with DI function parameter
>>> access (movdi reg:DI <-- m) which are (automatically) split into movhi
>>> subreg:HI <-- m; then in movhi reg:HI <- m. But the hook do not seem
>>> to work since the reg:HI is reloaded into a BASE_REG...
>>>
>>> So when is this hook called? Is there something specific with spliting
>>> insn? Or just a general thing about TARGET_SECONDARY_RELOAD I missed ?
>>
>> The hook is called during reload, which is run as part of register
>> allocation.  When are you splitting the DImode load?
>>
>> Ian
>>
> I have no instruction for it. GCC automatically splits it, and it does
> it at the very beginning (131r.expand) by affecting a subreg:HI, and
> affects a reg:HI at 139r.subregs, and a hard base_reg at 176r.greg. It
> is never changed after.
>
> Would it be a reg class pb ?
> For now, I defined BASE_REGS class for address registers which does
> not intersect with GENERAL_REGS class (the data registers). Should I
> define Address register and data register as general register, with a
> class for address register and a new class for data registers (such as
> m68k) ?
>
> Does GCC treat GENERALS_REGS differently than other classes ?

Yes, but I don't see why this would be your problem.

From your description I don't know why this is not working.  You are
going to have to debug it.  Probably the first thing to try would be a
few debug statements in your TARGET_SECONDARY_RELOAD to see if it is
being invoked as you expect.

Ian

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

end of thread, other threads:[~2011-06-28 14:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-23  8:35 reload in incompatible constraints Aurelien Buhrig
2011-06-23 17:58 ` Ian Lance Taylor
2011-06-27 21:46   ` Aurelien Buhrig
2011-06-28  6:01     ` Ian Lance Taylor
2011-06-28 17:57       ` Aurelien Buhrig
2011-06-28 18:55         ` Ian Lance Taylor

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