Patchwork [middle-end] Add machine_mode to address_cost target hook

login
register
mail settings
Submitter Oleg Endo
Date Sept. 4, 2012, 7:52 a.m.
Message ID <1346745157.2322.14.camel@yam-132-YW-E178-FTW>
Download mbox | patch
Permalink /patch/181513/
State New
Headers show

Comments

Oleg Endo - Sept. 4, 2012, 7:52 a.m.
On Mon, 2012-09-03 at 01:58 +0200, Oleg Endo wrote:
> OKOK -- I'll do it :)
> (within the next couple of days)
> 

And so I did.  Attached is an updated patch that adds the address space
parameter to the address_cost function.  I hope that this change does
not reset the ACKs so far:

[x] target-independent bits
[ ] alpha     [ ] arm       [ ] avr         [ ] bfin
[ ] cr16      [ ] cris      [ ] epiphany    [ ] i386
[ ] ia64      [ ] iq2000    [ ] lm32        [ ] m32c
[ ] m32r      [ ] mcore     [ ] mep         [x] microblaze
[x] mips      [ ] mmix      [x] mn10300     [ ] pa
[ ] rs6000    [ ] rx        [ ] s390        [ ] score
[x] sh        [ ] sparc     [ ] spu         [ ] stormy16
[ ] v850      [ ] vax       [ ] xtensa

Tested with 'make all-gcc' on SH xgcc and i386 native build.
No functional changes, except on MIPS, as requested by Richard
Sandiford.

Cheers,
Oleg

ChangeLog:

	* hooks.c (hook_int_rtx_mode_as_bool_0): New function.
	* hooks.h (hook_int_rtx_mode_as_bool_0): Declare it.
	* output.h (default_address_cost): Add machine_mode 
	and address space arguments.
	* target.def (address_cost): Likewise.
	* rtlanal.c (address_cost): Pass mode and address space to
	target hook.
	(default_address_cost): Add unnamed machine_mode and address 
	space arguments.
	* doc/tm.texi: Regenerate.
	* config/alpha/alpha.c (TARGET_ADDRESS_COST): Use 
	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
	* config/arm/arm.c (arm_address_cost): Add machine_mode 
	and address space arguments.
	* config/avr/avr.c (avr_address_cost): Likewise.
	* config/bfin/bfin.c (bfin_address_cost): Likewise.
	* config/cr16/cr16.c (cr16_address_cost): Likewise.
	* config/cris/cris.c (cris_address_cost): Likewise.
	* config/epiphany/epiphany.c (epiphany_address_cost): Likewise.
	* config/i386/i386.c (ix86_address_cost): Likewise.
	* config/ia64/ia64.c (TARGET_ADDRESS_COST): Use 
	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
	* config/iq2000/iq2000.c (iq2000_address_cost): Add 
        machine_mode and address space arguments.  Pass them on in
	recursive invocation.
	* config/lm32/lm32.c (TARGET_ADDRESS_COST): Use 
	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
	* config/m32c/m32c.c (m32c_address_cost): Add machine_mode 
	and address space arguments.
	* config/m32r/m32r.c (TARGET_ADDRESS_COST): Use 
	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
	* config/mcore/mcore.c (TARGET_ADDRESS_COST): Likewise.
	* config/mep/mep.c (mep_address_cost): Add machine_mode 
	and address space arguments.
	* config/microblaze/microblaze.c (microblaze_address_cost): 
	Likewise.
	* config/mips/mips.c (mips_address_cost): Likewise.
	* config/mmix/mmix.c (TARGET_ADDRESS_COST): Use 
	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
	* config/mn10300/mn10300.c (mn10300_address_cost): Add
        machine_mode and address space arguments.  Use GET_MODE (x) and 
	ADDR_SPACE_GENERIC in recursive invocation.
	* config/pa/pa.c (hppa_address_cost): Add machine_mode and 
	address space arguments.
	* config/rs6000/rs6000.c (rs6000_debug_address_cost): Likewise.
	(TARGET_ADDRESS_COST): Use hook_int_rtx_mode_as_bool_0 instead 
	of hook_int_rtx_bool_0.
        * config/rx/rx.c (rx_address_cost): Add machine_mode and 
	address space arguments.
	* config/s390/s390.c (s390_address_cost): Likewise.
	* config/score/score-protos.h (score_address_cost): Likewise.
	* config/score/score.c (score_address_cost): Likewise.
	* config/sh/sh.c (sh_address_cost): Likewise.
	* config/sparc/sparc.c (TARGET_ADDRESS_COST): Use 
	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
	* config/spu/spu.c (TARGET_ADDRESS_COST): Likewise.
	* config/stormy16/stormy16.c (xstormy16_address_cost): Add 
	machine_mode and address space arguments.
	* config/v850/v850.c (TARGET_ADDRESS_COST): Use 
	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
	* config/vax/vax.c (vax_address_cost): Add machine_mode 
	and address space arguments.
	* config/xtensa/xtensa (TARGET_ADDRESS_COST): Use 
	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
Nick Clifton - Sept. 4, 2012, 7:54 a.m.
Hi Oleg,

> And so I did.  Attached is an updated patch that adds the address space
> parameter to the address_cost function.  I hope that this change does
> not reset the ACKs so far:
>
> [x] target-independent bits
> [ ] alpha     [ ] arm       [ ] avr         [ ] bfin
> [ ] cr16      [ ] cris      [ ] epiphany    [ ] i386
> [ ] ia64      [ ] iq2000    [ ] lm32        [ ] m32c
> [ ] m32r      [ ] mcore     [ ] mep         [x] microblaze
> [x] mips      [ ] mmix      [x] mn10300     [ ] pa
> [ ] rs6000    [ ] rx        [ ] s390        [ ] score
> [x] sh        [ ] sparc     [ ] spu         [ ] stormy16
> [ ] v850      [ ] vax       [ ] xtensa

Please add ACKs for: iq2000, m32r, mcore, rx, stormy16 and v850.

Cheers
   Nick
Richard Earnshaw - Sept. 4, 2012, 9:52 a.m.
On 04/09/12 08:52, Oleg Endo wrote:
> On Mon, 2012-09-03 at 01:58 +0200, Oleg Endo wrote:
>> OKOK -- I'll do it :)
>> (within the next couple of days)
>>
> 
> And so I did.  Attached is an updated patch that adds the address space
> parameter to the address_cost function.  I hope that this change does
> not reset the ACKs so far:
> 
> [x] target-independent bits
> [ ] alpha     [ ] arm       [ ] avr         [ ] bfin
> [ ] cr16      [ ] cris      [ ] epiphany    [ ] i386
> [ ] ia64      [ ] iq2000    [ ] lm32        [ ] m32c
> [ ] m32r      [ ] mcore     [ ] mep         [x] microblaze
> [x] mips      [ ] mmix      [x] mn10300     [ ] pa
> [ ] rs6000    [ ] rx        [ ] s390        [ ] score
> [x] sh        [ ] sparc     [ ] spu         [ ] stormy16
> [ ] v850      [ ] vax       [ ] xtensa
> 
> Tested with 'make all-gcc' on SH xgcc and i386 native build.
> No functional changes, except on MIPS, as requested by Richard
> Sandiford.
> 
> Cheers,
> Oleg
> 
> ChangeLog:
> 
> 	* hooks.c (hook_int_rtx_mode_as_bool_0): New function.
> 	* hooks.h (hook_int_rtx_mode_as_bool_0): Declare it.
> 	* output.h (default_address_cost): Add machine_mode 
> 	and address space arguments.
> 	* target.def (address_cost): Likewise.
> 	* rtlanal.c (address_cost): Pass mode and address space to
> 	target hook.
> 	(default_address_cost): Add unnamed machine_mode and address 
> 	space arguments.
> 	* doc/tm.texi: Regenerate.
> 	* config/alpha/alpha.c (TARGET_ADDRESS_COST): Use 
> 	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
> 	* config/arm/arm.c (arm_address_cost): Add machine_mode 
> 	and address space arguments.
> 	* config/avr/avr.c (avr_address_cost): Likewise.
> 	* config/bfin/bfin.c (bfin_address_cost): Likewise.
> 	* config/cr16/cr16.c (cr16_address_cost): Likewise.
> 	* config/cris/cris.c (cris_address_cost): Likewise.
> 	* config/epiphany/epiphany.c (epiphany_address_cost): Likewise.
> 	* config/i386/i386.c (ix86_address_cost): Likewise.
> 	* config/ia64/ia64.c (TARGET_ADDRESS_COST): Use 
> 	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
> 	* config/iq2000/iq2000.c (iq2000_address_cost): Add 
>         machine_mode and address space arguments.  Pass them on in
> 	recursive invocation.
> 	* config/lm32/lm32.c (TARGET_ADDRESS_COST): Use 
> 	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
> 	* config/m32c/m32c.c (m32c_address_cost): Add machine_mode 
> 	and address space arguments.
> 	* config/m32r/m32r.c (TARGET_ADDRESS_COST): Use 
> 	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
> 	* config/mcore/mcore.c (TARGET_ADDRESS_COST): Likewise.
> 	* config/mep/mep.c (mep_address_cost): Add machine_mode 
> 	and address space arguments.
> 	* config/microblaze/microblaze.c (microblaze_address_cost): 
> 	Likewise.
> 	* config/mips/mips.c (mips_address_cost): Likewise.
> 	* config/mmix/mmix.c (TARGET_ADDRESS_COST): Use 
> 	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
> 	* config/mn10300/mn10300.c (mn10300_address_cost): Add
>         machine_mode and address space arguments.  Use GET_MODE (x) and 
> 	ADDR_SPACE_GENERIC in recursive invocation.
> 	* config/pa/pa.c (hppa_address_cost): Add machine_mode and 
> 	address space arguments.
> 	* config/rs6000/rs6000.c (rs6000_debug_address_cost): Likewise.
> 	(TARGET_ADDRESS_COST): Use hook_int_rtx_mode_as_bool_0 instead 
> 	of hook_int_rtx_bool_0.
>         * config/rx/rx.c (rx_address_cost): Add machine_mode and 
> 	address space arguments.
> 	* config/s390/s390.c (s390_address_cost): Likewise.
> 	* config/score/score-protos.h (score_address_cost): Likewise.
> 	* config/score/score.c (score_address_cost): Likewise.
> 	* config/sh/sh.c (sh_address_cost): Likewise.
> 	* config/sparc/sparc.c (TARGET_ADDRESS_COST): Use 
> 	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
> 	* config/spu/spu.c (TARGET_ADDRESS_COST): Likewise.
> 	* config/stormy16/stormy16.c (xstormy16_address_cost): Add 
> 	machine_mode and address space arguments.
> 	* config/v850/v850.c (TARGET_ADDRESS_COST): Use 
> 	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
> 	* config/vax/vax.c (vax_address_cost): Add machine_mode 
> 	and address space arguments.
> 	* config/xtensa/xtensa (TARGET_ADDRESS_COST): Use 
> 	hook_int_rtx_mode_as_bool_0 instead of hook_int_rtx_bool_0.
>         
> 
> 

The arm bits are OK.

R.
Paolo Bonzini - Sept. 4, 2012, 10:38 a.m.
Il 04/09/2012 09:52, Oleg Endo ha scritto:
> [x] target-independent bits
> [ ] alpha     [ ] arm       [ ] avr         [ ] bfin
> [ ] cr16      [ ] cris      [ ] epiphany    [ ] i386
> [ ] ia64      [ ] iq2000    [ ] lm32        [ ] m32c
> [ ] m32r      [ ] mcore     [ ] mep         [x] microblaze
> [x] mips      [ ] mmix      [x] mn10300     [ ] pa
> [ ] rs6000    [ ] rx        [ ] s390        [ ] score
> [x] sh        [ ] sparc     [ ] spu         [ ] stormy16
> [ ] v850      [ ] vax       [ ] xtensa
> 
> Tested with 'make all-gcc' on SH xgcc and i386 native build.
> No functional changes, except on MIPS, as requested by Richard
> Sandiford.

I think you only need explicit approval for mn10300.  All other changes
are trivial.

> +hook_int_rtx_mode_as_bool_0 (rtx, enum machine_mode, addr_space_t, bool)

So we're using C++ already?  Or do we want ATTRIBUTE_UNUSED here?

Paolo
Richard Guenther - Sept. 4, 2012, 2:32 p.m.
On Tue, Sep 4, 2012 at 12:38 PM, Paolo Bonzini <bonzini@gnu.org> wrote:
> Il 04/09/2012 09:52, Oleg Endo ha scritto:
>> [x] target-independent bits
>> [ ] alpha     [ ] arm       [ ] avr         [ ] bfin
>> [ ] cr16      [ ] cris      [ ] epiphany    [ ] i386
>> [ ] ia64      [ ] iq2000    [ ] lm32        [ ] m32c
>> [ ] m32r      [ ] mcore     [ ] mep         [x] microblaze
>> [x] mips      [ ] mmix      [x] mn10300     [ ] pa
>> [ ] rs6000    [ ] rx        [ ] s390        [ ] score
>> [x] sh        [ ] sparc     [ ] spu         [ ] stormy16
>> [ ] v850      [ ] vax       [ ] xtensa
>>
>> Tested with 'make all-gcc' on SH xgcc and i386 native build.
>> No functional changes, except on MIPS, as requested by Richard
>> Sandiford.
>
> I think you only need explicit approval for mn10300.  All other changes
> are trivial.
>
>> +hook_int_rtx_mode_as_bool_0 (rtx, enum machine_mode, addr_space_t, bool)
>
> So we're using C++ already?  Or do we want ATTRIBUTE_UNUSED here?

Use C++ where it is so nicely obvious an improvement ;)

Richard.

> Paolo
Alexandre Oliva - Sept. 4, 2012, 3:02 p.m.
On Sep  4, 2012, Oleg Endo <oleg.endo@t-online.de> wrote:

> 	* config/mn10300/mn10300.c (mn10300_address_cost): Add
>         machine_mode and address space arguments.  Use GET_MODE (x) and 
> 	ADDR_SPACE_GENERIC in recursive invocation.

Ok with a change, see below.

> 	* config/sh/sh.c (sh_address_cost): Likewise.

Ok, thanks.

> Index: gcc/config/mn10300/mn10300.c

> -      total = mn10300_address_cost (XEXP (x, 0), speed);
> +      total = mn10300_address_cost (XEXP (x, 0), GET_MODE (x),
> +				    ADDR_SPACE_GENERIC, speed);

Instead of ADDR_SPACE_GENERIC, this should be MEM_ADDR_SPACE (x), no?
Richard Sandiford - Sept. 4, 2012, 6:43 p.m.
Oleg Endo <oleg.endo@t-online.de> writes:
> On Mon, 2012-09-03 at 01:58 +0200, Oleg Endo wrote:
>> OKOK -- I'll do it :)
>> (within the next couple of days)
>> 
>
> And so I did.  Attached is an updated patch that adds the address space
> parameter to the address_cost function.  I hope that this change does
> not reset the ACKs so far:
>
> [x] target-independent bits
> [ ] alpha     [ ] arm       [ ] avr         [ ] bfin
> [ ] cr16      [ ] cris      [ ] epiphany    [ ] i386
> [ ] ia64      [ ] iq2000    [ ] lm32        [ ] m32c
> [ ] m32r      [ ] mcore     [ ] mep         [x] microblaze
> [x] mips      [ ] mmix      [x] mn10300     [ ] pa
> [ ] rs6000    [ ] rx        [ ] s390        [ ] score
> [x] sh        [ ] sparc     [ ] spu         [ ] stormy16
> [ ] v850      [ ] vax       [ ] xtensa
>
> Tested with 'make all-gcc' on SH xgcc and i386 native build.
> No functional changes, except on MIPS, as requested by Richard
> Sandiford.

Thanks, looks good to me.

Hopefully a friendly global maintainer will approve the whole thing in
one go (modulo Alex's comment) so that you don't need to get individual
approvals for all targets.

Richard
Hans-Peter Nilsson - Sept. 5, 2012, 1:33 a.m.
On Tue, 4 Sep 2012, Oleg Endo wrote:

> On Mon, 2012-09-03 at 01:58 +0200, Oleg Endo wrote:
> > OKOK -- I'll do it :)
> > (within the next couple of days)
> >
>
> And so I did.  Attached is an updated patch that adds the address space
> parameter to the address_cost function.  I hope that this change does
> not reset the ACKs so far:

It helps if you CC port maintainers where approval is requested;
you missed at least me.

The CRIS and MMIX bits are ok (and obvious) whenever the generic
bits are ok.

Still, considering that we're C++ now, you can presumably drop
the function parameter name instead of adding ATTRIBUTE_UNUSED.
(Either that or the posted version is ok for CRIS and MMIX.)

That goes for patches to trunk *only*.  On patches likely to be
backported to open branches (or local imports!), C++-syntax is
unwanted.

thanks.

PS. please consider building cc1 for each target using
contrib/config-list.mk or a similar script, to eliminate
breaking typos.

brgds, H-P
Oleg Endo - Sept. 5, 2012, 8:16 a.m.
Updated ACK table:

[x] target-independent bits
[ ] alpha     [x] arm       [ ] avr         [ ] bfin
[ ] cr16      [x] cris      [x] epiphany    [ ] i386
[ ] ia64      [x] iq2000    [ ] lm32        [ ] m32c
[x] m32r      [x] mcore     [ ] mep         [x] microblaze
[x] mips      [x] mmix      [x] mn10300     [ ] pa
[x] rs6000    [x] rx        [ ] s390        [ ] score
[x] sh        [ ] sparc     [x] spu         [x] stormy16
[x] v850      [ ] vax       [ ] xtensa

On Tue, 2012-09-04 at 21:33 -0400, Hans-Peter Nilsson wrote:

> It helps if you CC port maintainers where approval is requested;
> you missed at least me.

Right.  Did that for the remaining targets.
(BTW, there's no maintainer listed for the cr16 port)

For the reference, the current version of the patch is here:
http://gcc.gnu.org/ml/gcc-patches/2012-09/msg00210.html


> Still, considering that we're C++ now, you can presumably drop
> the function parameter name instead of adding ATTRIBUTE_UNUSED.

Yes, that has been mentioned before and I did drop the parameter names
in a place or two, but not in the target pieces -- on purpose.
Personally I prefer reading 'int bleh ATTRIBUTE_UNUSED' instead of
'int,int,bool,char,int,void*'.  Makes it somehow easier to follow and/or
fill in the blanks.

> PS. please consider building cc1 for each target using
> contrib/config-list.mk or a similar script, to eliminate
> breaking typos.

Thanks for the hint!

Cheers,
Oleg
Uros Bizjak - Sept. 5, 2012, 8:25 a.m.
On Wed, Sep 5, 2012 at 10:16 AM, Oleg Endo <oleg.endo@t-online.de> wrote:
> Updated ACK table:
>
> [x] target-independent bits
> [ ] alpha     [x] arm       [ ] avr         [ ] bfin
> [ ] cr16      [x] cris      [x] epiphany    [ ] i386
> [ ] ia64      [x] iq2000    [ ] lm32        [ ] m32c
> [x] m32r      [x] mcore     [ ] mep         [x] microblaze
> [x] mips      [x] mmix      [x] mn10300     [ ] pa
> [x] rs6000    [x] rx        [ ] s390        [ ] score
> [x] sh        [ ] sparc     [x] spu         [x] stormy16
> [x] v850      [ ] vax       [ ] xtensa
>
> On Tue, 2012-09-04 at 21:33 -0400, Hans-Peter Nilsson wrote:
>
>> It helps if you CC port maintainers where approval is requested;
>> you missed at least me.
>
> Right.  Did that for the remaining targets.
> (BTW, there's no maintainer listed for the cr16 port)

This is OK for x86.

Thanks,
Uros.
Richard Earnshaw - Sept. 5, 2012, 9:33 a.m.
On 05/09/12 09:16, Oleg Endo wrote:
> Updated ACK table:
> 
> [x] target-independent bits
> [ ] alpha     [x] arm       [ ] avr         [ ] bfin
> [ ] cr16      [x] cris      [x] epiphany    [ ] i386
> [ ] ia64      [x] iq2000    [ ] lm32        [ ] m32c
> [x] m32r      [x] mcore     [ ] mep         [x] microblaze
> [x] mips      [x] mmix      [x] mn10300     [ ] pa
> [x] rs6000    [x] rx        [ ] s390        [ ] score
> [x] sh        [ ] sparc     [x] spu         [x] stormy16
> [x] v850      [ ] vax       [ ] xtensa
> 
> On Tue, 2012-09-04 at 21:33 -0400, Hans-Peter Nilsson wrote:
> 
>> It helps if you CC port maintainers where approval is requested;
>> you missed at least me.
> 
> Right.  Did that for the remaining targets.
> (BTW, there's no maintainer listed for the cr16 port)
> 
> For the reference, the current version of the patch is here:
> http://gcc.gnu.org/ml/gcc-patches/2012-09/msg00210.html
> 
> 
>> Still, considering that we're C++ now, you can presumably drop
>> the function parameter name instead of adding ATTRIBUTE_UNUSED.
> 
> Yes, that has been mentioned before and I did drop the parameter names
> in a place or two, but not in the target pieces -- on purpose.
> Personally I prefer reading 'int bleh ATTRIBUTE_UNUSED' instead of
> 'int,int,bool,char,int,void*'.  Makes it somehow easier to follow and/or
> fill in the blanks.
> 
>> PS. please consider building cc1 for each target using
>> contrib/config-list.mk or a similar script, to eliminate
>> breaking typos.
> 
> Thanks for the hint!
> 
> Cheers,
> Oleg
> 
> 

Since they're not complicated: sparc, vax, ia64, mep, cr16, bfin, s390,
pa, xtensa, m32c, score, i386, lm32 and alpha are all ok.

R.
Denis Chertykov - Sept. 5, 2012, 9:44 a.m.
2012/9/5 Oleg Endo <oleg.endo@t-online.de>:
> Updated ACK table:
>
> [x] target-independent bits
> [ ] alpha     [x] arm       [ ] avr         [ ] bfin
> [ ] cr16      [x] cris      [x] epiphany    [ ] i386
> [ ] ia64      [x] iq2000    [ ] lm32        [ ] m32c
> [x] m32r      [x] mcore     [ ] mep         [x] microblaze
> [x] mips      [x] mmix      [x] mn10300     [ ] pa
> [x] rs6000    [x] rx        [ ] s390        [ ] score
> [x] sh        [ ] sparc     [x] spu         [x] stormy16
> [x] v850      [ ] vax       [ ] xtensa
>

avr - ok

Denis.
Oleg Endo - Sept. 5, 2012, 5:33 p.m.
On Wed, 2012-09-05 at 13:44 +0400, Denis Chertykov wrote:
> 2012/9/5 Oleg Endo <oleg.endo@t-online.de>:
> > Updated ACK table:
> >
> > [x] target-independent bits
> > [ ] alpha     [x] arm       [ ] avr         [ ] bfin
> > [ ] cr16      [x] cris      [x] epiphany    [ ] i386
> > [ ] ia64      [x] iq2000    [ ] lm32        [ ] m32c
> > [x] m32r      [x] mcore     [ ] mep         [x] microblaze
> > [x] mips      [x] mmix      [x] mn10300     [ ] pa
> > [x] rs6000    [x] rx        [ ] s390        [ ] score
> > [x] sh        [ ] sparc     [x] spu         [x] stormy16
> > [x] v850      [ ] vax       [ ] xtensa
> >
> 
> avr - ok

Thanks, that was the last piece.  I've committed the patch as rev
190990.

Cheers,
Oleg
DJ Delorie - Sept. 5, 2012, 6:39 p.m.
I don't feel the m32c change needs my specific ack, it's a harmless
change that goes with the ack for the feature itself.

However, I will note that m32c does have different costs for addresses
in different address spaces, at least when -Os.
Oleg Endo - Sept. 5, 2012, 6:57 p.m.
On Wed, 2012-09-05 at 14:39 -0400, DJ Delorie wrote:
> I don't feel the m32c change needs my specific ack, it's a harmless
> change that goes with the ack for the feature itself.
> 
> However, I will note that m32c does have different costs for addresses
> in different address spaces, at least when -Os.
> 

I have created http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54496
for this.

Cheers,
Oleg
Georg-Johann Lay - Sept. 6, 2012, 12:41 p.m.
Oleg Endo schrieb:
> On Wed, 2012-09-05 at 14:39 -0400, DJ Delorie wrote:
>> I don't feel the m32c change needs my specific ack, it's a harmless
>> change that goes with the ack for the feature itself.
>>
>> However, I will note that m32c does have different costs for addresses
>> in different address spaces, at least when -Os.
> 
> I have created http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54496
> for this.

The same is true for avr.  The address costs highly depend on the
address space, no matter what -O is used.

Can you explain how this works?

For example I don't see a single call of address_cost in
lower_subreg.c what means that at least that module has
not a reasonable cost model.  The costs go that odyssey:

lower-subreg.c:compute_costs()
-> rtlanal.c:insn_rtx_cost()
-> rtl.h:set_src_cost()
-> rtlanal.c:rtx_cost()
-> targetm.rtx_costs()

Each call level add some abstraction, i.e. removes information
about the insn; atually it's no more an insn, not even a pattern,
if the target hook is entered...

So at this point it appears a bit pointless to add mode
and addr_space to address_cost if the call sites don't use
that hook if it is needed.

The change is definitely in the right direction, but I wonder
how it helps to fix code bloats of 300%-400% as in PR52543?

The avr backend currently hacks around that by expanding MEM
for non-generic address space to UNSPEC.  Not nice.

Describing the cost will simply have no effect (provided that
MEM -> UNSPEC hack would be reverted).

Johann
Oleg Endo - Sept. 6, 2012, 7:09 p.m.
On Thu, 2012-09-06 at 14:41 +0200, Georg-Johann Lay wrote:
> Oleg Endo schrieb:
> > On Wed, 2012-09-05 at 14:39 -0400, DJ Delorie wrote:
> >> I don't feel the m32c change needs my specific ack, it's a harmless
> >> change that goes with the ack for the feature itself.
> >>
> >> However, I will note that m32c does have different costs for addresses
> >> in different address spaces, at least when -Os.
> > 
> > I have created http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54496
> > for this.
> 
> The same is true for avr.

As it is for other targets, too...

> Can you explain how this works?
> 

I'm not sure, however ... 

> For example I don't see a single call of address_cost in
> lower_subreg.c what means that at least that module has
> not a reasonable cost model.  The costs go that odyssey:
> 
> lower-subreg.c:compute_costs()
> -> rtlanal.c:insn_rtx_cost()
> -> rtl.h:set_src_cost()
> -> rtlanal.c:rtx_cost()
> -> targetm.rtx_costs()

... lower-subreg obviously is simply not dealding with mem loads/stores
when it collects the 'SET' costs.  Also notice that it calls into the
target once during startup and not for each individual insn.

> Each call level add some abstraction, i.e. removes information
> about the insn; atually it's no more an insn, not even a pattern,
> if the target hook is entered...
> 
> So at this point it appears a bit pointless to add mode
> and addr_space to address_cost if the call sites don't use
> that hook if it is needed.

I've noticed, that some passes (e.g. auto-inc-dec) would construct a MEM
pattern and use set_src_cost instead of using address_cost.  This can be
handled by simply implementing the MEM case in the rtx_costs hook and
re-using the target's address_cost function.  In fact some targets do
exactly that.

> The change is definitely in the right direction, but I wonder
> how it helps to fix code bloats of 300%-400% as in PR52543?

I'm not familiar with the AVR parts.
BTW, There was a small change in lower-subreg which required some
adaptations in targets:
http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00425.html

See also gcc/config/sh/sh.c (sh_rtx_costs): case SET: ...
Not sure whether it helps in your case.

> The avr backend currently hacks around that by expanding MEM
> for non-generic address space to UNSPEC.  Not nice.
> 
> Describing the cost will simply have no effect (provided that
> MEM -> UNSPEC hack would be reverted).

Because the address cost is not considered when doing the splits.
Maybe lower-subreg could be extended to pay attention to MEMs when
splitting (which would complicate its costs calculations -- it probably
would have to call into the target for every insn it looks at).

Maybe Richard or Ian have better ideas regarding this issue.

Cheers,
Oleg
Hans-Peter Nilsson - Sept. 8, 2012, 8:55 p.m.
Oleg Endo wrote:
> On Thu, 2012-09-06 at 14:41 +0200, Georg-Johann Lay wrote:
> > The change is definitely in the right direction, but I wonder
> > how it helps to fix code bloats of 300%-400% as in PR52543?
>
> I'm not familiar with the AVR parts.
> BTW, There was a small change in lower-subreg which required some
> adaptations in targets:
> http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00425.html
>
> See also gcc/config/sh/sh.c (sh_rtx_costs): case SET: ...
> Not sure whether it helps in your case.

Those kinds of changes are not required anymore (for most
targets), the fallback rtx_cost was amended to more sanely take
the mode-size into account, and to handle SET.  Whether that is
related to PR52543, I don't know.

brgds, H-P
Georg-Johann Lay - Sept. 8, 2012, 11:21 p.m.
Hans-Peter Nilsson schrieb:
> Oleg Endo wrote:
>> Georg-Johann Lay wrote:
>>> The change is definitely in the right direction, but I wonder
>>> how it helps to fix code bloats of 300%-400% as in PR52543?
>> I'm not familiar with the AVR parts.
>> BTW, There was a small change in lower-subreg which required some
>> adaptations in targets:
>> http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00425.html
>>
>> See also gcc/config/sh/sh.c (sh_rtx_costs): case SET: ...
>> Not sure whether it helps in your case.
> 
> Those kinds of changes are not required anymore (for most
> targets), the fallback rtx_cost was amended to more sanely take
> the mode-size into account, and to handle SET.  Whether that is
> related to PR52543, I don't know.

Hi,

I found an older compiler version (4.7.1 prerelease) without the
"expand MEM as UNSPEC" hack, and compiled one test case from
PR52543:

long read1 (const __flash1 long *p)
{
     return *p;
}

with the following options

$ avr-gcc -mmcu=atmega128 -c foo.c -fdump-rtl-subreg1-details 
-fdump-rtl-jump-details -mlog=rtx_costs,address_cost -Os  -std=gnu99 -dp 
-save-temps

The -mlog= option logs all results from the mentioned target hooks.

What I see is this:

- targetm.address_cost isn't even called once

- In .157r.jump the insn is fine, it reads SI from AS2:

(insn 6 3 7 2 (set (reg:SI 46)
         (mem:SI (reg/v/f:HI 44 [ p ]) [2 *p_1(D)+0 S4 A8 AS2])) 
foo.c:10 26 {*movsi}
      (nil))

- In pass .158r.subreg1 this insn is split into 4 movqi.
   This costs 16 instructions instead of 6 without a split.
   Besides that the register pressure goes up.

- Costs for mem:QI/AS2 are called *after* subreg1 split the insn
   forst time from cse1.

- There is not a single call that tries to get the costs for
   mem:SI/AS2 moves

- The only calls that get costs for SI moves look like

avr_rtx_costs[:pass=?]=true (size) total=16, outer=set:
(mem:SI (reg:HI 38 virtual-stack-dynamic) [0 S4 A8])

This cost is for generic address space, not for AS2.
Besides that it calls the hook with the wrong optimization
(speed instead of size as requested by -Os)

Johann

Patch

Index: gcc/rtlanal.c
===================================================================
--- gcc/rtlanal.c	(revision 190865)
+++ gcc/rtlanal.c	(working copy)
@@ -3820,13 +3820,13 @@ 
   if (!memory_address_addr_space_p (mode, x, as))
     return 1000;
 
-  return targetm.address_cost (x, speed);
+  return targetm.address_cost (x, mode, as, speed);
 }
 
 /* If the target doesn't override, compute the cost as with arithmetic.  */
 
 int
-default_address_cost (rtx x, bool speed)
+default_address_cost (rtx x, enum machine_mode, addr_space_t, bool speed)
 {
   return rtx_cost (x, MEM, 0, speed);
 }
Index: gcc/hooks.c
===================================================================
--- gcc/hooks.c	(revision 190865)
+++ gcc/hooks.c	(working copy)
@@ -200,6 +200,12 @@ 
   return 0;
 }
 
+int
+hook_int_rtx_mode_as_bool_0 (rtx, enum machine_mode, addr_space_t, bool)
+{
+  return 0;
+}
+
 unsigned int
 hook_uint_void_0 (void)
 {
Index: gcc/hooks.h
===================================================================
--- gcc/hooks.h	(revision 190865)
+++ gcc/hooks.h	(working copy)
@@ -75,6 +75,8 @@ 
 extern int hook_int_const_tree_const_tree_1 (const_tree, const_tree);
 extern int hook_int_rtx_0 (rtx);
 extern int hook_int_rtx_bool_0 (rtx, bool);
+extern int hook_int_rtx_mode_as_bool_0 (rtx, enum machine_mode, addr_space_t,
+					bool);
 
 extern tree hook_tree_const_tree_null (const_tree);
 
Index: gcc/target.def
===================================================================
--- gcc/target.def	(revision 190865)
+++ gcc/target.def	(working copy)
@@ -1758,7 +1758,7 @@ 
 DEFHOOK
 (address_cost,
  "",
- int, (rtx address, bool speed),
+ int, (rtx address, enum machine_mode mode, addr_space_t as, bool speed),
  default_address_cost)
 
 /* Return where to allocate pseudo for a given hard register initial value.  */
Index: gcc/output.h
===================================================================
--- gcc/output.h	(revision 190865)
+++ gcc/output.h	(working copy)
@@ -606,7 +606,7 @@ 
 extern void default_elf_fini_array_asm_out_destructor (rtx, int);
 extern int maybe_assemble_visibility (tree);
 
-extern int default_address_cost (rtx, bool);
+extern int default_address_cost (rtx, enum machine_mode, addr_space_t, bool);
 
 /* Output stack usage information.  */
 extern void output_stack_usage (void);
Index: gcc/config/v850/v850.c
===================================================================
--- gcc/config/v850/v850.c	(revision 190865)
+++ gcc/config/v850/v850.c	(working copy)
@@ -3130,7 +3130,7 @@ 
 #define TARGET_RTX_COSTS v850_rtx_costs
 
 #undef  TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 
 #undef  TARGET_MACHINE_DEPENDENT_REORG
 #define TARGET_MACHINE_DEPENDENT_REORG v850_reorg
Index: gcc/config/mmix/mmix.c
===================================================================
--- gcc/config/mmix/mmix.c	(revision 190865)
+++ gcc/config/mmix/mmix.c	(working copy)
@@ -223,7 +223,7 @@ 
 #undef TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS mmix_rtx_costs
 #undef TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 
 #undef TARGET_REGISTER_MOVE_COST
 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
Index: gcc/config/cr16/cr16.c
===================================================================
--- gcc/config/cr16/cr16.c	(revision 190865)
+++ gcc/config/cr16/cr16.c	(working copy)
@@ -1286,7 +1286,9 @@ 
 
 /* Return cost of the memory address x.  */
 static int
-cr16_address_cost (rtx addr, bool speed ATTRIBUTE_UNUSED)
+cr16_address_cost (rtx addr, enum machine_mode mode ATTRIBUTE_UNUSED,
+		   addr_space_t as ATTRIBUTE_UNUSED,
+		   bool speed ATTRIBUTE_UNUSED)
 {
   enum cr16_addrtype addrtype;
   struct cr16_address address;
Index: gcc/config/bfin/bfin.c
===================================================================
--- gcc/config/bfin/bfin.c	(revision 190865)
+++ gcc/config/bfin/bfin.c	(working copy)
@@ -1288,7 +1288,10 @@ 
    All addressing modes are equally cheap on the Blackfin.  */
 
 static int
-bfin_address_cost (rtx addr ATTRIBUTE_UNUSED, bool speed ATTRIBUTE_UNUSED)
+bfin_address_cost (rtx addr ATTRIBUTE_UNUSED,
+		   enum machine_mode mode ATTRIBUTE_UNUSED,
+		   addr_space_t as ATTRIBUTE_UNUSED,
+		   bool speed ATTRIBUTE_UNUSED)
 {
   return 1;
 }
Index: gcc/config/mn10300/mn10300.c
===================================================================
--- gcc/config/mn10300/mn10300.c	(revision 190865)
+++ gcc/config/mn10300/mn10300.c	(working copy)
@@ -2142,7 +2142,8 @@ 
    with an address register.  */
 
 static int
-mn10300_address_cost (rtx x, bool speed)
+mn10300_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+		      addr_space_t as ATTRIBUTE_UNUSED, bool speed)
 {
   HOST_WIDE_INT i;
   rtx base, index;
@@ -2457,7 +2458,8 @@ 
       break;
 
     case MEM:
-      total = mn10300_address_cost (XEXP (x, 0), speed);
+      total = mn10300_address_cost (XEXP (x, 0), GET_MODE (x),
+				    ADDR_SPACE_GENERIC, speed);
       if (speed)
 	total = COSTS_N_INSNS (2 + total);
       goto alldone;
Index: gcc/config/s390/s390.c
===================================================================
--- gcc/config/s390/s390.c	(revision 190865)
+++ gcc/config/s390/s390.c	(working copy)
@@ -2597,7 +2597,9 @@ 
 /* Return the cost of an address rtx ADDR.  */
 
 static int
-s390_address_cost (rtx addr, bool speed ATTRIBUTE_UNUSED)
+s390_address_cost (rtx addr, enum machine_mode mode ATTRIBUTE_UNUSED,
+		   addr_space_t as ATTRIBUTE_UNUSED,
+		   bool speed ATTRIBUTE_UNUSED)
 {
   struct s390_address ad;
   if (!s390_decompose_address (addr, &ad))
Index: gcc/config/m32c/m32c.c
===================================================================
--- gcc/config/m32c/m32c.c	(revision 190865)
+++ gcc/config/m32c/m32c.c	(working copy)
@@ -2278,7 +2278,9 @@ 
 #undef TARGET_ADDRESS_COST
 #define TARGET_ADDRESS_COST m32c_address_cost
 static int
-m32c_address_cost (rtx addr, bool speed ATTRIBUTE_UNUSED)
+m32c_address_cost (rtx addr, enum machine_mode mode ATTRIBUTE_UNUSED,
+		   addr_space_t as ATTRIBUTE_UNUSED,
+		   bool speed ATTRIBUTE_UNUSED)
 {
   int i;
   /*  fprintf(stderr, "\naddress_cost\n");
Index: gcc/config/m32r/m32r.c
===================================================================
--- gcc/config/m32r/m32r.c	(revision 190865)
+++ gcc/config/m32r/m32r.c	(working copy)
@@ -161,7 +161,7 @@ 
 #undef  TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS m32r_rtx_costs
 #undef  TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 
 #undef  TARGET_PROMOTE_PROTOTYPES
 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
Index: gcc/config/rx/rx.c
===================================================================
--- gcc/config/rx/rx.c	(revision 190865)
+++ gcc/config/rx/rx.c	(working copy)
@@ -2724,7 +2724,8 @@ 
 }
 
 static int
-rx_address_cost (rtx addr, bool speed)
+rx_address_cost (rtx addr, enum machine_mode mode ATTRIBUTE_UNUSED,
+		 addr_space_t as ATTRIBUTE_UNUSED, bool speed)
 {
   rtx a, b;
 
Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 190865)
+++ gcc/config/i386/i386.c	(working copy)
@@ -12027,7 +12027,9 @@ 
    requires to two regs - that would mean more pseudos with longer
    lifetimes.  */
 static int
-ix86_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
+ix86_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+		   addr_space_t as ATTRIBUTE_UNUSED,
+		   bool speed ATTRIBUTE_UNUSED)
 {
   struct ix86_address parts;
   int cost = 1;
Index: gcc/config/mcore/mcore.c
===================================================================
--- gcc/config/mcore/mcore.c	(revision 190865)
+++ gcc/config/mcore/mcore.c	(working copy)
@@ -191,7 +191,7 @@ 
 #undef  TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS 		mcore_rtx_costs
 #undef  TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST 		hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST 		hook_int_rtx_mode_as_bool_0
 #undef  TARGET_MACHINE_DEPENDENT_REORG
 #define TARGET_MACHINE_DEPENDENT_REORG	mcore_reorg
 
Index: gcc/config/sh/sh.c
===================================================================
--- gcc/config/sh/sh.c	(revision 190865)
+++ gcc/config/sh/sh.c	(working copy)
@@ -248,7 +248,7 @@ 
 static bool unspec_caller_rtx_p (rtx);
 static bool sh_cannot_copy_insn_p (rtx);
 static bool sh_rtx_costs (rtx, int, int, int, int *, bool);
-static int sh_address_cost (rtx, bool);
+static int sh_address_cost (rtx, enum machine_mode, addr_space_t, bool);
 static int sh_pr_n_sets (void);
 static rtx sh_allocate_initial_value (rtx);
 static reg_class_t sh_preferred_reload_class (rtx, reg_class_t);
@@ -3368,7 +3368,8 @@ 
 /* Compute the cost of an address.  */
 
 static int
-sh_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
+sh_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+		 addr_space_t as ATTRIBUTE_UNUSED, bool speed ATTRIBUTE_UNUSED)
 {
   /* 'reg + disp' addressing.  */
   if (satisfies_constraint_Sdd (x))
Index: gcc/config/score/score-protos.h
===================================================================
--- gcc/config/score/score-protos.h	(revision 190865)
+++ gcc/config/score/score-protos.h	(working copy)
@@ -39,7 +39,8 @@ 
 extern bool score_unaligned_load (rtx* ops);
 extern bool score_unaligned_store (rtx* ops);
 extern bool score_block_move (rtx* ops);
-extern int score_address_cost (rtx addr, bool speed);
+extern int score_address_cost (rtx addr, enum machine_mode mode,
+			       addr_space_t as, bool speed);
 extern int score_address_p (enum machine_mode mode, rtx x, int strict);
 extern int score_reg_class (int regno);
 extern int score_hard_regno_mode_ok (unsigned int, enum machine_mode);
Index: gcc/config/score/score.c
===================================================================
--- gcc/config/score/score.c	(revision 190865)
+++ gcc/config/score/score.c	(working copy)
@@ -1232,7 +1232,8 @@ 
 
 /* Implement TARGET_ADDRESS_COST macro.  */
 int
-score_address_cost (rtx addr,
+score_address_cost (rtx addr, enum machine_mode mode ATTRIBUTE_UNUSED,
+		    addr_space_t as ATTRIBUTE_UNUSED,
 		    bool speed ATTRIBUTE_UNUSED)
 {
   return score_address_insns (addr, SImode);
Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c	(revision 190865)
+++ gcc/config/arm/arm.c	(working copy)
@@ -162,7 +162,7 @@ 
 static bool arm_xscale_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
 static bool arm_9e_rtx_costs (rtx, enum rtx_code, enum rtx_code, int *, bool);
 static bool arm_rtx_costs (rtx, int, int, int, int *, bool);
-static int arm_address_cost (rtx, bool);
+static int arm_address_cost (rtx, enum machine_mode, addr_space_t, bool);
 static int arm_register_move_cost (enum machine_mode, reg_class_t, reg_class_t);
 static int arm_memory_move_cost (enum machine_mode, reg_class_t, bool);
 static void arm_init_builtins (void);
@@ -8411,7 +8411,8 @@ 
 }
 
 static int
-arm_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
+arm_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+		  addr_space_t as ATTRIBUTE_UNUSED, bool speed ATTRIBUTE_UNUSED)
 {
   return TARGET_32BIT ? arm_arm_address_cost (x) : arm_thumb_address_cost (x);
 }
Index: gcc/config/microblaze/microblaze.c
===================================================================
--- gcc/config/microblaze/microblaze.c	(revision 190865)
+++ gcc/config/microblaze/microblaze.c	(working copy)
@@ -1043,7 +1043,9 @@ 
 /* Provide the costs of an addressing mode that contains ADDR.
    If ADDR is not a valid address, its cost is irrelevant.  */
 static int
-microblaze_address_cost (rtx addr, bool speed ATTRIBUTE_UNUSED)
+microblaze_address_cost (rtx addr, enum machine_mode mode ATTRIBUTE_UNUSED,
+			 addr_space_t as ATTRIBUTE_UNUSED,
+			 bool speed ATTRIBUTE_UNUSED)
 {
   return COSTS_N_INSNS (microblaze_address_insns (addr, GET_MODE (addr)));
 }
Index: gcc/config/xtensa/xtensa.c
===================================================================
--- gcc/config/xtensa/xtensa.c	(revision 190865)
+++ gcc/config/xtensa/xtensa.c	(working copy)
@@ -211,7 +211,7 @@ 
 #undef TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS xtensa_rtx_costs
 #undef TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 
 #undef TARGET_MEMBER_TYPE_FORCES_BLK
 #define TARGET_MEMBER_TYPE_FORCES_BLK xtensa_member_type_forces_blk
Index: gcc/config/stormy16/stormy16.c
===================================================================
--- gcc/config/stormy16/stormy16.c	(revision 190865)
+++ gcc/config/stormy16/stormy16.c	(working copy)
@@ -58,7 +58,7 @@ 
 static void xstormy16_init_builtins (void);
 static rtx xstormy16_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
 static bool xstormy16_rtx_costs (rtx, int, int, int, int *, bool);
-static int xstormy16_address_cost (rtx, bool);
+static int xstormy16_address_cost (rtx, enum machine_mode, addr_space_t, bool);
 static bool xstormy16_return_in_memory (const_tree, const_tree);
 
 static GTY(()) section *bss100_section;
@@ -103,7 +103,9 @@ 
 }
 
 static int
-xstormy16_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
+xstormy16_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+			addr_space_t as ATTRIBUTE_UNUSED,
+			bool speed ATTRIBUTE_UNUSED)
 {
   return (CONST_INT_P (x) ? 2
 	  : GET_CODE (x) == PLUS ? 7
Index: gcc/config/epiphany/epiphany.c
===================================================================
--- gcc/config/epiphany/epiphany.c	(revision 190865)
+++ gcc/config/epiphany/epiphany.c	(working copy)
@@ -729,7 +729,8 @@ 
    If ADDR is not a valid address, its cost is irrelevant.  */
 
 static int
-epiphany_address_cost (rtx addr, bool speed)
+epiphany_address_cost (rtx addr, enum machine_mode mode ATTRIBUTE_UNUSED,
+		       addr_space_t as ATTRIBUTE_UNUSED, bool speed)
 {
   rtx reg;
   rtx off = const0_rtx;
Index: gcc/config/lm32/lm32.c
===================================================================
--- gcc/config/lm32/lm32.c	(revision 190865)
+++ gcc/config/lm32/lm32.c	(working copy)
@@ -86,7 +86,7 @@ 
 #undef TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE lm32_option_override
 #undef TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 #undef TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS lm32_rtx_costs
 #undef TARGET_IN_SMALL_DATA_P
Index: gcc/config/vax/vax.c
===================================================================
--- gcc/config/vax/vax.c	(revision 190865)
+++ gcc/config/vax/vax.c	(working copy)
@@ -53,7 +53,7 @@ 
 static void vax_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
 				 HOST_WIDE_INT, tree);
 static int vax_address_cost_1 (rtx);
-static int vax_address_cost (rtx, bool);
+static int vax_address_cost (rtx, enum machine_mode, addr_space_t, bool);
 static bool vax_rtx_costs (rtx, int, int, int, int *, bool);
 static rtx vax_function_arg (cumulative_args_t, enum machine_mode,
 			     const_tree, bool);
@@ -738,7 +738,9 @@ 
 }
 
 static int
-vax_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
+vax_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+		  addr_space_t as ATTRIBUTE_UNUSED,
+		  bool speed ATTRIBUTE_UNUSED)
 {
   return (1 + (REG_P (x) ? 0 : vax_address_cost_1 (x)));
 }
Index: gcc/config/cris/cris.c
===================================================================
--- gcc/config/cris/cris.c	(revision 190865)
+++ gcc/config/cris/cris.c	(working copy)
@@ -130,7 +130,7 @@ 
 static int cris_register_move_cost (enum machine_mode, reg_class_t, reg_class_t);
 static int cris_memory_move_cost (enum machine_mode, reg_class_t, bool);
 static bool cris_rtx_costs (rtx, int, int, int, int *, bool);
-static int cris_address_cost (rtx, bool);
+static int cris_address_cost (rtx, enum machine_mode, addr_space_t, bool);
 static bool cris_pass_by_reference (cumulative_args_t, enum machine_mode,
 				    const_tree, bool);
 static int cris_arg_partial_bytes (cumulative_args_t, enum machine_mode,
@@ -2149,7 +2149,9 @@ 
 /* The ADDRESS_COST worker.  */
 
 static int
-cris_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
+cris_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+		   addr_space_t as ATTRIBUTE_UNUSED,
+		   bool speed ATTRIBUTE_UNUSED)
 {
   /* The metric to use for the cost-macros is unclear.
      The metric used here is (the number of cycles needed) / 2,
Index: gcc/config/iq2000/iq2000.c
===================================================================
--- gcc/config/iq2000/iq2000.c	(revision 190865)
+++ gcc/config/iq2000/iq2000.c	(working copy)
@@ -152,7 +152,8 @@ 
 					   enum machine_mode, tree, int *,
 					   int);
 static bool iq2000_rtx_costs          (rtx, int, int, int, int *, bool);
-static int  iq2000_address_cost       (rtx, bool);
+static int  iq2000_address_cost       (rtx, enum machine_mode, addr_space_t,
+				       bool);
 static section *iq2000_select_section (tree, int, unsigned HOST_WIDE_INT);
 static rtx  iq2000_legitimize_address (rtx, rtx, enum machine_mode);
 static bool iq2000_pass_by_reference  (cumulative_args_t, enum machine_mode,
@@ -779,7 +780,8 @@ 
 /* Provide the costs of an addressing mode that contains ADDR.  */
 
 static int
-iq2000_address_cost (rtx addr, bool speed)
+iq2000_address_cost (rtx addr, enum machine_mode mode, addr_space_t as,
+		     bool speed)
 {
   switch (GET_CODE (addr))
     {
@@ -830,7 +832,7 @@ 
 	  case LABEL_REF:
 	  case HIGH:
 	  case LO_SUM:
-	    return iq2000_address_cost (plus1, speed) + 1;
+	    return iq2000_address_cost (plus1, mode, as, speed) + 1;
 
 	  default:
 	    break;
Index: gcc/config/alpha/alpha.c
===================================================================
--- gcc/config/alpha/alpha.c	(revision 190865)
+++ gcc/config/alpha/alpha.c	(working copy)
@@ -9795,7 +9795,7 @@ 
 #undef TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS alpha_rtx_costs
 #undef TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 
 #undef TARGET_MACHINE_DEPENDENT_REORG
 #define TARGET_MACHINE_DEPENDENT_REORG alpha_reorg
Index: gcc/config/ia64/ia64.c
===================================================================
--- gcc/config/ia64/ia64.c	(revision 190865)
+++ gcc/config/ia64/ia64.c	(working copy)
@@ -524,7 +524,7 @@ 
 #undef TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS ia64_rtx_costs
 #undef TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 
 #undef TARGET_UNSPEC_MAY_TRAP_P
 #define TARGET_UNSPEC_MAY_TRAP_P ia64_unspec_may_trap_p
Index: gcc/config/spu/spu.c
===================================================================
--- gcc/config/spu/spu.c	(revision 190865)
+++ gcc/config/spu/spu.c	(working copy)
@@ -7161,7 +7161,7 @@ 
 #define TARGET_RTX_COSTS spu_rtx_costs
 
 #undef TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 
 #undef TARGET_SCHED_ISSUE_RATE
 #define TARGET_SCHED_ISSUE_RATE spu_sched_issue_rate
Index: gcc/config/sparc/sparc.c
===================================================================
--- gcc/config/sparc/sparc.c	(revision 190865)
+++ gcc/config/sparc/sparc.c	(working copy)
@@ -689,7 +689,7 @@ 
 #undef TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS sparc_rtx_costs
 #undef TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 #undef TARGET_REGISTER_MOVE_COST
 #define TARGET_REGISTER_MOVE_COST sparc_register_move_cost
 
Index: gcc/config/mep/mep.c
===================================================================
--- gcc/config/mep/mep.c	(revision 190865)
+++ gcc/config/mep/mep.c	(working copy)
@@ -212,7 +212,7 @@ 
 static rtx mep_make_bundle (rtx, rtx);
 static void mep_bundle_insns (rtx);
 static bool mep_rtx_cost (rtx, int, int, int, int *, bool);
-static int mep_address_cost (rtx, bool);
+static int mep_address_cost (rtx, enum machine_mode, addr_space_t, bool);
 static void mep_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
 					tree, int *, int);
 static bool mep_pass_by_reference (cumulative_args_t cum, enum machine_mode,
@@ -7152,7 +7152,10 @@ 
 }
 
 static int
-mep_address_cost (rtx addr ATTRIBUTE_UNUSED, bool ATTRIBUTE_UNUSED speed_p)
+mep_address_cost (rtx addr ATTRIBUTE_UNUSED,
+		  enum machine_mode mode ATTRIBUTE_UNUSED,
+		  addr_space_t as ATTRIBUTE_UNUSED,
+		  bool ATTRIBUTE_UNUSED speed_p)
 {
   return 1;
 }
Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c	(revision 190865)
+++ gcc/config/rs6000/rs6000.c	(working copy)
@@ -928,7 +928,8 @@ 
 static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
 static int rs6000_memory_move_cost (enum machine_mode, reg_class_t, bool);
 static bool rs6000_debug_rtx_costs (rtx, int, int, int, int *, bool);
-static int rs6000_debug_address_cost (rtx, bool);
+static int rs6000_debug_address_cost (rtx, enum machine_mode, addr_space_t,
+				      bool);
 static int rs6000_debug_adjust_cost (rtx, rtx, rtx, int);
 static bool is_microcoded_insn (rtx);
 static bool is_nonpipeline_insn (rtx);
@@ -1294,7 +1295,7 @@ 
 #undef TARGET_RTX_COSTS
 #define TARGET_RTX_COSTS rs6000_rtx_costs
 #undef TARGET_ADDRESS_COST
-#define TARGET_ADDRESS_COST hook_int_rtx_bool_0
+#define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
 
 #undef TARGET_DWARF_REGISTER_SPAN
 #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
@@ -26070,7 +26071,8 @@ 
 /* Debug form of ADDRESS_COST that is selected if -mdebug=cost.  */
 
 static int
-rs6000_debug_address_cost (rtx x, bool speed)
+rs6000_debug_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+			   addr_space_t as ATTRIBUTE_UNUSED, bool speed)
 {
   int ret = TARGET_ADDRESS_COST (x, speed);
 
Index: gcc/config/avr/avr.c
===================================================================
--- gcc/config/avr/avr.c	(revision 190865)
+++ gcc/config/avr/avr.c	(working copy)
@@ -8886,7 +8886,9 @@ 
 /* Implement `TARGET_ADDRESS_COST'.  */
 
 static int
-avr_address_cost (rtx x, bool speed ATTRIBUTE_UNUSED)
+avr_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
+		  addr_space_t as ATTRIBUTE_UNUSED,
+		  bool speed ATTRIBUTE_UNUSED)
 {
   int cost = 4;
   
Index: gcc/config/pa/pa.c
===================================================================
--- gcc/config/pa/pa.c	(revision 190865)
+++ gcc/config/pa/pa.c	(working copy)
@@ -91,7 +91,7 @@ 
 static void fix_range (const char *);
 static int hppa_register_move_cost (enum machine_mode mode, reg_class_t,
 				    reg_class_t);
-static int hppa_address_cost (rtx, bool);
+static int hppa_address_cost (rtx, enum machine_mode mode, addr_space_t, bool);
 static bool hppa_rtx_costs (rtx, int, int, int, int *, bool);
 static inline rtx force_mode (enum machine_mode, rtx);
 static void pa_reorg (void);
@@ -1397,7 +1397,8 @@ 
    as GO_IF_LEGITIMATE_ADDRESS.  */
 
 static int
-hppa_address_cost (rtx X,
+hppa_address_cost (rtx X, enum machine_mode mode ATTRIBUTE_UNUSED,
+		   addr_space_t as ATTRIBUTE_UNUSED,
 		   bool speed ATTRIBUTE_UNUSED)
 {
   switch (GET_CODE (X))
Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c	(revision 190865)
+++ gcc/config/mips/mips.c	(working copy)
@@ -3943,9 +3943,11 @@ 
 /* Implement TARGET_ADDRESS_COST.  */
 
 static int
-mips_address_cost (rtx addr, bool speed ATTRIBUTE_UNUSED)
+mips_address_cost (rtx addr, enum machine_mode mode,
+		   addr_space_t as ATTRIBUTE_UNUSED,
+		   bool speed ATTRIBUTE_UNUSED)
 {
-  return mips_address_insns (addr, SImode, false);
+  return mips_address_insns (addr, mode, false);
 }
 
 /* Information about a single instruction in a multi-instruction
Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi	(revision 190865)
+++ gcc/doc/tm.texi	(working copy)
@@ -6440,7 +6440,7 @@ 
 processed, and false when @code{rtx_cost} should recurse.
 @end deftypefn
 
-@deftypefn {Target Hook} int TARGET_ADDRESS_COST (rtx @var{address}, bool @var{speed})
+@deftypefn {Target Hook} int TARGET_ADDRESS_COST (rtx @var{address}, enum machine_mode @var{mode}, addr_space_t @var{as}, bool @var{speed})
 This hook computes the cost of an addressing mode that contains
 @var{address}.  If not defined, the cost is computed from
 the @var{address} expression and the @code{TARGET_RTX_COST} hook.