From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15018 invoked by alias); 15 Apr 2015 08:48:44 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 14976 invoked by uid 48); 15 Apr 2015 08:48:40 -0000 From: "senthil_kumar.selvaraj at atmel dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/65657] [avr] read from __memx address space tramples argument to following function Date: Wed, 15 Apr 2015 08:48:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: senthil_kumar.selvaraj at atmel dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-04/txt/msg01182.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65657 --- Comment #5 from Senthil Kumar Selvaraj --- 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 calls gen_xload_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.