https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65657

--- Comment #5 from Senthil Kumar Selvaraj <senthil_kumar.selvaraj at atmel dot 
com> ---
This tentative patch (pending regression tests) makes the problem go away
diff --git gcc/config/avr/avr.c gcc/config/avr/avr.c
index 68d5ddc..46ff7e1 100644
--- gcc/config/avr/avr.c
+++ gcc/config/avr/avr.c
@@ -9959,7 +9959,11 @@ avr_rtx_costs_1 (rtx x, int codearg, int outer_code
ATTRIBUTE_UNUSED,
       return true;

     case MEM:
-      *total = COSTS_N_INSNS (GET_MODE_SIZE (mode));
+      /* MEM rtx with non-default address space is more
+         expensive. Not expressing that results in reg
+         clobber during expand (PR 65657). */
+      *total = COSTS_N_INSNS (GET_MODE_SIZE (mode)
+               + (MEM_ADDR_SPACE(x) == ADDR_SPACE_RAM ? 0 : 5));

       return true;

     case NEG:

Function call arguments are expanded right to left, which means that when
expanding the call to foo, R22:R23 is set to 0xABCD first up, and then the
expansion of *x clobbers R22 when mov<mode> calls gen_xload<mode>_A. Call
expansion does not appear to take the clobber (reg:MOVMODE 22) into account -
when it checks for argument overlap, the RTL (args[i].value) is only a MEM in
QImode - the clobber shows up when it eventually calls emit_move_insn.

This does not happen if x is a int pointer (rather than char) - turns out that
precompute_register_parameters does a copy_to_mode_reg if the cost of
args[i].value is more than COSTS_N_INSNS(1) i.e., it creates a pseudo and later
assigns the pseudo to the arg register.

Doing the same thing - providing a better cost estimate for a MEM rtx in the
non-default address space, makes this problem go away.

Reply via email to