From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120031 invoked by alias); 11 Dec 2019 17:55:39 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 120014 invoked by uid 89); 11 Dec 2019 17:55:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=forbids X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Dec 2019 17:55:37 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D20A731B; Wed, 11 Dec 2019 09:55:35 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5EA0F3F6CF; Wed, 11 Dec 2019 09:55:35 -0800 (PST) From: Richard Sandiford To: Georg-Johann Lay Mail-Followup-To: Georg-Johann Lay ,gcc@gcc.gnu.org, richard.sandiford@arm.com Cc: gcc@gcc.gnu.org Subject: Re: Code bloat due to silly IRA cost model? References: <47b10439-21b8-81f6-3838-a2bcd0fa8048@gjlay.de> <5DEFFCD4.4080903@gcc.gnu.org> Date: Wed, 11 Dec 2019 17:55:00 -0000 In-Reply-To: <5DEFFCD4.4080903@gcc.gnu.org> (Georg-Johann Lay's message of "Tue, 10 Dec 2019 21:15:16 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2019-12/txt/msg00178.txt.bz2 Georg-Johann Lay writes: > Hi, doesn't actually anybody know know to make memory more expensive > than registers when it comes to allocating registers? > > Whatever I am trying for TARGET_MEMORY_MOVE_COST and > TARGET_REGISTER_MOVE_COST, ira-costs.c always makes registers more > expensive than mem and therefore allocates values to stack slots instead > of keeping them in registers. > > Test case (for avr) is as simple as it gets: > > float func (float); > > float call (float f) > { > return func (f); > } > > What am I missing? > > Johann > > > Georg-Johann Lay schrieb: >> Hi, >> >> I am trying to track down a code bloat issue and am stuck because I do >> not understand IRA's cost model. >> >> The test case is as simple as it gets: >> >> float func (float); >> >> float call (float f) >> { >> return func (f); >> } >> >> IRA dump shows the following insns: >> >> >> (insn 14 4 2 2 (set (reg:SF 44) >> (reg:SF 22 r22 [ f ])) "bloat.c":4:1 85 {*movsf} >> (expr_list:REG_DEAD (reg:SF 22 r22 [ f ]) >> (nil))) >> (insn 2 14 3 2 (set (reg/v:SF 43 [ f ]) >> (reg:SF 44)) "bloat.c":4:1 85 {*movsf} >> (expr_list:REG_DEAD (reg:SF 44) >> (nil))) >> (note 3 2 6 2 NOTE_INSN_FUNCTION_BEG) >> (insn 6 3 7 2 (set (reg:SF 22 r22) >> (reg/v:SF 43 [ f ])) "bloat.c":5:12 85 {*movsf} >> (expr_list:REG_DEAD (reg/v:SF 43 [ f ]) >> (nil))) >> (call_insn/j 7 6 8 2 (parallel [ >> >> #14 sets pseudo 44 from arg register R22. >> #2 moves it to pseudo 43 >> #6 moves it to R22 as it prepares for call_insn #7. >> >> There are 2 allocnos and cost: >> >> Pass 0 for finding pseudo/allocno costs >> >> a1 (r44,l0) best NO_REGS, allocno NO_REGS >> a0 (r43,l0) best NO_REGS, allocno NO_REGS >> >> a0(r43,l0) costs: ADDW_REGS:32000 SIMPLE_LD_REGS:32000 LD_REGS:32000 >> NO_LD_REGS:32000 GENERAL_REGS:32000 MEM:9000 >> a1(r44,l0) costs: ADDW_REGS:32000 SIMPLE_LD_REGS:32000 LD_REGS:32000 >> NO_LD_REGS:32000 GENERAL_REGS:32000 MEM:9000 >> >> which is quite odd because MEM is way more expensive here than any REG. >> >> Okay, so let's boost the MEM cost (TARGET_MEMORY_MOVE_COST) by a factor >> of 100: >> >> a1 (r44,l0) best NO_REGS, allocno NO_REGS >> a0 (r43,l0) best NO_REGS, allocno NO_REGS >> >> a0(r43,l0) costs: ADDW_REGS:3200000 SIMPLE_LD_REGS:3200000 >> LD_REGS:3200000 NO_LD_REGS:3200000 GENERAL_REGS:3200000 MEM:801000 >> a1(r44,l0) costs: ADDW_REGS:3200000 SIMPLE_LD_REGS:3200000 >> LD_REGS:3200000 NO_LD_REGS:3200000 GENERAL_REGS:3200000 MEM:801000 >> >> What??? The REG costs are 100 times higher, and stille higher that the >> MEM costs. What the heck is going on? >> >> Setting TARGET_REGISTER_MOVE_COST and also TARGET_MEMORY_MOVE_COST to 0 >> yiels: >> >> a0(r43,l0) costs: ADDW_REGS:0 SIMPLE_LD_REGS:0 LD_REGS:0 NO_LD_REGS:0 >> GENERAL_REGS:0 MEM:0 >> a1(r44,l0) costs: ADDW_REGS:0 SIMPLE_LD_REGS:0 LD_REGS:0 NO_LD_REGS:0 >> GENERAL_REGS:0 MEM:0 >> >> as expected, i.e. there is no other hidden source of costs considered by >> IRA. And even TARGET_REGISTER_MOVE_COST = 0 and >> TARGET_MEMORY_MOVE_COST = original gives: >> >> a0(r43,l0) costs: ADDW_REGS:32000 SIMPLE_LD_REGS:32000 LD_REGS:32000 >> NO_LD_REGS:32000 GENERAL_REGS:32000 MEM:9000 >> a1(r44,l0) costs: ADDW_REGS:32000 SIMPLE_LD_REGS:32000 LD_REGS:32000 >> NO_LD_REGS:32000 GENERAL_REGS:32000 MEM:9000 >> >> How the heck do I tell ira-costs that registers are way cheaper than MEM? I think this is coming from: /* FIXME: Ideally, the following test is not needed. However, it turned out that it can reduce the number of spill fails. AVR and it's poor endowment with address registers is extreme stress test for reload. */ if (GET_MODE_SIZE (mode) >= 4 && regno >= REG_X) return false; in avr_hard_regno_mode_ok. This forbids SFmode in r26+ and means that moves between pointer registers and general registers have the highest possible cost (65535) to prevent them for being used for SFmode. So: ira_register_move_cost[SFmode][POINTER_REGS][GENERAL_REGS] = 65535; The costs for union classes are the maximum (worst-case) cost of for each subclass, so this means that: ira_register_move_cost[SFmode][GENERAL_REGS][GENERAL_REGS] = 65535; as well. Removing the code above fixes it. If you don't want to do that, an alternative might be to add a class for r0-r25 (but I've not tested that). Thanks, Richard >> >> Johann >> >> >> p.s. >> >> test case compiled with >> >> $ avr-gcc bloat.c -S -Os -dp -da -fsplit-wide-types-early -v >> >> Target: avr >> Configured with: ../../gcc.gnu.org/trunk/configure --target=avr >> --prefix=/local/gnu/install/gcc-10 --disable-shared --disable-nls >> --with-dwarf2 --enable-target-optspace=yes --with-gnu-as --with-gnu-ld >> --enable-checking=release --enable-languages=c,c++ --disable-gcov >> Thread model: single >> Supported LTO compression algorithms: zlib >> gcc version 10.0.0 20191021 (experimental) (GCC)