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

Andrew Pinski pinskia@gmail.com
Thu Sep 18 18:21:00 GMT 2014


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;
>>
>>
>
-------------- next part --------------
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.
---

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


More information about the Gcc-patches mailing list