Bug 50925 - [4.8 Regression][avr] ICE at spill_failure, at reload1.c:2118
Summary: [4.8 Regression][avr] ICE at spill_failure, at reload1.c:2118
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 4.7.0
: P4 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 52575 (view as bug list)
Depends on:
Blocks: 56183
  Show dependency treegraph
 
Reported: 2011-10-30 19:09 UTC by Joel Sherrill
Modified: 2015-06-23 08:30 UTC (History)
10 users (show)

See Also:
Host:
Target: avr-*
Build:
Known to work: 4.9.0
Known to fail: 4.5.2, 4.6.2, 4.7.0
Last reconfirmed: 2012-08-02 00:00:00


Attachments
Preprocessed output (14.06 KB, text/x-csrc)
2011-10-30 19:43 UTC, Joel Sherrill
Details
size-compared.txt (887 bytes, text/plain)
2011-11-04 17:12 UTC, Georg-Johann Lay
Details
Simplified testcase (814 bytes, text/x-csrc)
2011-12-06 18:42 UTC, denisc
Details
main-loop.c (maybe related from PR52025) (127 bytes, text/plain)
2012-01-27 23:20 UTC, Georg-Johann Lay
Details
spill.c - another reduced test (239 bytes, text/plain)
2012-02-27 20:42 UTC, Georg-Johann Lay
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joel Sherrill 2011-10-30 19:09:23 UTC
/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.
Comment 1 Joel Sherrill 2011-10-30 19:42:50 UTC
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
Comment 2 Joel Sherrill 2011-10-30 19:43:24 UTC
Created attachment 25667 [details]
Preprocessed output

Preprocessed code.
Comment 3 Georg-Johann Lay 2011-11-04 17:08:30 UTC
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.
Comment 4 Georg-Johann Lay 2011-11-04 17:12:21 UTC
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.
Comment 5 Georg-Johann Lay 2011-11-04 22:27:58 UTC
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
Comment 6 Joel Sherrill 2011-11-14 01:26:40 UTC
(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.
Comment 7 Joel Sherrill 2011-11-14 01:28:46 UTC
Adding Jeff Law (to the right PR) in the hopes that he can determine who is the right person to investigate this.
Comment 8 Jeffrey A. Law 2011-11-14 17:09:04 UTC
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.
Comment 9 denisc 2011-12-05 18:31:53 UTC
(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()
Comment 10 Jeffrey A. Law 2011-12-05 18:53:34 UTC
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
Comment 11 denisc 2011-12-05 19:08:41 UTC
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.
Comment 13 denisc 2011-12-06 18:42:23 UTC
Created attachment 26008 [details]
Simplified testcase
Comment 14 denisc 2012-01-12 18:30:00 UTC
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
Comment 15 denisc 2012-01-14 18:11:33 UTC
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
Comment 16 Georg-Johann Lay 2012-01-27 23:20:03 UTC
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.
Comment 17 Georg-Johann Lay 2012-01-27 23:26:37 UTC
Assuming there is a connexion between these two issues.

If that assumption turns out to be wrong, please cut the dependency.
Comment 18 denisc 2012-01-28 10:05:50 UTC
(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.
Comment 19 Georg-Johann Lay 2012-02-27 20:42:39 UTC
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
Comment 20 Georg-Johann Lay 2012-02-27 21:04:29 UTC
Adjusted "known to fail" as with the new test case.
Comment 21 Georg-Johann Lay 2012-03-13 09:44:04 UTC
*** Bug 52575 has been marked as a duplicate of this bug. ***
Comment 22 Richard Biener 2012-03-22 08:26:54 UTC
GCC 4.7.0 is being released, adjusting target milestone.
Comment 23 Richard Biener 2012-06-14 08:31:44 UTC
GCC 4.7.1 is being released, adjusting target milestone.
Comment 24 Georg-Johann Lay 2012-08-02 17:24:25 UTC
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...
Comment 25 Georg-Johann Lay 2012-08-02 17:34:40 UTC
(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.
Comment 26 Jakub Jelinek 2012-09-20 10:19:12 UTC
GCC 4.7.2 has been released.
Comment 27 Jakub Jelinek 2013-04-12 15:16:12 UTC
GCC 4.6.4 has been released and the branch has been closed.
Comment 28 Jorn Wolfgang Rennecke 2014-02-19 14:11:53 UTC
I can't reproduce this with the current trunk.  Can was mark this
as "known to work" for 4.9 ?
Comment 29 Ralf Corsepius 2014-02-19 17:07:18 UTC
(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.
Comment 30 Richard Biener 2014-06-12 13:43:09 UTC
The 4.7 branch is being closed, moving target milestone to 4.8.4.
Comment 31 Jakub Jelinek 2014-12-19 13:26:28 UTC
GCC 4.8.4 has been released.
Comment 32 Richard Biener 2015-06-23 08:30:27 UTC
Fixed for 4.9.0.