Bug 52148

Summary: [4.7 regression] ICE: in spill_failure, at reload1.c:2120
Product: gcc Reporter: Michal Hlavinka <mhlavink>
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED WORKSFORME    
Severity: normal CC: eric.weddington, gjl
Priority: P4 Keywords: FIXME, ice-on-valid-code
Version: 4.7.0   
Target Milestone: 4.7.0   
Host: Target: avr
Build: Known to work:
Known to fail: Last reconfirmed: 2012-02-17 00:00:00
Attachments: pre-processed reproducer

Description Michal Hlavinka 2012-02-07 10:55:07 UTC
Created attachment 26601 [details]
pre-processed reproducer

gcc 4.7 fails on code that was working in 4.6 without any problem

Version: 4.7.0-20120204
Target: avr

Problem happens only when optimization (O2 or O3) is used.

Pre-processed reproducer attached.

$ avr-gcc -mmcu=atmega64 -O2  allsrce.cpp -c -o allsrc.o

allsrce.cpp: In function 'void applyExpos(int16_t*, uint8_t)':
allsrce.cpp:68:1: error: unable to find a register to spill in class 'POINTER_REGS'
allsrce.cpp:68:1: error: this is the insn:
(insn 17 16 9 2 (parallel [
            (set (mem:BLK (reg:HI 26 r26) [0 A8])
                (mem:BLK (reg/v/f:HI 97 [ anas ]) [0 A8]))
            (unspec [
                    (const_int 0 [0])
                ] UNSPEC_MOVMEM)
            (use (reg:QI 24 r24 [99]))
            (clobber (reg:HI 26 r26))
            (clobber (reg:HI 30 r30))
            (clobber (reg:QI 0 r0))
            (clobber (reg:QI 24 r24 [99]))
        ]) allsrce.cpp:49 29 {movmem_qi}
     (expr_list:REG_DEAD (reg:QI 24 r24 [99])
        (expr_list:REG_DEAD (reg:QI 27 r27)
            (expr_list:REG_UNUSED (reg:QI 24 r24 [99])
                (expr_list:REG_UNUSED (reg:QI 0 r0)
                    (expr_list:REG_UNUSED (reg:HI 30 r30)
                        (expr_list:REG_UNUSED (reg:HI 26 r26)
                            (nil))))))))
allsrce.cpp:68:1: internal compiler error: in spill_failure, at reload1.c:2120
Please submit a full bug report,
with preprocessed source if appropriate.


Additional information:
$ avr-gcc -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/avr/4.7.0/lto-wrapper
Target: avr
Configured with: ../gcc-4.7-20120204/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-system-zlib --enable-version-specific-runtime-libs --with-pkgversion='Fedora 4.7-0.fc16.1' --with-bugurl=https://bugzilla.redhat.com/
Thread model: single
gcc version 4.7.0 20120204 (experimental) (Fedora 4.7-0.fc16.1)
Comment 1 Michal Hlavinka 2012-02-07 10:58:56 UTC
note: looks similar to 

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50925
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52025

but compared to both bugs above, adding -fno-caller-saves does not fix the problem
Comment 2 Georg-Johann Lay 2012-02-17 12:18:28 UTC
There is already FIXME comment in avr.c:avr_emit_movmemhi that register allocator is likely to ICE with spill fail. momvmemhi must use Z and X regsiters and there is no freedom for the allocator.
Comment 3 Georg-Johann Lay 2012-02-28 08:51:42 UTC
Author: gjl
Date: Tue Feb 28 08:51:39 2012
New Revision: 184615

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184615
Log:
	PR target/52148
	* config/avr/avr.md (movmem_<mode>): Replace match_operand that
	match only one single hard register with respective hard reg rtx.
	(movmemx_<mode>): Ditto.
	* config/avr/avr.c (avr_emit_movmemhi): Adapt expanding to new
	insn anatomy of movmem[x]_<mode>.
	(avr_out_movmem): Same for printing assembler and operand usage.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr.c
    trunk/gcc/config/avr/avr.md
Comment 4 Georg-Johann Lay 2012-02-28 09:03:48 UTC
Fixed as WORKSFORME:

With the patch, the test case can be compiled. However, it does not fix the root cause of spill fails, see PR50925 for details.
Comment 5 Georg-Johann Lay 2012-03-12 17:35:48 UTC
Author: gjl
Date: Mon Mar 12 17:35:43 2012
New Revision: 185253

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185253
Log:
	PR target/52148
	* config/avr/avr.c (avr_out_movmem): Fix typo in output template
	for the case ADDR_SPACE_FLASH and AVR_HAVE_LPMX introduced in
	r184615 from 2012-02-28.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr.c
Comment 6 Georg-Johann Lay 2012-03-22 15:07:33 UTC
Author: gjl
Date: Thu Mar 22 15:06:57 2012
New Revision: 185697

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185697
Log:
libgcc/
	Backport from 2012-03-07 mainline r185033.

	PR target/52507
	* config/avr/lib1funcs.S (__movmemx_hi): Fix loop label in RAM-part.

	Backport from 2012-03-07 mainline r185031.

	PR target/52505
	* config/avr/lib1funcs.S (__xload_1): Don't read unintentionally
	from RAM.

	Backport from 2012-03-07 mainline r185030.

	PR target/52461
	PR target/52508
	* config/avr/lib1funcs.S (__do_copy_data): Clear RAMPZ after usage
	if RAMPZ affects reading from RAM.
	(__tablejump_elpm__): Ditto.
	(.xload): Ditto.
	(__movmemx_hi): Ditto.
	(__do_global_ctors): Right condition for RAMPZ usage is "have ELPM".
	(__do_global_dtors): Ditto.
	(__xload_1, __xload_2, __xload_3, __xload_4): Ditto.
	(__movmemx_hi): Ditto.

gcc/
	Backport from 2012-03-22 mainline r185692.

	PR target/52496
	* config/avr/avr.md (unspec): Remove UNSPEC_MEMORY_BARRIER.
	(unspecv): Add UNSPECV_MEMORY_BARRIER.
	(cli_sei): Use unspec_volatile instead of unspec for memory barrier.
	(delay_cycles_1, delay_cycles_2): Ditto.
	(delay_cycles_3, delay_cycles_4): Ditto.
	(nopv, *nopv): Ditto.
	(sleep, *sleep): Ditto.
	(wdr, *wdr): Ditto.

	Backport from 2012-03-21 mainline r185605.

	PR rtl-optimization/52543
	PR target/52461
	* config/avr/avr-protos.h (avr_load_lpm): New prototype.
	* config/avr/avr.c (avr_mode_dependent_address_p): New function.
	(TARGET_MODE_DEPENDENT_ADDRESS_P): New define.
	(avr_load_libgcc_p): Restrict to __flash loads.
	(avr_out_lpm): Only handle 1-byte loads from __flash.
	(avr_load_lpm): New function.
	(avr_find_unused_d_reg): Remove.
	(avr_out_lpm_no_lpmx): Remove.
	(adjust_insn_length): Handle ADJUST_LEN_LOAD_LPM.
	* config/avr/avr.md (unspec): Add UNSPEC_LPM.
	(load_<mode>_libgcc): Use UNSPEC_LPM instead of MEM.
	(load_<mode>, load_<mode>_clobber): New insns.
	(mov<mode>): For multi-byte move from non-generic
	16-bit address spaces: Expand to load_<mode> resp.
	load_<mode>_clobber.
	(load<mode>_libgcc): Remove expander.
	(split-lpmx): Remove split.

	Backport from 2012-03-13 mainline r185329.

	PR target/52488
	* config/avr/avr.c (avr_prologue_setup_frame): Cut down stack
	offset (size) to a value the insns can deal with.
	(expand_epilogue): Ditto.

	Backport from 2012-03-12 mainline r185256.

	PR target/52499
	* config/avr/avr.c (avr_mode_code_base_reg_class): Change return
	type from reg_class_t to enum reg_class.
	* config/avr/avr-protos.h (avr_mode_code_base_reg_class): Ditto.

	Backport from 2012-03-12 mainline r185253.

	PR target/52148
	* config/avr/avr.c (avr_out_movmem): Fix typo in output template
	for the case ADDR_SPACE_FLASH and AVR_HAVE_LPMX introduced in
	r184615 from 2012-02-28.

	Backport from 2012-03-08 mainline r185105.

	* config/avr/avr.md (*addhi3, addhi3_clobber): Add "w" alternative
	for constants in [-63,63].

	Backport from 2012-03-08 mainline r185100.

	PR target/52496
	* config/avr/avr.c (avr_mem_clobber): New static function.
	(avr_expand_delay_cycles): Add memory clobber operand to
	delay_cycles_1, delay_cycles_2, delay_cycles_3, delay_cycles_4.
	* config/avr/avr.md (unspec): Add UNSPEC_MEMORY_BARRIER.
	(enable_interrupt, disable_interrupt): New expander.
	(nopv, sleep, wdr): New expanders.
	(delay_cycles_1): Add memory clobber.
	(delay_cycles_2): Add memory clobber.
	(delay_cycles_3): Add memory clobber.
	(delay_cycles_4): Add memory clobber.
	(cli_sei): New insn from former "enable_interrupt",
	"disable_interrupt" with memory clobber.
	(*wdt): New insn from former "wdt" with memory clobber.
	(*nopv): Similar, but for "nopv".
	(*sleep): Similar, but for "sleep".

	Backport from 2012-03-07 mainline r185043.

	PR target/52484
	* config/avr/avr.md (xload<mode>_A): Add R22... to register footprint.

	Backport from 2012-03-07 mainline r185032.

	PR target/52506
	* gcc/config/avr/avr.c (expand_epilogue): Fix order of restoration
	to: RAMPZ, RAMPY, RAMPX, RAMPD.
	(expand_prologue): Only clear RAMPZ if it has effect on RAM-read.

	Backport from 2012-03-07 mainline r185031.

	PR target/52505
	* config/avr/avr.c (avr_out_xload): Don't read unintentionally
	from RAM.
	* config/avr/avr.md (xload_8): Adjust insn length.

	Backport from 2012-03-07 mainline r185030.

	PR target/52461
	* gcc/config/avr/avr.c (avr_out_lpm): Clear RAMPZ after usage
	if RAMPZ affects reading from RAM.

	Backport from 2012-03-05 mainline r184919.

	* config/avr/avr.md (*umaddqihi4.2): New insn-and-split.


Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/avr/avr-protos.h
    branches/gcc-4_7-branch/gcc/config/avr/avr.c
    branches/gcc-4_7-branch/gcc/config/avr/avr.md
    branches/gcc-4_7-branch/libgcc/ChangeLog
    branches/gcc-4_7-branch/libgcc/config/avr/lib1funcs.S