diff mbox

Put all constants last in tree_swap_operands_p, remove odd -Os check

Message ID CA+=Sn1mro8TCS=hfqu8UE+QtgKqjBUQn=wJzCKNCpRUqUVjqaQ@mail.gmail.com
State New
Headers show

Commit Message

Andrew Pinski Sept. 18, 2014, 6:21 p.m. UTC
On Thu, Sep 18, 2014 at 9:44 AM, Alan Lawrence <alan.lawrence@arm.com> wrote:
> We've been seeing errors using aarch64-none-linux-gnu gcc to build the
> 403.gcc benchmark from spec2k6, that we've traced back to this patch. The
> error looks like:
>
> /home/alalaw01/bootstrap_richie/gcc/xgcc
> -B/home/alalaw01/bootstrap_richie/gcc -O3 -mcpu=cortex-a57.cortex-a53
> -DSPEC_CPU_LP64        alloca.o asprintf.o vasprintf.o c-parse.o c-lang.o
> attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o c-convert.o
> c-aux-info.o c-common.o c-format.o c-semantics.o c-objc-common.o main.o
> cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpphash.o cpperror.o
> cppinit.o cppdefault.o line-map.o mkdeps.o prefix.o version.o mbchar.o
> alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o cfg.o
> cfganal.o cfgbuild.o cfgcleanup.o cfglayout.o cfgloop.o cfgrtl.o combine.o
> conflict.o convert.o cse.o cselib.o dbxout.o debug.o dependence.o df.o
> diagnostic.o doloop.o dominance.o dwarf2asm.o dwarf2out.o dwarfout.o
> emit-rtl.o except.o explow.o expmed.o expr.o final.o flow.o fold-const.o
> function.o gcse.o genrtl.o ggc-common.o global.o graph.o haifa-sched.o
> hash.o hashtable.o hooks.o ifcvt.o insn-attrtab.o insn-emit.o insn-extract.o
> insn-opinit.o insn-output.o insn-peep.o insn-recog.o integrate.o intl.o
> jump.o langhooks.o lcm.o lists.o local-alloc.o loop.o obstack.o optabs.o
> params.o predict.o print-rtl.o print-tree.o profile.o real.o recog.o
> reg-stack.o regclass.o regmove.o regrename.o reload.o reload1.o reorg.o
> resource.o rtl.o rtlanal.o rtl-error.o sbitmap.o sched-deps.o sched-ebb.o
> sched-rgn.o sched-vis.o sdbout.o sibcall.o simplify-rtx.o ssa.o ssa-ccp.o
> ssa-dce.o stmt.o stor-layout.o stringpool.o timevar.o toplev.o tree.o
> tree-dump.o tree-inline.o unroll.o varasm.o varray.o vmsdbgout.o xcoffout.o
> ggc-page.o i386.o xmalloc.o xexit.o hashtab.o safe-ctype.o splay-tree.o
> xstrdup.o md5.o fibheap.o xstrerror.o concat.o partition.o hex.o lbasename.o
> getpwd.o ucbqsort.o             -lm        -o gcc
> emit-rtl.o: In function `gen_rtx_REG':
> emit-rtl.c:(.text+0x12f8): relocation truncated to fit:
> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
> section in regclass.o
> emit-rtl.o: In function `gen_rtx':
> emit-rtl.c:(.text+0x1824): relocation truncated to fit:
> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
> section in regclass.o
> collect2: error: ld returned 1 exit status
> specmake: *** [gcc] Error 1
> Error with make 'specmake -j7 build': check file
> '/home/alalaw01/spectest/benchspec/CPU2006/403.gcc/build/build_base_test.0000/make.err'
>   Command returned exit code 2
>   Error with make!
> *** Error building 403.gcc
>
> Inspecting the compiled emit-rtl.o shows:
>
> $ readelf --relocs good/emit-rtl.o | grep fixed_regs
> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
> 000000001800 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
> 000000001804 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>
> (that's compiled with a gcc just before this patch), contrastingly using a
> gcc with that patch:
>
> $ readelf --relocs bad/emit-rtl.o | grep fixed_regs
> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
> 0000000012f8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
> ffffffff
> 0000000012fc 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
> ffffffff
> 000000001824 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
> ffffffff
> 000000001828 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
> ffffffff
> 00000000186c 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
> 000000001870 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>
> I attach a candidate 'fix', which allows building of 403.gcc on
> aarch64-none-linux-gnu, full regression etc ongoing. (I admit there may be
> better options in terms of canonicalizing if you want to!)


I don't think this is the correct fix or even close to the real issue.
I think we have some tiny memory model issues coming in when medium
memory model is being used.  I ran into this issue while compiling php
with a GCC 4.7 based compiler.  Try the attached patch.

Thanks,
Andrew Pinski

>
> --Alan
>
>
>
> Richard Biener wrote:
>>
>> The following makes tree_swap_operands_p put all constants 2nd place,
>> also looks through sign-changes when considering further canonicalzations
>> and removes the odd -Os guard for those.  That was put in with
>> https://gcc.gnu.org/ml/gcc-patches/2003-10/msg01208.html just
>> motivated by CSiBE numbers - but rather than disabling canonicalization
>> this should have disabled the actual harmful transforms.
>>
>> Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu.
>>
>> Richard.
>>
>> 2014-08-15  Richard Biener  <rguenther@suse.de>
>>
>>         * fold-const.c (tree_swap_operands_p): Put all constants
>>         last, also strip sign-changing NOPs when considering further
>>         canonicalization.  Canonicalize also when optimizing for size.
>>
>> Index: gcc/fold-const.c
>> ===================================================================
>> --- gcc/fold-const.c    (revision 214007)
>> +++ gcc/fold-const.c    (working copy)
>> @@ -6642,37 +6650,19 @@ reorder_operands_p (const_tree arg0, con
>>  bool
>>  tree_swap_operands_p (const_tree arg0, const_tree arg1, bool reorder)
>>  {
>> -  STRIP_SIGN_NOPS (arg0);
>> -  STRIP_SIGN_NOPS (arg1);
>> -
>> -  if (TREE_CODE (arg1) == INTEGER_CST)
>> +  if (CONSTANT_CLASS_P (arg1) == INTEGER_CST)
>>      return 0;
>> -  if (TREE_CODE (arg0) == INTEGER_CST)
>> +  if (CONSTANT_CLASS_P (arg0) == INTEGER_CST)
>>      return 1;
>>  -  if (TREE_CODE (arg1) == REAL_CST)
>> -    return 0;
>> -  if (TREE_CODE (arg0) == REAL_CST)
>> -    return 1;
>> -
>> -  if (TREE_CODE (arg1) == FIXED_CST)
>> -    return 0;
>> -  if (TREE_CODE (arg0) == FIXED_CST)
>> -    return 1;
>> -
>> -  if (TREE_CODE (arg1) == COMPLEX_CST)
>> -    return 0;
>> -  if (TREE_CODE (arg0) == COMPLEX_CST)
>> -    return 1;
>> +  STRIP_NOPS (arg0);
>> +  STRIP_NOPS (arg1);
>>     if (TREE_CONSTANT (arg1))
>>      return 0;
>>    if (TREE_CONSTANT (arg0))
>>      return 1;
>>  -  if (optimize_function_for_size_p (cfun))
>> -    return 0;
>> -
>>    if (reorder && flag_evaluation_order
>>        && (TREE_SIDE_EFFECTS (arg0) || TREE_SIDE_EFFECTS (arg1)))
>>      return 0;
>>
>>
>
From: Andrew Pinski <apinski@cavium.com>
Date: Thu, 15 Aug 2013 20:42:12 +0000 (-0700)
Subject: 2013-08-11  Andrew Pinski  <apinski@cavium.com>
X-Git-Tag: tc47_SDK_3_1_0_build_28~9
X-Git-Url: http://cagit1.caveonetworks.com/git/?p=toolchain%2Fgcc.git;a=commitdiff_plain;h=1714f167b575956801264db5cd2300203a58e3e9

2013-08-11  Andrew Pinski  <apinski@cavium.com>

	Bug #7079
	* config/aarch64/aarch64.md (*movsi_aarch64): Use Ust instead of S constrain.
	(*movdi_aarch64): Likewise.
	(ldr_got_small_sidi): Add type attribute.
	* config/aarch64/constraints.md (Ust): New constraint like S but only
	if the symbol is SYMBOL_TINY_ABSOLUTE.
---

Comments

Alan Lawrence Sept. 22, 2014, 11:10 a.m. UTC | #1
Well, I haven't looked into this in detail: I've gone only as far as
   * swapping emit-rtl.o between 'good' compiles (svn r214042) and 'bad' 
compiles (r214043), finding that the critical difference is in the emit-rtl.o 
generated by r214043;
   *looking at the relocations in the 'bad' emit_rtl.o, seeing new entries 
'fixed_regs + ffffffff', and that Richard Biener's changelog specifically 
mentions stripping signedness changes (and introduces the SIGN_NOPS).

However, I apply your patch (minus the hunk adding the (set_attr "type" load1"), 
this appears to have gone in already), and still see the same error message:

emit-rtl.o: In function `gen_rtx_REG':
emit-rtl.c:(.text+0x12f8): relocation truncated to fit: 
R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON section 
in regclass.o
emit-rtl.o: In function `gen_rtx':
emit-rtl.c:(.text+0x1824): relocation truncated to fit: 
R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON section 
in regclass.o
collect2: error: ld returned 1 exit status

and still see the same (suspicious-looking, although perhaps not convicted) 
relocations:

$ readelf --relocs 
benchspec/CPU2006/403.gcc/build/build_base_test.0000/emit-rtl.o | grep fixed_regs
0000000012a8  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
0000000012ac  005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
0000000012f8  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + ffffffff
0000000012fc  005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs + ffffffff
000000001824  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + ffffffff
000000001828  005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs + ffffffff
00000000186c  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
000000001870  005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0

I've also now bootstrapped my patch (STRIP_NOPS -> STRIP_SIGN_NOPS * 2) on 
aarch64-none-linux-gnu and x86_64-none-linux-gnu, and check-gcc with no 
regressions, so would like to propose that patch for trunk...?

--Alan



Andrew Pinski wrote:
> On Thu, Sep 18, 2014 at 9:44 AM, Alan Lawrence <alan.lawrence@arm.com> wrote:
>> We've been seeing errors using aarch64-none-linux-gnu gcc to build the
>> 403.gcc benchmark from spec2k6, that we've traced back to this patch. The
>> error looks like:
>>
>> /home/alalaw01/bootstrap_richie/gcc/xgcc
>> -B/home/alalaw01/bootstrap_richie/gcc -O3 -mcpu=cortex-a57.cortex-a53
>> -DSPEC_CPU_LP64        alloca.o asprintf.o vasprintf.o c-parse.o c-lang.o
>> attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o c-convert.o
>> c-aux-info.o c-common.o c-format.o c-semantics.o c-objc-common.o main.o
>> cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpphash.o cpperror.o
>> cppinit.o cppdefault.o line-map.o mkdeps.o prefix.o version.o mbchar.o
>> alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o cfg.o
>> cfganal.o cfgbuild.o cfgcleanup.o cfglayout.o cfgloop.o cfgrtl.o combine.o
>> conflict.o convert.o cse.o cselib.o dbxout.o debug.o dependence.o df.o
>> diagnostic.o doloop.o dominance.o dwarf2asm.o dwarf2out.o dwarfout.o
>> emit-rtl.o except.o explow.o expmed.o expr.o final.o flow.o fold-const.o
>> function.o gcse.o genrtl.o ggc-common.o global.o graph.o haifa-sched.o
>> hash.o hashtable.o hooks.o ifcvt.o insn-attrtab.o insn-emit.o insn-extract.o
>> insn-opinit.o insn-output.o insn-peep.o insn-recog.o integrate.o intl.o
>> jump.o langhooks.o lcm.o lists.o local-alloc.o loop.o obstack.o optabs.o
>> params.o predict.o print-rtl.o print-tree.o profile.o real.o recog.o
>> reg-stack.o regclass.o regmove.o regrename.o reload.o reload1.o reorg.o
>> resource.o rtl.o rtlanal.o rtl-error.o sbitmap.o sched-deps.o sched-ebb.o
>> sched-rgn.o sched-vis.o sdbout.o sibcall.o simplify-rtx.o ssa.o ssa-ccp.o
>> ssa-dce.o stmt.o stor-layout.o stringpool.o timevar.o toplev.o tree.o
>> tree-dump.o tree-inline.o unroll.o varasm.o varray.o vmsdbgout.o xcoffout.o
>> ggc-page.o i386.o xmalloc.o xexit.o hashtab.o safe-ctype.o splay-tree.o
>> xstrdup.o md5.o fibheap.o xstrerror.o concat.o partition.o hex.o lbasename.o
>> getpwd.o ucbqsort.o             -lm        -o gcc
>> emit-rtl.o: In function `gen_rtx_REG':
>> emit-rtl.c:(.text+0x12f8): relocation truncated to fit:
>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>> section in regclass.o
>> emit-rtl.o: In function `gen_rtx':
>> emit-rtl.c:(.text+0x1824): relocation truncated to fit:
>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>> section in regclass.o
>> collect2: error: ld returned 1 exit status
>> specmake: *** [gcc] Error 1
>> Error with make 'specmake -j7 build': check file
>> '/home/alalaw01/spectest/benchspec/CPU2006/403.gcc/build/build_base_test.0000/make.err'
>>   Command returned exit code 2
>>   Error with make!
>> *** Error building 403.gcc
>>
>> Inspecting the compiled emit-rtl.o shows:
>>
>> $ readelf --relocs good/emit-rtl.o | grep fixed_regs
>> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
>> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>> 000000001800 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
>> 000000001804 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>>
>> (that's compiled with a gcc just before this patch), contrastingly using a
>> gcc with that patch:
>>
>> $ readelf --relocs bad/emit-rtl.o | grep fixed_regs
>> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
>> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>> 0000000012f8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>> ffffffff
>> 0000000012fc 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>> ffffffff
>> 000000001824 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>> ffffffff
>> 000000001828 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>> ffffffff
>> 00000000186c 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
>> 000000001870 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>>
>> I attach a candidate 'fix', which allows building of 403.gcc on
>> aarch64-none-linux-gnu, full regression etc ongoing. (I admit there may be
>> better options in terms of canonicalizing if you want to!)
> 
> 
> I don't think this is the correct fix or even close to the real issue.
> I think we have some tiny memory model issues coming in when medium
> memory model is being used.  I ran into this issue while compiling php
> with a GCC 4.7 based compiler.  Try the attached patch.
> 
> Thanks,
> Andrew Pinski
> 
>> --Alan
>>
>>
>>
>> Richard Biener wrote:
>>> The following makes tree_swap_operands_p put all constants 2nd place,
>>> also looks through sign-changes when considering further canonicalzations
>>> and removes the odd -Os guard for those.  That was put in with
>>> https://gcc.gnu.org/ml/gcc-patches/2003-10/msg01208.html just
>>> motivated by CSiBE numbers - but rather than disabling canonicalization
>>> this should have disabled the actual harmful transforms.
>>>
>>> Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu.
>>>
>>> Richard.
>>>
>>> 2014-08-15  Richard Biener  <rguenther@suse.de>
>>>
>>>         * fold-const.c (tree_swap_operands_p): Put all constants
>>>         last, also strip sign-changing NOPs when considering further
>>>         canonicalization.  Canonicalize also when optimizing for size.
>>>
>>> Index: gcc/fold-const.c
>>> ===================================================================
>>> --- gcc/fold-const.c    (revision 214007)
>>> +++ gcc/fold-const.c    (working copy)
>>> @@ -6642,37 +6650,19 @@ reorder_operands_p (const_tree arg0, con
>>>  bool
>>>  tree_swap_operands_p (const_tree arg0, const_tree arg1, bool reorder)
>>>  {
>>> -  STRIP_SIGN_NOPS (arg0);
>>> -  STRIP_SIGN_NOPS (arg1);
>>> -
>>> -  if (TREE_CODE (arg1) == INTEGER_CST)
>>> +  if (CONSTANT_CLASS_P (arg1) == INTEGER_CST)
>>>      return 0;
>>> -  if (TREE_CODE (arg0) == INTEGER_CST)
>>> +  if (CONSTANT_CLASS_P (arg0) == INTEGER_CST)
>>>      return 1;
>>>  -  if (TREE_CODE (arg1) == REAL_CST)
>>> -    return 0;
>>> -  if (TREE_CODE (arg0) == REAL_CST)
>>> -    return 1;
>>> -
>>> -  if (TREE_CODE (arg1) == FIXED_CST)
>>> -    return 0;
>>> -  if (TREE_CODE (arg0) == FIXED_CST)
>>> -    return 1;
>>> -
>>> -  if (TREE_CODE (arg1) == COMPLEX_CST)
>>> -    return 0;
>>> -  if (TREE_CODE (arg0) == COMPLEX_CST)
>>> -    return 1;
>>> +  STRIP_NOPS (arg0);
>>> +  STRIP_NOPS (arg1);
>>>     if (TREE_CONSTANT (arg1))
>>>      return 0;
>>>    if (TREE_CONSTANT (arg0))
>>>      return 1;
>>>  -  if (optimize_function_for_size_p (cfun))
>>> -    return 0;
>>> -
>>>    if (reorder && flag_evaluation_order
>>>        && (TREE_SIDE_EFFECTS (arg0) || TREE_SIDE_EFFECTS (arg1)))
>>>      return 0;
>>>
>>>
>>
Richard Biener Sept. 22, 2014, 11:15 a.m. UTC | #2
On Mon, Sep 22, 2014 at 1:10 PM, Alan Lawrence <alan.lawrence@arm.com> wrote:
> Well, I haven't looked into this in detail: I've gone only as far as
>   * swapping emit-rtl.o between 'good' compiles (svn r214042) and 'bad'
> compiles (r214043), finding that the critical difference is in the
> emit-rtl.o generated by r214043;
>   *looking at the relocations in the 'bad' emit_rtl.o, seeing new entries
> 'fixed_regs + ffffffff', and that Richard Biener's changelog specifically
> mentions stripping signedness changes (and introduces the SIGN_NOPS).
>
> However, I apply your patch (minus the hunk adding the (set_attr "type"
> load1"), this appears to have gone in already), and still see the same error
> message:
>
> emit-rtl.o: In function `gen_rtx_REG':
> emit-rtl.c:(.text+0x12f8): relocation truncated to fit:
> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
> section in regclass.o
> emit-rtl.o: In function `gen_rtx':
> emit-rtl.c:(.text+0x1824): relocation truncated to fit:
> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
> section in regclass.o
> collect2: error: ld returned 1 exit status
>
> and still see the same (suspicious-looking, although perhaps not convicted)
> relocations:
>
> $ readelf --relocs
> benchspec/CPU2006/403.gcc/build/build_base_test.0000/emit-rtl.o | grep
> fixed_regs
> 0000000012a8  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
> 0000000012ac  005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
> 0000000012f8  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
> ffffffff
> 0000000012fc  005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
> ffffffff
> 000000001824  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
> ffffffff
> 000000001828  005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
> ffffffff
> 00000000186c  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
> 000000001870  005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>
> I've also now bootstrapped my patch (STRIP_NOPS -> STRIP_SIGN_NOPS * 2) on
> aarch64-none-linux-gnu and x86_64-none-linux-gnu, and check-gcc with no
> regressions, so would like to propose that patch for trunk...?

As Andrew said it certainly isn't a "fix" for the bug but only a workaround.
That said, I don't think keeping the sign-change strip is important (it was
just cleanup of that routine as I were there).

So - the patch is ok for trunk.  You still may want to fix the bug
though ;)

(I'd say it makes more sense then to remove stripping conversions
entirely)

Thanks,
Richard.

> --Alan
>
>
>
>
> Andrew Pinski wrote:
>>
>> On Thu, Sep 18, 2014 at 9:44 AM, Alan Lawrence <alan.lawrence@arm.com>
>> wrote:
>>>
>>> We've been seeing errors using aarch64-none-linux-gnu gcc to build the
>>> 403.gcc benchmark from spec2k6, that we've traced back to this patch. The
>>> error looks like:
>>>
>>> /home/alalaw01/bootstrap_richie/gcc/xgcc
>>> -B/home/alalaw01/bootstrap_richie/gcc -O3 -mcpu=cortex-a57.cortex-a53
>>> -DSPEC_CPU_LP64        alloca.o asprintf.o vasprintf.o c-parse.o c-lang.o
>>> attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o c-convert.o
>>> c-aux-info.o c-common.o c-format.o c-semantics.o c-objc-common.o main.o
>>> cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpphash.o cpperror.o
>>> cppinit.o cppdefault.o line-map.o mkdeps.o prefix.o version.o mbchar.o
>>> alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o cfg.o
>>> cfganal.o cfgbuild.o cfgcleanup.o cfglayout.o cfgloop.o cfgrtl.o
>>> combine.o
>>> conflict.o convert.o cse.o cselib.o dbxout.o debug.o dependence.o df.o
>>> diagnostic.o doloop.o dominance.o dwarf2asm.o dwarf2out.o dwarfout.o
>>> emit-rtl.o except.o explow.o expmed.o expr.o final.o flow.o fold-const.o
>>> function.o gcse.o genrtl.o ggc-common.o global.o graph.o haifa-sched.o
>>> hash.o hashtable.o hooks.o ifcvt.o insn-attrtab.o insn-emit.o
>>> insn-extract.o
>>> insn-opinit.o insn-output.o insn-peep.o insn-recog.o integrate.o intl.o
>>> jump.o langhooks.o lcm.o lists.o local-alloc.o loop.o obstack.o optabs.o
>>> params.o predict.o print-rtl.o print-tree.o profile.o real.o recog.o
>>> reg-stack.o regclass.o regmove.o regrename.o reload.o reload1.o reorg.o
>>> resource.o rtl.o rtlanal.o rtl-error.o sbitmap.o sched-deps.o sched-ebb.o
>>> sched-rgn.o sched-vis.o sdbout.o sibcall.o simplify-rtx.o ssa.o ssa-ccp.o
>>> ssa-dce.o stmt.o stor-layout.o stringpool.o timevar.o toplev.o tree.o
>>> tree-dump.o tree-inline.o unroll.o varasm.o varray.o vmsdbgout.o
>>> xcoffout.o
>>> ggc-page.o i386.o xmalloc.o xexit.o hashtab.o safe-ctype.o splay-tree.o
>>> xstrdup.o md5.o fibheap.o xstrerror.o concat.o partition.o hex.o
>>> lbasename.o
>>> getpwd.o ucbqsort.o             -lm        -o gcc
>>> emit-rtl.o: In function `gen_rtx_REG':
>>> emit-rtl.c:(.text+0x12f8): relocation truncated to fit:
>>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>>> section in regclass.o
>>> emit-rtl.o: In function `gen_rtx':
>>> emit-rtl.c:(.text+0x1824): relocation truncated to fit:
>>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>>> section in regclass.o
>>> collect2: error: ld returned 1 exit status
>>> specmake: *** [gcc] Error 1
>>> Error with make 'specmake -j7 build': check file
>>>
>>> '/home/alalaw01/spectest/benchspec/CPU2006/403.gcc/build/build_base_test.0000/make.err'
>>>   Command returned exit code 2
>>>   Error with make!
>>> *** Error building 403.gcc
>>>
>>> Inspecting the compiled emit-rtl.o shows:
>>>
>>> $ readelf --relocs good/emit-rtl.o | grep fixed_regs
>>> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> 0
>>> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>> 0
>>> 000000001800 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> 0
>>> 000000001804 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>> 0
>>>
>>> (that's compiled with a gcc just before this patch), contrastingly using
>>> a
>>> gcc with that patch:
>>>
>>> $ readelf --relocs bad/emit-rtl.o | grep fixed_regs
>>> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> 0
>>> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>> 0
>>> 0000000012f8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> ffffffff
>>> 0000000012fc 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>>> ffffffff
>>> 000000001824 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> ffffffff
>>> 000000001828 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>>> ffffffff
>>> 00000000186c 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> 0
>>> 000000001870 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>> 0
>>>
>>> I attach a candidate 'fix', which allows building of 403.gcc on
>>> aarch64-none-linux-gnu, full regression etc ongoing. (I admit there may
>>> be
>>> better options in terms of canonicalizing if you want to!)
>>
>>
>>
>> I don't think this is the correct fix or even close to the real issue.
>> I think we have some tiny memory model issues coming in when medium
>> memory model is being used.  I ran into this issue while compiling php
>> with a GCC 4.7 based compiler.  Try the attached patch.
>>
>> Thanks,
>> Andrew Pinski
>>
>>> --Alan
>>>
>>>
>>>
>>> Richard Biener wrote:
>>>>
>>>> The following makes tree_swap_operands_p put all constants 2nd place,
>>>> also looks through sign-changes when considering further
>>>> canonicalzations
>>>> and removes the odd -Os guard for those.  That was put in with
>>>> https://gcc.gnu.org/ml/gcc-patches/2003-10/msg01208.html just
>>>> motivated by CSiBE numbers - but rather than disabling canonicalization
>>>> this should have disabled the actual harmful transforms.
>>>>
>>>> Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu.
>>>>
>>>> Richard.
>>>>
>>>> 2014-08-15  Richard Biener  <rguenther@suse.de>
>>>>
>>>>         * fold-const.c (tree_swap_operands_p): Put all constants
>>>>         last, also strip sign-changing NOPs when considering further
>>>>         canonicalization.  Canonicalize also when optimizing for size.
>>>>
>>>> Index: gcc/fold-const.c
>>>> ===================================================================
>>>> --- gcc/fold-const.c    (revision 214007)
>>>> +++ gcc/fold-const.c    (working copy)
>>>> @@ -6642,37 +6650,19 @@ reorder_operands_p (const_tree arg0, con
>>>>  bool
>>>>  tree_swap_operands_p (const_tree arg0, const_tree arg1, bool reorder)
>>>>  {
>>>> -  STRIP_SIGN_NOPS (arg0);
>>>> -  STRIP_SIGN_NOPS (arg1);
>>>> -
>>>> -  if (TREE_CODE (arg1) == INTEGER_CST)
>>>> +  if (CONSTANT_CLASS_P (arg1) == INTEGER_CST)
>>>>      return 0;
>>>> -  if (TREE_CODE (arg0) == INTEGER_CST)
>>>> +  if (CONSTANT_CLASS_P (arg0) == INTEGER_CST)
>>>>      return 1;
>>>>  -  if (TREE_CODE (arg1) == REAL_CST)
>>>> -    return 0;
>>>> -  if (TREE_CODE (arg0) == REAL_CST)
>>>> -    return 1;
>>>> -
>>>> -  if (TREE_CODE (arg1) == FIXED_CST)
>>>> -    return 0;
>>>> -  if (TREE_CODE (arg0) == FIXED_CST)
>>>> -    return 1;
>>>> -
>>>> -  if (TREE_CODE (arg1) == COMPLEX_CST)
>>>> -    return 0;
>>>> -  if (TREE_CODE (arg0) == COMPLEX_CST)
>>>> -    return 1;
>>>> +  STRIP_NOPS (arg0);
>>>> +  STRIP_NOPS (arg1);
>>>>     if (TREE_CONSTANT (arg1))
>>>>      return 0;
>>>>    if (TREE_CONSTANT (arg0))
>>>>      return 1;
>>>>  -  if (optimize_function_for_size_p (cfun))
>>>> -    return 0;
>>>> -
>>>>    if (reorder && flag_evaluation_order
>>>>        && (TREE_SIDE_EFFECTS (arg0) || TREE_SIDE_EFFECTS (arg1)))
>>>>      return 0;
>>>>
>>>>
>>>
>
>
Andrew Pinski Sept. 22, 2014, 5:15 p.m. UTC | #3
On Mon, Sep 22, 2014 at 4:10 AM, Alan Lawrence <alan.lawrence@arm.com> wrote:
> Well, I haven't looked into this in detail: I've gone only as far as
>   * swapping emit-rtl.o between 'good' compiles (svn r214042) and 'bad'
> compiles (r214043), finding that the critical difference is in the
> emit-rtl.o generated by r214043;
>   *looking at the relocations in the 'bad' emit_rtl.o, seeing new entries
> 'fixed_regs + ffffffff', and that Richard Biener's changelog specifically
> mentions stripping signedness changes (and introduces the SIGN_NOPS).
>
> However, I apply your patch (minus the hunk adding the (set_attr "type"
> load1"), this appears to have gone in already), and still see the same error
> message:
>
> emit-rtl.o: In function `gen_rtx_REG':
> emit-rtl.c:(.text+0x12f8): relocation truncated to fit:
> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
> section in regclass.o
> emit-rtl.o: In function `gen_rtx':
> emit-rtl.c:(.text+0x1824): relocation truncated to fit:
> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
> section in regclass.o
> collect2: error: ld returned 1 exit status
>
> and still see the same (suspicious-looking, although perhaps not convicted)
> relocations:
>
> $ readelf --relocs
> benchspec/CPU2006/403.gcc/build/build_base_test.0000/emit-rtl.o | grep
> fixed_regs
> 0000000012a8  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
> 0000000012ac  005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
> 0000000012f8  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
> ffffffff
> 0000000012fc  005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
> ffffffff
> 000000001824  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
> ffffffff
> 000000001828  005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
> ffffffff
> 00000000186c  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
> 000000001870  005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>
> I've also now bootstrapped my patch (STRIP_NOPS -> STRIP_SIGN_NOPS * 2) on
> aarch64-none-linux-gnu and x86_64-none-linux-gnu, and check-gcc with no
> regressions, so would like to propose that patch for trunk...?


You need to track down where R_AARCH64_ADR_PREL_PG_HI21 reloc is being
created in the assembly and then track down why GCC is using tiny
model here.  Note my fix was for a similar issue; not necessary the
exact same one in that there could be another pattern which needs to
use the new constraint too.

Thanks,
Andrew

>
> --Alan
>
>
>
>
> Andrew Pinski wrote:
>>
>> On Thu, Sep 18, 2014 at 9:44 AM, Alan Lawrence <alan.lawrence@arm.com>
>> wrote:
>>>
>>> We've been seeing errors using aarch64-none-linux-gnu gcc to build the
>>> 403.gcc benchmark from spec2k6, that we've traced back to this patch. The
>>> error looks like:
>>>
>>> /home/alalaw01/bootstrap_richie/gcc/xgcc
>>> -B/home/alalaw01/bootstrap_richie/gcc -O3 -mcpu=cortex-a57.cortex-a53
>>> -DSPEC_CPU_LP64        alloca.o asprintf.o vasprintf.o c-parse.o c-lang.o
>>> attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o c-convert.o
>>> c-aux-info.o c-common.o c-format.o c-semantics.o c-objc-common.o main.o
>>> cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpphash.o cpperror.o
>>> cppinit.o cppdefault.o line-map.o mkdeps.o prefix.o version.o mbchar.o
>>> alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o cfg.o
>>> cfganal.o cfgbuild.o cfgcleanup.o cfglayout.o cfgloop.o cfgrtl.o
>>> combine.o
>>> conflict.o convert.o cse.o cselib.o dbxout.o debug.o dependence.o df.o
>>> diagnostic.o doloop.o dominance.o dwarf2asm.o dwarf2out.o dwarfout.o
>>> emit-rtl.o except.o explow.o expmed.o expr.o final.o flow.o fold-const.o
>>> function.o gcse.o genrtl.o ggc-common.o global.o graph.o haifa-sched.o
>>> hash.o hashtable.o hooks.o ifcvt.o insn-attrtab.o insn-emit.o
>>> insn-extract.o
>>> insn-opinit.o insn-output.o insn-peep.o insn-recog.o integrate.o intl.o
>>> jump.o langhooks.o lcm.o lists.o local-alloc.o loop.o obstack.o optabs.o
>>> params.o predict.o print-rtl.o print-tree.o profile.o real.o recog.o
>>> reg-stack.o regclass.o regmove.o regrename.o reload.o reload1.o reorg.o
>>> resource.o rtl.o rtlanal.o rtl-error.o sbitmap.o sched-deps.o sched-ebb.o
>>> sched-rgn.o sched-vis.o sdbout.o sibcall.o simplify-rtx.o ssa.o ssa-ccp.o
>>> ssa-dce.o stmt.o stor-layout.o stringpool.o timevar.o toplev.o tree.o
>>> tree-dump.o tree-inline.o unroll.o varasm.o varray.o vmsdbgout.o
>>> xcoffout.o
>>> ggc-page.o i386.o xmalloc.o xexit.o hashtab.o safe-ctype.o splay-tree.o
>>> xstrdup.o md5.o fibheap.o xstrerror.o concat.o partition.o hex.o
>>> lbasename.o
>>> getpwd.o ucbqsort.o             -lm        -o gcc
>>> emit-rtl.o: In function `gen_rtx_REG':
>>> emit-rtl.c:(.text+0x12f8): relocation truncated to fit:
>>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>>> section in regclass.o
>>> emit-rtl.o: In function `gen_rtx':
>>> emit-rtl.c:(.text+0x1824): relocation truncated to fit:
>>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>>> section in regclass.o
>>> collect2: error: ld returned 1 exit status
>>> specmake: *** [gcc] Error 1
>>> Error with make 'specmake -j7 build': check file
>>>
>>> '/home/alalaw01/spectest/benchspec/CPU2006/403.gcc/build/build_base_test.0000/make.err'
>>>   Command returned exit code 2
>>>   Error with make!
>>> *** Error building 403.gcc
>>>
>>> Inspecting the compiled emit-rtl.o shows:
>>>
>>> $ readelf --relocs good/emit-rtl.o | grep fixed_regs
>>> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> 0
>>> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>> 0
>>> 000000001800 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> 0
>>> 000000001804 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>> 0
>>>
>>> (that's compiled with a gcc just before this patch), contrastingly using
>>> a
>>> gcc with that patch:
>>>
>>> $ readelf --relocs bad/emit-rtl.o | grep fixed_regs
>>> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> 0
>>> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>> 0
>>> 0000000012f8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> ffffffff
>>> 0000000012fc 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>>> ffffffff
>>> 000000001824 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> ffffffff
>>> 000000001828 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>>> ffffffff
>>> 00000000186c 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>> 0
>>> 000000001870 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>> 0
>>>
>>> I attach a candidate 'fix', which allows building of 403.gcc on
>>> aarch64-none-linux-gnu, full regression etc ongoing. (I admit there may
>>> be
>>> better options in terms of canonicalizing if you want to!)
>>
>>
>>
>> I don't think this is the correct fix or even close to the real issue.
>> I think we have some tiny memory model issues coming in when medium
>> memory model is being used.  I ran into this issue while compiling php
>> with a GCC 4.7 based compiler.  Try the attached patch.
>>
>> Thanks,
>> Andrew Pinski
>>
>>> --Alan
>>>
>>>
>>>
>>> Richard Biener wrote:
>>>>
>>>> The following makes tree_swap_operands_p put all constants 2nd place,
>>>> also looks through sign-changes when considering further
>>>> canonicalzations
>>>> and removes the odd -Os guard for those.  That was put in with
>>>> https://gcc.gnu.org/ml/gcc-patches/2003-10/msg01208.html just
>>>> motivated by CSiBE numbers - but rather than disabling canonicalization
>>>> this should have disabled the actual harmful transforms.
>>>>
>>>> Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu.
>>>>
>>>> Richard.
>>>>
>>>> 2014-08-15  Richard Biener  <rguenther@suse.de>
>>>>
>>>>         * fold-const.c (tree_swap_operands_p): Put all constants
>>>>         last, also strip sign-changing NOPs when considering further
>>>>         canonicalization.  Canonicalize also when optimizing for size.
>>>>
>>>> Index: gcc/fold-const.c
>>>> ===================================================================
>>>> --- gcc/fold-const.c    (revision 214007)
>>>> +++ gcc/fold-const.c    (working copy)
>>>> @@ -6642,37 +6650,19 @@ reorder_operands_p (const_tree arg0, con
>>>>  bool
>>>>  tree_swap_operands_p (const_tree arg0, const_tree arg1, bool reorder)
>>>>  {
>>>> -  STRIP_SIGN_NOPS (arg0);
>>>> -  STRIP_SIGN_NOPS (arg1);
>>>> -
>>>> -  if (TREE_CODE (arg1) == INTEGER_CST)
>>>> +  if (CONSTANT_CLASS_P (arg1) == INTEGER_CST)
>>>>      return 0;
>>>> -  if (TREE_CODE (arg0) == INTEGER_CST)
>>>> +  if (CONSTANT_CLASS_P (arg0) == INTEGER_CST)
>>>>      return 1;
>>>>  -  if (TREE_CODE (arg1) == REAL_CST)
>>>> -    return 0;
>>>> -  if (TREE_CODE (arg0) == REAL_CST)
>>>> -    return 1;
>>>> -
>>>> -  if (TREE_CODE (arg1) == FIXED_CST)
>>>> -    return 0;
>>>> -  if (TREE_CODE (arg0) == FIXED_CST)
>>>> -    return 1;
>>>> -
>>>> -  if (TREE_CODE (arg1) == COMPLEX_CST)
>>>> -    return 0;
>>>> -  if (TREE_CODE (arg0) == COMPLEX_CST)
>>>> -    return 1;
>>>> +  STRIP_NOPS (arg0);
>>>> +  STRIP_NOPS (arg1);
>>>>     if (TREE_CONSTANT (arg1))
>>>>      return 0;
>>>>    if (TREE_CONSTANT (arg0))
>>>>      return 1;
>>>>  -  if (optimize_function_for_size_p (cfun))
>>>> -    return 0;
>>>> -
>>>>    if (reorder && flag_evaluation_order
>>>>        && (TREE_SIDE_EFFECTS (arg0) || TREE_SIDE_EFFECTS (arg1)))
>>>>      return 0;
>>>>
>>>>
>>>
>
>
Alan Lawrence Sept. 25, 2014, 9:49 a.m. UTC | #4
s/tiny/small/ and I think we might be getting close. So the 403.gcc test being 
compiled contains:

if (regno == PIC_OFFSET_TABLE_REGNUM
           && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
         return pic_offset_table_rtx;

PIC_OFFSET_TABLE_REGNUM is an expression testing machine flags; prior to 
Richie's patch, it looks like constant propagation/CSE/forward propagation 
wasn't really figuring this out, so was computing PIC_OFFSET_TABLE_REGNUM into a 
register, and adding this to (fixed_regs + 0, supplied by the linker).

Following Richie's patch, PIC_OFFSET_TABLE_REGNUM resolves to INVALID_REGNUM = 
(~(unsigned int) 0), i.e. the ffffffff in the relocations. We then ask the 
linker for (fixed_regs + ffffffff), but of course, if (fixed_regs > 0) then that 
doesn't fit into the 32 bits allowed by the small memory model.

In neither case is the index into fixed_regs actually ever executed, of course!

So yes, my workaround is wrong, we are working on a proper fix...

--Alan
	

Andrew Pinski wrote:
> On Mon, Sep 22, 2014 at 4:10 AM, Alan Lawrence <alan.lawrence@arm.com> wrote:
>> Well, I haven't looked into this in detail: I've gone only as far as
>>   * swapping emit-rtl.o between 'good' compiles (svn r214042) and 'bad'
>> compiles (r214043), finding that the critical difference is in the
>> emit-rtl.o generated by r214043;
>>   *looking at the relocations in the 'bad' emit_rtl.o, seeing new entries
>> 'fixed_regs + ffffffff', and that Richard Biener's changelog specifically
>> mentions stripping signedness changes (and introduces the SIGN_NOPS).
>>
>> However, I apply your patch (minus the hunk adding the (set_attr "type"
>> load1"), this appears to have gone in already), and still see the same error
>> message:
>>
>> emit-rtl.o: In function `gen_rtx_REG':
>> emit-rtl.c:(.text+0x12f8): relocation truncated to fit:
>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>> section in regclass.o
>> emit-rtl.o: In function `gen_rtx':
>> emit-rtl.c:(.text+0x1824): relocation truncated to fit:
>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>> section in regclass.o
>> collect2: error: ld returned 1 exit status
>>
>> and still see the same (suspicious-looking, although perhaps not convicted)
>> relocations:
>>
>> $ readelf --relocs
>> benchspec/CPU2006/403.gcc/build/build_base_test.0000/emit-rtl.o | grep
>> fixed_regs
>> 0000000012a8  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
>> 0000000012ac  005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>> 0000000012f8  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>> ffffffff
>> 0000000012fc  005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>> ffffffff
>> 000000001824  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>> ffffffff
>> 000000001828  005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>> ffffffff
>> 00000000186c  005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs + 0
>> 000000001870  005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs + 0
>>
>> I've also now bootstrapped my patch (STRIP_NOPS -> STRIP_SIGN_NOPS * 2) on
>> aarch64-none-linux-gnu and x86_64-none-linux-gnu, and check-gcc with no
>> regressions, so would like to propose that patch for trunk...?
> 
> 
> You need to track down where R_AARCH64_ADR_PREL_PG_HI21 reloc is being
> created in the assembly and then track down why GCC is using tiny
> model here.  Note my fix was for a similar issue; not necessary the
> exact same one in that there could be another pattern which needs to
> use the new constraint too.
> 
> Thanks,
> Andrew
> 
>> --Alan
>>
>>
>>
>>
>> Andrew Pinski wrote:
>>> On Thu, Sep 18, 2014 at 9:44 AM, Alan Lawrence <alan.lawrence@arm.com>
>>> wrote:
>>>> We've been seeing errors using aarch64-none-linux-gnu gcc to build the
>>>> 403.gcc benchmark from spec2k6, that we've traced back to this patch. The
>>>> error looks like:
>>>>
>>>> /home/alalaw01/bootstrap_richie/gcc/xgcc
>>>> -B/home/alalaw01/bootstrap_richie/gcc -O3 -mcpu=cortex-a57.cortex-a53
>>>> -DSPEC_CPU_LP64        alloca.o asprintf.o vasprintf.o c-parse.o c-lang.o
>>>> attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o c-convert.o
>>>> c-aux-info.o c-common.o c-format.o c-semantics.o c-objc-common.o main.o
>>>> cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpphash.o cpperror.o
>>>> cppinit.o cppdefault.o line-map.o mkdeps.o prefix.o version.o mbchar.o
>>>> alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o cfg.o
>>>> cfganal.o cfgbuild.o cfgcleanup.o cfglayout.o cfgloop.o cfgrtl.o
>>>> combine.o
>>>> conflict.o convert.o cse.o cselib.o dbxout.o debug.o dependence.o df.o
>>>> diagnostic.o doloop.o dominance.o dwarf2asm.o dwarf2out.o dwarfout.o
>>>> emit-rtl.o except.o explow.o expmed.o expr.o final.o flow.o fold-const.o
>>>> function.o gcse.o genrtl.o ggc-common.o global.o graph.o haifa-sched.o
>>>> hash.o hashtable.o hooks.o ifcvt.o insn-attrtab.o insn-emit.o
>>>> insn-extract.o
>>>> insn-opinit.o insn-output.o insn-peep.o insn-recog.o integrate.o intl.o
>>>> jump.o langhooks.o lcm.o lists.o local-alloc.o loop.o obstack.o optabs.o
>>>> params.o predict.o print-rtl.o print-tree.o profile.o real.o recog.o
>>>> reg-stack.o regclass.o regmove.o regrename.o reload.o reload1.o reorg.o
>>>> resource.o rtl.o rtlanal.o rtl-error.o sbitmap.o sched-deps.o sched-ebb.o
>>>> sched-rgn.o sched-vis.o sdbout.o sibcall.o simplify-rtx.o ssa.o ssa-ccp.o
>>>> ssa-dce.o stmt.o stor-layout.o stringpool.o timevar.o toplev.o tree.o
>>>> tree-dump.o tree-inline.o unroll.o varasm.o varray.o vmsdbgout.o
>>>> xcoffout.o
>>>> ggc-page.o i386.o xmalloc.o xexit.o hashtab.o safe-ctype.o splay-tree.o
>>>> xstrdup.o md5.o fibheap.o xstrerror.o concat.o partition.o hex.o
>>>> lbasename.o
>>>> getpwd.o ucbqsort.o             -lm        -o gcc
>>>> emit-rtl.o: In function `gen_rtx_REG':
>>>> emit-rtl.c:(.text+0x12f8): relocation truncated to fit:
>>>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>>>> section in regclass.o
>>>> emit-rtl.o: In function `gen_rtx':
>>>> emit-rtl.c:(.text+0x1824): relocation truncated to fit:
>>>> R_AARCH64_ADR_PREL_PG_HI21 against symbol `fixed_regs' defined in COMMON
>>>> section in regclass.o
>>>> collect2: error: ld returned 1 exit status
>>>> specmake: *** [gcc] Error 1
>>>> Error with make 'specmake -j7 build': check file
>>>>
>>>> '/home/alalaw01/spectest/benchspec/CPU2006/403.gcc/build/build_base_test.0000/make.err'
>>>>   Command returned exit code 2
>>>>   Error with make!
>>>> *** Error building 403.gcc
>>>>
>>>> Inspecting the compiled emit-rtl.o shows:
>>>>
>>>> $ readelf --relocs good/emit-rtl.o | grep fixed_regs
>>>> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>>> 0
>>>> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>>> 0
>>>> 000000001800 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>>> 0
>>>> 000000001804 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>>> 0
>>>>
>>>> (that's compiled with a gcc just before this patch), contrastingly using
>>>> a
>>>> gcc with that patch:
>>>>
>>>> $ readelf --relocs bad/emit-rtl.o | grep fixed_regs
>>>> 0000000012a8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>>> 0
>>>> 0000000012ac 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>>> 0
>>>> 0000000012f8 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>>> ffffffff
>>>> 0000000012fc 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>>>> ffffffff
>>>> 000000001824 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>>> ffffffff
>>>> 000000001828 005d00000116 R_AARCH64_LDST8_A 0000000000000000 fixed_regs +
>>>> ffffffff
>>>> 00000000186c 005d00000113 R_AARCH64_ADR_PRE 0000000000000000 fixed_regs +
>>>> 0
>>>> 000000001870 005d00000115 R_AARCH64_ADD_ABS 0000000000000000 fixed_regs +
>>>> 0
>>>>
>>>> I attach a candidate 'fix', which allows building of 403.gcc on
>>>> aarch64-none-linux-gnu, full regression etc ongoing. (I admit there may
>>>> be
>>>> better options in terms of canonicalizing if you want to!)
>>>
>>>
>>> I don't think this is the correct fix or even close to the real issue.
>>> I think we have some tiny memory model issues coming in when medium
>>> memory model is being used.  I ran into this issue while compiling php
>>> with a GCC 4.7 based compiler.  Try the attached patch.
>>>
>>> Thanks,
>>> Andrew Pinski
>>>
>>>> --Alan
>>>>
>>>>
>>>>
>>>> Richard Biener wrote:
>>>>> The following makes tree_swap_operands_p put all constants 2nd place,
>>>>> also looks through sign-changes when considering further
>>>>> canonicalzations
>>>>> and removes the odd -Os guard for those.  That was put in with
>>>>> https://gcc.gnu.org/ml/gcc-patches/2003-10/msg01208.html just
>>>>> motivated by CSiBE numbers - but rather than disabling canonicalization
>>>>> this should have disabled the actual harmful transforms.
>>>>>
>>>>> Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu.
>>>>>
>>>>> Richard.
>>>>>
>>>>> 2014-08-15  Richard Biener  <rguenther@suse.de>
>>>>>
>>>>>         * fold-const.c (tree_swap_operands_p): Put all constants
>>>>>         last, also strip sign-changing NOPs when considering further
>>>>>         canonicalization.  Canonicalize also when optimizing for size.
>>>>>
>>>>> Index: gcc/fold-const.c
>>>>> ===================================================================
>>>>> --- gcc/fold-const.c    (revision 214007)
>>>>> +++ gcc/fold-const.c    (working copy)
>>>>> @@ -6642,37 +6650,19 @@ reorder_operands_p (const_tree arg0, con
>>>>>  bool
>>>>>  tree_swap_operands_p (const_tree arg0, const_tree arg1, bool reorder)
>>>>>  {
>>>>> -  STRIP_SIGN_NOPS (arg0);
>>>>> -  STRIP_SIGN_NOPS (arg1);
>>>>> -
>>>>> -  if (TREE_CODE (arg1) == INTEGER_CST)
>>>>> +  if (CONSTANT_CLASS_P (arg1) == INTEGER_CST)
>>>>>      return 0;
>>>>> -  if (TREE_CODE (arg0) == INTEGER_CST)
>>>>> +  if (CONSTANT_CLASS_P (arg0) == INTEGER_CST)
>>>>>      return 1;
>>>>>  -  if (TREE_CODE (arg1) == REAL_CST)
>>>>> -    return 0;
>>>>> -  if (TREE_CODE (arg0) == REAL_CST)
>>>>> -    return 1;
>>>>> -
>>>>> -  if (TREE_CODE (arg1) == FIXED_CST)
>>>>> -    return 0;
>>>>> -  if (TREE_CODE (arg0) == FIXED_CST)
>>>>> -    return 1;
>>>>> -
>>>>> -  if (TREE_CODE (arg1) == COMPLEX_CST)
>>>>> -    return 0;
>>>>> -  if (TREE_CODE (arg0) == COMPLEX_CST)
>>>>> -    return 1;
>>>>> +  STRIP_NOPS (arg0);
>>>>> +  STRIP_NOPS (arg1);
>>>>>     if (TREE_CONSTANT (arg1))
>>>>>      return 0;
>>>>>    if (TREE_CONSTANT (arg0))
>>>>>      return 1;
>>>>>  -  if (optimize_function_for_size_p (cfun))
>>>>> -    return 0;
>>>>> -
>>>>>    if (reorder && flag_evaluation_order
>>>>>        && (TREE_SIDE_EFFECTS (arg0) || TREE_SIDE_EFFECTS (arg1)))
>>>>>      return 0;
>>>>>
>>>>>
>>
>
diff mbox

Patch

diff --git a/gcc/ChangeLog.aarch64 b/gcc/ChangeLog.aarch64
index 3c8ff13..f4e1e91 100644
--- a/gcc/ChangeLog.aarch64
+++ b/gcc/ChangeLog.aarch64
@@ -1,3 +1,12 @@ 
+2013-08-11  Andrew Pinski  <apinski@cavium.com>
+
+	Bug #7079
+	* config/aarch64/aarch64.md (*movsi_aarch64): Use Ust instead of S constrain.
+	(*movdi_aarch64): Likewise.
+	(ldr_got_small_sidi): Add type attribute.
+	* config/aarch64/constraints.md (Ust): New constraint like S but only
+	if the symbol is SYMBOL_TINY_ABSOLUTE.
+
 2013-08-14  Yufeng Zhang  <yufeng.zhang@arm.com>
 
 	* function.c (assign_parm_find_data_types): Set passed_mode and
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 485bd59..0cd6a41 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -810,7 +810,7 @@ 
 
 (define_insn "*movsi_aarch64"
   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,k,r,r,r,*w,m,  m,r,r  ,*w, r,*w")
-	(match_operand:SI 1 "aarch64_mov_operand"  " r,r,k,M,m, m,rZ,*w,S,Ush,rZ,*w,*w"))]
+	(match_operand:SI 1 "aarch64_mov_operand"  " r,r,k,M,m, m,rZ,*w,Ust,Ush,rZ,*w,*w"))]
   "(register_operand (operands[0], SImode)
     || aarch64_reg_or_zero (operands[1], SImode))"
   "@
@@ -836,7 +836,7 @@ 
 
 (define_insn "*movdi_aarch64"
   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,k,r,r,r,*w,m,  m,r,r,  *w, r,*w,w")
-	(match_operand:DI 1 "aarch64_mov_operand"  " r,r,k,N,m, m,rZ,*w,S,Ush,rZ,*w,*w,Dd"))]
+	(match_operand:DI 1 "aarch64_mov_operand"  " r,r,k,N,m, m,rZ,*w,Ust,Ush,rZ,*w,*w,Dd"))]
   "(register_operand (operands[0], DImode)
     || aarch64_reg_or_zero (operands[1], DImode))"
   "@
@@ -3978,6 +3978,7 @@ 
   "TARGET_ILP32"
   "ldr\\t%w0, [%1, #:got_lo12:%a2]"
   [(set_attr "v8type" "load1")
+   (set_attr "type" "load1")
    (set_attr "mode" "DI")]
 )
 
diff --git a/gcc/config/aarch64/constraints.md b/gcc/config/aarch64/constraints.md
index 2570400..a36bdaf 100644
--- a/gcc/config/aarch64/constraints.md
+++ b/gcc/config/aarch64/constraints.md
@@ -114,6 +114,12 @@ 
   (and (match_code "const_int")
        (match_test "(unsigned) exact_log2 (ival) <= 4")))
 
+(define_constraint "Ust"
+  "A constraint that matches an absolute symbolic address; only for tiny model."
+  (and (match_code "const,symbol_ref,label_ref")
+       (match_test "aarch64_symbolic_address_p (op)
+		    && aarch64_classify_symbolic_expression (op, SYMBOL_CONTEXT_ADR) == SYMBOL_TINY_ABSOLUTE")))
+
 (define_memory_constraint "Q"
  "A memory address which uses a single base register with no offset."
  (and (match_code "mem")