public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to legitimize the reload address?
@ 2008-05-20 14:42 Mohamed Shafi
  2008-05-20 17:11 ` Ian Lance Taylor
  0 siblings, 1 reply; 7+ messages in thread
From: Mohamed Shafi @ 2008-05-20 14:42 UTC (permalink / raw)
  To: GCC

Hello all,

For the 16 bit target that i am currently porting can have only
positive offsets less than 0x100. (unsigned 8 bit) for offset
addressing mode.
During reload i am getting ICE because the address created is not
legitimate. So i guess i have to define the macro
LEGITIMIZE_RELOAD_ADDRESS.
But i am not sure how to do this?

With this will i be able to convert
load Rd, Rb[offset]
into
li Rs, offset
add Rs,Rb
load Rd, Rs

where Rs is a reserved register.

Or the only way is to do this  like the other targets say in rs6000

From rs6000_legitimize_reload_address()

     /* Reload the high part into a base reg; leave the low part
	 in the mem directly.  */

      x = gen_rtx_PLUS (GET_MODE (x),
			gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
				      GEN_INT (high)),
			GEN_INT (low));

      push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
		   BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
		   opnum, (enum reload_type)type);
      *win = 1;
      return x;

I guess this will generate something like

add Rs, Rb, excess_offset
load Rd, Rs[legitimate_offset];

Regards,
Shafi

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

* Re: How to legitimize the reload address?
  2008-05-20 14:42 How to legitimize the reload address? Mohamed Shafi
@ 2008-05-20 17:11 ` Ian Lance Taylor
  2008-05-20 19:35   ` Denis Chertykov
  2008-05-20 20:16   ` Jeff Law
  0 siblings, 2 replies; 7+ messages in thread
From: Ian Lance Taylor @ 2008-05-20 17:11 UTC (permalink / raw)
  To: Mohamed Shafi; +Cc: GCC

"Mohamed Shafi" <shafitvm@gmail.com> writes:

> For the 16 bit target that i am currently porting can have only
> positive offsets less than 0x100. (unsigned 8 bit) for offset
> addressing mode.

I would expect reload to be able to handle this kind of thing anyhow,
assuming you define GO_IF_LEGITIMATE_ADDRESS correctly.  reload should
automatically try loading an out of range offset into a register.

Ian

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

* Re: How to legitimize the reload address?
  2008-05-20 17:11 ` Ian Lance Taylor
@ 2008-05-20 19:35   ` Denis Chertykov
  2008-05-20 20:16   ` Jeff Law
  1 sibling, 0 replies; 7+ messages in thread
From: Denis Chertykov @ 2008-05-20 19:35 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Mohamed Shafi, GCC

2008/5/20 Ian Lance Taylor <iant@google.com>:
> "Mohamed Shafi" <shafitvm@gmail.com> writes:
>
>> For the 16 bit target that i am currently porting can have only
>> positive offsets less than 0x100. (unsigned 8 bit) for offset
>> addressing mode.
>
> I would expect reload to be able to handle this kind of thing anyhow,
> assuming you define GO_IF_LEGITIMATE_ADDRESS correctly.  reload should
> automatically try loading an out of range offset into a register.

No. Reload can't do it in any cases.  Reload can do it in many cases
but not in all.

Mohamed look to:
 - avr/avr.h: LEGITIMIZE_RELOAD_ADDRESS
 - avr/avr.md: *movqi
 - avr/avr.c: out_movqi_mr_r
Here I have emulated infinite displacement.

Bad things happened while many reloads occurs on insn with big
displacement (0xff,0xfe).
Also, while reload generate local variable (spill to stack slot) and
you have an insn
with address like [SP+0xff].

Denis.

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

* Re: How to legitimize the reload address?
  2008-05-20 17:11 ` Ian Lance Taylor
  2008-05-20 19:35   ` Denis Chertykov
@ 2008-05-20 20:16   ` Jeff Law
  2008-05-21 10:08     ` Mohamed Shafi
  1 sibling, 1 reply; 7+ messages in thread
From: Jeff Law @ 2008-05-20 20:16 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Mohamed Shafi, GCC

Ian Lance Taylor wrote:
> "Mohamed Shafi" <shafitvm@gmail.com> writes:
> 
>> For the 16 bit target that i am currently porting can have only
>> positive offsets less than 0x100. (unsigned 8 bit) for offset
>> addressing mode.
> 
> I would expect reload to be able to handle this kind of thing anyhow,
> assuming you define GO_IF_LEGITIMATE_ADDRESS correctly.  reload should
> automatically try loading an out of range offset into a register.
Agreed.

Typically if there are problems in this area it is because the port 
hasn't properly defined secondary reloads, or the valid offsets are not 
consistent within a machine mode.

Mohamed, without more details, there's not much we can do to help you.


Jeff

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

* Re: How to legitimize the reload address?
  2008-05-20 20:16   ` Jeff Law
@ 2008-05-21 10:08     ` Mohamed Shafi
  2008-05-21 13:52       ` Ian Lance Taylor
  2008-05-21 16:46       ` Jeff Law
  0 siblings, 2 replies; 7+ messages in thread
From: Mohamed Shafi @ 2008-05-21 10:08 UTC (permalink / raw)
  To: Jeff Law; +Cc: Ian Lance Taylor, GCC

On Wed, May 21, 2008 at 1:42 AM, Jeff Law <law@redhat.com> wrote:
> Ian Lance Taylor wrote:
>>
>> "Mohamed Shafi" <shafitvm@gmail.com> writes:
>>
>>> For the 16 bit target that i am currently porting can have only
>>> positive offsets less than 0x100. (unsigned 8 bit) for offset
>>> addressing mode.
>>
>> I would expect reload to be able to handle this kind of thing anyhow,
>> assuming you define GO_IF_LEGITIMATE_ADDRESS correctly.  reload should
>> automatically try loading an out of range offset into a register.
>
> Agreed.
>
> Typically if there are problems in this area it is because the port hasn't
> properly defined secondary reloads, or the valid offsets are not consistent
> within a machine mode.
>
> Mohamed, without more details, there's not much we can do to help you.
>
    I am sure that i have written GO_IF_LEGITIMATE_ADDRESS correctly.
What i have in my port is something similar to mcore back-end. These
are the relevant parts:

  else if (GET_CODE (X) == PLUS)
    {
      rtx xop0 = XEXP (X,0);
      rtx xop1 = XEXP (X,1);

      if (BASE_REGISTER_RTX_P (xop0))
        return legitimate_index_p (mode, xop1);
   }

static int
legitimate_index_p (enum machine_mode mode, rtx OP)
{
  if (GET_CODE (OP) == CONST_INT)
    {
      if (GET_MODE_SIZE (mode) >= 4
          && (((unsigned)INTVAL (OP)) % 4) == 0
          &&  ((unsigned)INTVAL (OP)) <= 0x0100)
        return 1;

      if (GET_MODE_SIZE (mode) == 2
          && (((unsigned)INTVAL (OP)) % 2) == 0
          &&  ((unsigned)INTVAL (OP)) <= 0x0100)
        return 1;

      if (GET_MODE_SIZE (mode) == 1
          && ((unsigned)INTVAL (OP)) <= 0x0100)
        return 1;
    }

  return 0;
}


The compiler is crashing in change_address_1, at emit-rtl.c
...
  if (validate)
    {
      if (reload_in_progress || reload_completed)
	gcc_assert (memory_address_p (mode, addr));
      else
	addr = memory_address (mode, addr);
    }
....


Everything starts when cleanup_subreg_operands() is called from
reload() for the following pattern.

(set (subreg:HI (mem:SI (plus:HI (reg:HI 12 [SP]) (const_int 256)) 2)
       (reg:HI 3))

and then this becomes

(set (mem:HI (plus:HI (reg:HI 12 [SP] ) (const_int 258)))
       (reg:HI 3))

This pattern is not legitimate due to out of range offset.
Will i be able to overcome this if i write LEGITIMIZE_RELOAD_ADDRESS
or LEGITIMIZE_ADDRESS

Thank you for your time.

Regards,
Shafi

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

* Re: How to legitimize the reload address?
  2008-05-21 10:08     ` Mohamed Shafi
@ 2008-05-21 13:52       ` Ian Lance Taylor
  2008-05-21 16:46       ` Jeff Law
  1 sibling, 0 replies; 7+ messages in thread
From: Ian Lance Taylor @ 2008-05-21 13:52 UTC (permalink / raw)
  To: Mohamed Shafi; +Cc: Jeff Law, GCC

"Mohamed Shafi" <shafitvm@gmail.com> writes:

> Everything starts when cleanup_subreg_operands() is called from
> reload() for the following pattern.
>
> (set (subreg:HI (mem:SI (plus:HI (reg:HI 12 [SP]) (const_int 256)) 2)
>        (reg:HI 3))

I think your movhi operand predicate may have to look for this case
and reject it.

> This pattern is not legitimate due to out of range offset.
> Will i be able to overcome this if i write LEGITIMIZE_RELOAD_ADDRESS
> or LEGITIMIZE_ADDRESS

No, because those won't reliably be called on a legitimate address.
You need to reject the operand at some point.

Ian

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

* Re: How to legitimize the reload address?
  2008-05-21 10:08     ` Mohamed Shafi
  2008-05-21 13:52       ` Ian Lance Taylor
@ 2008-05-21 16:46       ` Jeff Law
  1 sibling, 0 replies; 7+ messages in thread
From: Jeff Law @ 2008-05-21 16:46 UTC (permalink / raw)
  To: Mohamed Shafi; +Cc: Ian Lance Taylor, GCC

Mohamed Shafi wrote:
> On Wed, May 21, 2008 at 1:42 AM, Jeff Law <law@redhat.com> wrote:
>> Ian Lance Taylor wrote:
>>> "Mohamed Shafi" <shafitvm@gmail.com> writes:
>>>
>>>> For the 16 bit target that i am currently porting can have only
>>>> positive offsets less than 0x100. (unsigned 8 bit) for offset
>>>> addressing mode.
>>> I would expect reload to be able to handle this kind of thing anyhow,
>>> assuming you define GO_IF_LEGITIMATE_ADDRESS correctly.  reload should
>>> automatically try loading an out of range offset into a register.
>> Agreed.
>>
>> Typically if there are problems in this area it is because the port hasn't
>> properly defined secondary reloads, or the valid offsets are not consistent
>> within a machine mode.
>>
>> Mohamed, without more details, there's not much we can do to help you.
>>
>     I am sure that i have written GO_IF_LEGITIMATE_ADDRESS correctly.
> What i have in my port is something similar to mcore back-end. These
> are the relevant parts:
> 
>   else if (GET_CODE (X) == PLUS)
>     {
>       rtx xop0 = XEXP (X,0);
>       rtx xop1 = XEXP (X,1);
> 
>       if (BASE_REGISTER_RTX_P (xop0))
>         return legitimate_index_p (mode, xop1);
>    }
> 
> static int
> legitimate_index_p (enum machine_mode mode, rtx OP)
> {
>   if (GET_CODE (OP) == CONST_INT)
>     {
>       if (GET_MODE_SIZE (mode) >= 4
>           && (((unsigned)INTVAL (OP)) % 4) == 0
>           &&  ((unsigned)INTVAL (OP)) <= 0x0100)
>         return 1;
> 
>       if (GET_MODE_SIZE (mode) == 2
>           && (((unsigned)INTVAL (OP)) % 2) == 0
>           &&  ((unsigned)INTVAL (OP)) <= 0x0100)
>         return 1;
> 
>       if (GET_MODE_SIZE (mode) == 1
>           && ((unsigned)INTVAL (OP)) <= 0x0100)
>         return 1;
>     }
> 
>   return 0;
> }
> 
> 
> The compiler is crashing in change_address_1, at emit-rtl.c
> ...
>   if (validate)
>     {
>       if (reload_in_progress || reload_completed)
> 	gcc_assert (memory_address_p (mode, addr));
>       else
> 	addr = memory_address (mode, addr);
>     }
> ....
> 
> 
> Everything starts when cleanup_subreg_operands() is called from
> reload() for the following pattern.
> 
> (set (subreg:HI (mem:SI (plus:HI (reg:HI 12 [SP]) (const_int 256)) 2)
>        (reg:HI 3))
> 
> and then this becomes
> 
> (set (mem:HI (plus:HI (reg:HI 12 [SP] ) (const_int 258)))
>        (reg:HI 3))
> 
> This pattern is not legitimate due to out of range offset.
> Will i be able to overcome this if i write LEGITIMIZE_RELOAD_ADDRESS
> or LEGITIMIZE_ADDRESS
You have a (subreg (mem)) expression.  The mem part of that expression 
should have been reloaded into a register.    You probably want to look 
at your reload debugging dumps to see how/why that's not happening properly.

Using LEGITIMIZE_RELOAD_ADDRESS is definitely not the way to solve this 
problem.  It's intended solely as a means to optimize how reload 
generates code for certain cases.   LEGITIMIZE_ADDRESS won't have an 
affect at this stage in the compiler.

jeff
> 
> Thank you for your time.

> 
> Regards,
> Shafi

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

end of thread, other threads:[~2008-05-21 16:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-20 14:42 How to legitimize the reload address? Mohamed Shafi
2008-05-20 17:11 ` Ian Lance Taylor
2008-05-20 19:35   ` Denis Chertykov
2008-05-20 20:16   ` Jeff Law
2008-05-21 10:08     ` Mohamed Shafi
2008-05-21 13:52       ` Ian Lance Taylor
2008-05-21 16:46       ` Jeff Law

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