https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116780
--- Comment #4 from denisc at gcc dot gnu.org ---
After IRA we have:
---------------------------------------
;; bb 2 artificial_defs: { }
;; bb 2 artificial_uses: { u-1(28){ }u-1(32){ }u-1(34){ }}
;; lr in 28 [r28] 29 [r29] 32 [__SP_L__] 34 [argL]
;; lr use 28 [r28] 29 [r29] 32 [__SP_L__] 34 [argL]
;; lr def
(note 3 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 3 5 2 NOTE_INSN_FUNCTION_BEG)
(insn 5 2 0 2 (set (mem/v:QI (plus:HI (reg/f:HI 28 r28)
(const_int 1 [0x1])) [0 c[0]+0 S1 A8])
(const_int 0 [0])) "a.c":5:8 86 {movqi_insn_split}
(expr_list:REG_DEAD (reg:QI 29 r29)
(nil)))
;; succ: EXIT [always] count:1073741824 (estimated locally, freq
1.0000) (FALLTHRU) a.c:6:1
;; lr out 28 [r28] 32 [__SP_L__] 34 [argL]
---------------------------------------
We have only one executable insn in test function `a' after IRA:
(insn 5 2 0 2 (set (mem/v:QI (plus:HI (reg/f:HI 28 r28)
(const_int 1 [0x1])) [0 c[0]+0 S1 A8])
(const_int 0 [0])) "a.c":5:8 86 {movqi_insn_split}
(expr_list:REG_DEAD (reg:QI 29 r29)
(nil)))
(reg:HI 28) is a frame pointer register Y or R28,r29
LRA tries to eliminate frame pointer to stack pointer and uses
TARGET_FRAME_POINTER_REQUIRED hook.
The hook:
static bool
avr_frame_pointer_required_p (void)
{
return (cfun->calls_alloca
|| cfun->calls_setjmp
|| cfun->has_nonlocal_label
|| crtl->args.info.has_stack_args
|| get_frame_size () > 0);
}
The hook return `true' because frame size is 0.
After LRA we have:
---------------------------------------
;; bb 2 artificial_defs: { }
;; bb 2 artificial_uses: { u-1(32){ }}
;; lr in 32 [__SP_L__] 33 [__SP_H__]
;; lr use 32 [__SP_L__] 33 [__SP_H__]
;; lr def
(note 3 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 3 5 2 NOTE_INSN_FUNCTION_BEG)
(insn 5 2 8 2 (set (mem/v:QI (plus:HI (reg/f:HI 32 __SP_L__)
(const_int 1 [0x1])) [0 c[0]+0 S1 A8])
(const_int 0 [0])) "a.c":5:8 86 {movqi_insn_split}
(nil))
;; succ: EXIT [always] count:1073741824 (estimated locally, freq
1.0000) (FALLTHRU) a.c:6:1
;; lr out 32 [__SP_L__]
---------------------------------------
insn 5 has a wrong address. AVR can't use (reg/f:HI 32 __SP_L__) as an address
register.
Probably we have two bugs:
1. AVR port assumes that LRA (or reload) can eliminate frame pointer to stack
pointer (if no args and frame size = 0). It's wrong for this testcase;
2. LRA made a wrong elimination (may be because of AVR port have a wrong insn
definition or something else)