/home2/joel/build/b-avr-gcc/./gcc/xgcc -B/home2/joel/build/b-avr-gcc/./gcc/ -nostdinc -B/home2/joel/build/b-avr-gcc/avr-rtems4.11/avr25/newlib/ -isystem /home2/joel/build/b-avr-gcc/avr-rtems4.11/avr25/newlib/targ-include -isystem /users/joel/test-gcc/gcc-svn/newlib/libc/include -B/users/joel/test-gcc/install-svn/avr-rtems4.11/bin/ -B/users/joel/test-gcc/install-svn/avr-rtems4.11/lib/ -isystem /users/joel/test-gcc/install-svn/avr-rtems4.11/include -isystem /users/joel/test-gcc/install-svn/avr-rtems4.11/sys-include -mmcu=avr25 -DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" -DPACKAGE_VERSION=\"1.19.0\" -DPACKAGE_STRING=\"newlib\ 1.19.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I. -I/users/joel/test-gcc/gcc-svn/newlib/libc/search -Os -DPREFER_SIZE_OVER_SPEED -mcall-prologues -D_COMPILING_NEWLIB -DMALLOC_PROVIDED -DEXIT_PROVIDED -DSIGNAL_PROVIDED -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_NANOSLEEP -DHAVE_BLKSIZE -DHAVE_FCNTL -DHAVE_ASSERT_FUNC -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT -D_NO_GETPASS -D_NO_SIGSET -D_NO_WORDEXP -D_NO_POPEN -Wall -fno-builtin -g -O2 -mmcu=avr25 -c -o lib_a-twalk.o `test -f 'twalk.c' || echo '/users/joel/test-gcc/gcc-svn/newlib/libc/search/'`twalk.c /users/joel/test-gcc/gcc-svn/newlib/libc/search/hash.c: In function '__expand_table': /users/joel/test-gcc/gcc-svn/newlib/libc/search/hash.c:898:1: error: unable to find a register to spill in class 'POINTER_REGS' /users/joel/test-gcc/gcc-svn/newlib/libc/search/hash.c:898:1: error: this is the insn: (insn 172 96 173 10 (set (reg:QI 18 r18) (mem/c:QI (plus:HI (reg/f:HI 28 r28) (const_int 5 [0x5])) [16 S1 A8])) /users/joel/test-gcc/gcc-svn/newlib/libc/search/hash.c:886 1 {movqi_insn} (nil)) /users/joel/test-gcc/gcc-svn/newlib/libc/search/hash.c:898:1: internal compiler error: in spill_failure, at reload1.c:2118 Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions.
gcc (GCC) 4.7.0 20111029 (experimental) Newlib up to date at same time Cut and pasted from log with multiple jobs in parallel. The actual command line for hash.c was. /home2/joel/build/b-avr-gcc/./gcc/xgcc -B/home2/joel/build/b-avr-gcc/./gcc/ -nostdinc -B/home2/joel/build/b-avr-gcc/avr-rtems4.11/avr25/newlib/ -isystem /home2/joel/build/b-avr-gcc/avr-rtems4.11/avr25/newlib/targ-include -isystem /users/joel/test-gcc/gcc-svn/newlib/libc/include -B/users/joel/test-gcc/install-svn/avr-rtems4.11/bin/ -B/users/joel/test-gcc/install-svn/avr-rtems4.11/lib/ -isystem /users/joel/test-gcc/install-svn/avr-rtems4.11/include -isystem /users/joel/test-gcc/install-svn/avr-rtems4.11/sys-include -mmcu=avr25 -DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" -DPACKAGE_VERSION=\"1.19.0\" -DPACKAGE_STRING=\"newlib\ 1.19.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I. -I/users/joel/test-gcc/gcc-svn/newlib/libc/search -Os -DPREFER_SIZE_OVER_SPEED -mcall-prologues -D_COMPILING_NEWLIB -DMALLOC_PROVIDED -DEXIT_PROVIDED -DSIGNAL_PROVIDED -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_NANOSLEEP -DHAVE_BLKSIZE -DHAVE_FCNTL -DHAVE_ASSERT_FUNC -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT -D_NO_GETPASS -D_NO_SIGSET -D_NO_WORDEXP -D_NO_POPEN -Wall -fno-builtin -g -O2 -c -o lib_a-hash.o `test -f 'hash.c' || echo '/users/joel/test-gcc/gcc-svn/newlib/libc/search/'`hash.c This shouldn't matter much except to have hash.c instead of twalk.c
Created attachment 25667 [details] Preprocessed output Preprocessed code.
I can confirm this on current trunk r180962 with -Os/-O2/-O3. The bug disappears with -fno-caller-saves. I already observed trouble with -fcaller-saves together with -mstrict-X so that perhaps it is a good idea to disable that option for AVR? A size comparison if avr-libc generated with -f[no-]caller-saves looks as follows: Columns: 3nd = #bytes with -fcaller-saves 3rd = #bytes with -fno-caller-saves 4th = relative size gain 5th = absolute size gain vfscanf_flt.o : 21197 21347 0.7% 150 realloc.o : 4110 4164 1.3% 54 vfprintf_std.o : 8858 8840 -0.2% -18 vfprintf_flt.o : 16604 16508 -0.6% -96 calloc.o : 636 540 -15.1% -96 strdup.o : 654 516 -21.1% -138 vfscanf_min.o : 9613 9433 -1.9% -180 vfscanf_std.o : 12918 12736 -1.4% -182 :::::: Total ::::::: : 322839 322333 -0.2% -506 Other object do not change in size. Denis, what do you think: Should we kick off caller-saves alltogether? Appears that option increases register pressure/spill requests up to a level not appropriate for AVR.
Created attachment 25720 [details] size-compared.txt This is a size comparison where objects of same name are not mangled. ...and let me add that the error also occurs for avr-unknown-none.
Asserting that the bug is not a flaw in avr backend, I set the component to "other". The bug is somewhere in the caller-saves/IRA/reload triangle like PR50775: http://gcc.gnu.org/ml/gcc/2011-10/msg00537.html
(In reply to comment #5) > Asserting that the bug is not a flaw in avr backend, I set the component to > "other". The bug is somewhere in the caller-saves/IRA/reload triangle like > PR50775: http://gcc.gnu.org/ml/gcc/2011-10/msg00537.html We need to get someone more general to look at this and get the right person investigating.
Adding Jeff Law (to the right PR) in the hopes that he can determine who is the right person to investigate this.
I'm not going to be able to look at it anytime soon, but just some general thoughts: 1. Disabling caller-saves probably isn't appropriate. Just looking at codesize isn't the way to evaluate caller-saves either as caller-saves is tasked with improving performance, possibly at the expense of codesize. 2. The first thing someone needs to do is provide information as to why that insn needs reloads. I don't know enough about the AVR to hazard as guess why that insn needs reloads. 3. Find out where insn 172 comes from. There are restrictions on the insns created by caller-save. So if caller-save creates a bogus insn, then that needs to be investigated. Anyway, that's where I'd start. I can't say enough that disabling caller-saves merely to work around this problem is wrong wrong wrong.
(In reply to comment #8) > I'm not going to be able to look at it anytime soon, but just some general > thoughts: I think that I'm ready to explain the bug. > 1. Disabling caller-saves probably isn't appropriate. Just looking at > codesize isn't the way to evaluate caller-saves either as caller-saves is > tasked with improving performance, possibly at the expense of codesize. I'm agree. I don't want to disable caller-saves. > > 2. The first thing someone needs to do is provide information as to why that > insn needs reloads. I don't know enough about the AVR to hazard as guess why > that insn needs reloads. > > 3. Find out where insn 172 comes from. There are restrictions on the insns > created by caller-save. So if caller-save creates a bogus insn, then that > needs to be investigated. Generally, caller-save generate right insn. 1. AVR port have a specific dependency between frame_pointer_neede and gat_frame_size()
Other ports seem to work OK when the requirement for a frame pointer is conditional on the size of the stack. It's not the most common case, but it does come up in several ports. I still haven't seen a good description of why the particular insn needs reloads. Not everyone is familiar with the guts of the avr port. I'd then be looking at init_caller_save to determine why it thinks a particular address is OK for a caller-save, when in fact it isn't OK. jeff
Sorry, wrong button was pressed. (In reply to comment #8) > I'm not going to be able to look at it anytime soon, but just some general > thoughts: I think that I'm ready to explain the bug. > 1. Disabling caller-saves probably isn't appropriate. Just looking at > codesize isn't the way to evaluate caller-saves either as caller-saves is > tasked with improving performance, possibly at the expense of codesize. I'm agree. I don't want to disable caller-saves. > > 2. The first thing someone needs to do is provide information as to why that > insn needs reloads. I don't know enough about the AVR to hazard as guess why > that insn needs reloads. > > 3. Find out where insn 172 comes from. There are restrictions on the insns > created by caller-save. So if caller-save creates a bogus insn, then that > needs to be investigated. Generally, caller-save generate right insn. 1. AVR port have a specific dependency between frame_pointer_needed and get_frame_size(). avr_frame_pointer_required_p (void) { return (cfun->calls_alloca || cfun->calls_setjmp || cfun->has_nonlocal_label || crtl->args.info.nregs == 0 || get_frame_size () > 0); } 2. reload calls the `setup_save_areas ()' and after that get_frame_size () equal to 2, but frame_pointer_needed is 0. It's wrong for AVR port (If dependency between frame_pointer_needed and get_frame_size() is permitted by GCC core). 3. After that caller-save generate right save/restore insns for save to frame slot and restore from it. Like this (r28 is a frame pointer): (insn 162 77 163 10 (set (reg:QI 18 r18) (mem/c:QI (plus:HI (reg/f:HI 28 r28) (const_int 1 [0x1])) [8 S1 A8])) /mnt/d/avr-work/tst/nl.c:120 20 {movqi_insn} (nil)) 4. After that the following code was executed: /* If needed, eliminate any eliminable registers. */ if (num_eliminable || num_eliminable_invariants) did_elimination = eliminate_regs_in_insn (insn, 0); And right insns converted to wrong (__SP_L__ can not be used as a pointer): (insn 162 77 163 10 (set (reg:QI 18 r18) (mem/c:QI (plus:HI (reg/f:HI 32 __SP_L__) (const_int 1 [0x1])) [8 S1 A8])) /mnt/d/avr-work/tst/nl.c:120 20 {movqi_insn} (nil)) Here we have a wrong elimination FP->SP because frame_pointer_needed was not recalculated earlier. 5. relod have the following fragment: if (caller_save_needed) setup_save_areas (); /* If we allocated another stack slot, redo elimination bookkeeping. */ if (something_was_spilled || starting_frame_size != get_frame_size ()) continue; ------------------------------- But it's not resolve the problem. frame_pointer_needed isn't recalculated. Call to `update_eliminables ()' seems as a right solution.
This is a very old bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42204 http://gcc.gnu.org/ml/gcc/2006-03/msg00783.html
Created attachment 26008 [details] Simplified testcase
Author: denisc Date: Thu Jan 12 18:29:54 2012 New Revision: 183136 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183136 Log: PR target/50925 * config/avr/avr-protos.h (avr_hard_regno_nregs): Declare. * config/avr/avr.c (avr_can_eliminate): Simplify. (avr_initial_elimination_offset): Likewise. (avr_prologue_setup_frame): Use hard_frame_pointer_rtx. (expand_epilogue): Likewise. (avr_legitimize_address): Gut. (avr_legitimize_reload_address): Use hard_frame_pointer_rtx. (avr_hard_regno_nregs): New. (avr_hard_regno_ok): Allow only Pmode for arg and frame_pointers. (avr_regno_mode_code_ok_for_base_b): Handle arg and frame pointers. * config/avr/avr.h (FIXED_REGISTERS): Adjust arg pointer, add soft frame pointer. (CALL_USED_REGISTERS): Likewise. (REG_CLASS_CONTENTS): Likewise. (REGISTER_NAMES): Likewise. (HARD_REGNO_NREGS): Use avr_hard_regno_nregs. (HARD_FRAME_POINTER_REGNUM): New. (FRAME_POINTER_REGNUM): Use soft frame pointer. (ELIMINABLE_REGS): Eliminate from the soft frame pointer, remove the HARD_FRAME_POINTER self-elimination. Modified: trunk/gcc/ChangeLog trunk/gcc/config/avr/avr-protos.h trunk/gcc/config/avr/avr.c trunk/gcc/config/avr/avr.h
Author: denisc Date: Sat Jan 14 18:11:29 2012 New Revision: 183183 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183183 Log: PR target/50925 * config/avr/avr-protos.h: Revert change of 2012-01-09. * config/avr/avr.c: Likewise. * config/avr/avr.h: Likewise. Modified: trunk/gcc/ChangeLog trunk/gcc/config/avr/avr-protos.h trunk/gcc/config/avr/avr.c trunk/gcc/config/avr/avr.h
Created attachment 26486 [details] main-loop.c (maybe related from PR52025) This is a small test case from PR52025 generates strange code: It sets up a frame to store a local variable. Notice that there is just one local variable in the whole little program, so there is really no frame needed. This issue can be resolved by -fno-caller-saves, so maybe it's related to the spill fails from here that can also be hacked around with -fno-caller-saves. Maybe this little programs helps to find what's going wrong with the register allocation and spill fails.
Assuming there is a connexion between these two issues. If that assumption turns out to be wrong, please cut the dependency.
(In reply to comment #17) > Assuming there is a connexion between these two issues. > > If that assumption turns out to be wrong, please cut the dependency. Dependency cutted. 52025 isn't related to this bug.
Created attachment 26765 [details] spill.c - another reduced test Here is yet another different and simplified test case. With that test case I can produce spill fails for 4.5.2, 4.6.2 and 4.7 trunk (build from around 2012-02-17). >> avr-gcc spill.c -Os -S spill.c: In function 'menu_cycle': spill.c:31:1: error: unable to find a register to spill in class 'POINTER_REGS' spill.c:31:1: error: this is the insn: (insn 36 20 21 2 (set (reg:QI 18 r18) (mem/c:QI (plus:HI (reg/f:HI 28 r28) (const_int 1 [0x1])) [3 S1 A8])) spill.c:29 18 {movqi_insn} (nil)) spill.c:31:1: internal compiler error: in spill_failure, at reload1.c:2120
Adjusted "known to fail" as with the new test case.
*** Bug 52575 has been marked as a duplicate of this bug. ***
GCC 4.7.0 is being released, adjusting target milestone.
GCC 4.7.1 is being released, adjusting target milestone.
FYI, I just tried the TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P hook but without avail: Even with the most restrict setup (always return true) attachment 26765 [details] triggers the bug. The kook isn't even called once...
(In reply to comment #24) > The kook isn't even called once... My bad... The hook IS called, but it does not help with this bug.
GCC 4.7.2 has been released.
GCC 4.6.4 has been released and the branch has been closed.
I can't reproduce this with the current trunk. Can was mark this as "known to work" for 4.9 ?
(In reply to Jorn Wolfgang Rennecke from comment #28) > I can't reproduce this with the current trunk. Confirmed. gcc-4.9 doesn't show this bug for --target=avr-rtems4.11, anymore. > Can was mark this > as "known to work" for 4.9 ? I am inclined to agree.
The 4.7 branch is being closed, moving target milestone to 4.8.4.
GCC 4.8.4 has been released.
Fixed for 4.9.0.