From patchwork Fri Oct 18 19:48:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 176955 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp1293730ocf; Fri, 18 Oct 2019 12:57:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHFRZWOuBp1NKFLh/MVSgaUIdD6X6R26gBZQkMv5rWntOlJ7W8IE7ki06L0WLm8J+FtVXV X-Received: by 2002:aa7:de12:: with SMTP id h18mr11536932edv.226.1571428629986; Fri, 18 Oct 2019 12:57:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571428629; cv=none; d=google.com; s=arc-20160816; b=PyMq5ml7vqbEO3FwX9rnQbylz8dx+oRF6kTuG5AA80sAF52MDr1vYOCHqZ7qsQPozC YXeN3n4pvx6MyAExPYvKnwk7LJz/iyJVKeEqBv1C2NEe/rSTUpa6eU0/6IN0NAQ3vBh0 92LzvDMS+oDGblEk0s5PRGL65Cgq3ReGSyjxds2x+Ee8FQy0PXLUQ9Emr4uyYMosKHLy rdmsGlLzsZEv6WWtYsTs1+NpQyolyUoE2hDaY5P9CRugxYio1CZNrgK+zD6mp4HGfw5O SinTfqJc6wPnSj3s1qu9jU1RvTwr1auM9eTNWKXCD4k5FYpgc+TGb+MSsmJj/732Yk6m 2eHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=WX1znOJQ/uK/2OHnAXvoxbJ4qUefTRWQOmqke3z8gGM=; b=IDjrsyNX4r568aXc+DBq8qhls1o2UZL2P6O8pJCqaKOCXast3fPGPMEGfAbOL0GHkL JQyp7hVllUJtqjTBaIWMVv+Axcl/O7AK5HzeeGiDdrDzNvCvRwUTmbfQDW/KZyZG0+Q2 gZhF89IbP8cl8VPIND8UR1ZXe26Vln4ptsgnM8sFsYk1BGxpxWKochbEkpxFIowzf6h+ J9R4PEPIPl0Od8DLc+xj+8IVLgWCaLo1Q80xQGL6OCjFrQ0PWafCFr64V/7CZo6c1OSF A0vyAzbFZfuOzmAykyKRk8NNb1QP6P/o9Wbdn7c/OcJia8xPwo+a0GDbgQAmNlS4lZ7v 3zDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="mvzKsu/Y"; spf=pass (google.com: domain of gcc-patches-return-511321-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-511321-patch=linaro.org@gcc.gnu.org" Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id jx20si3957238ejb.291.2019.10.18.12.57.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Oct 2019 12:57:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-511321-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="mvzKsu/Y"; spf=pass (google.com: domain of gcc-patches-return-511321-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-511321-patch=linaro.org@gcc.gnu.org" DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; q=dns; s=default; b=aMNLsOlGsXdDV0La LlFWrraMnjrABN7otZGpVTF2cXfySKI3dTzZ0mtMiR8IMZRT2FTu1w+Nj8SL380/ lh/LUYdqKnwDuNU4j62Hobt35N3GpDZaoSeiS8Q9/q2SertgCmjLcLYG57tbVNIn 0jjpzehW1v20H3oYaxwPQI3R3ug= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=default; bh=OQLRzcMh/sM7YRMrj38x7p de7B0=; b=mvzKsu/YSQoqpqMeKHZ5IGVP45s8KV6i+qZ6J/KTKq+F+wOTz9D1DZ iLFH33cRJle2NbXmkFXuDc5kgqVj93IGS8ZfW5GYR/D4OCmnVQbz7RxwWcSHcw5j H8AtWnnMJYOH66XnT2lsnW/UjC7pv2QJD/9XXZHvCknnoi4Zq9gXo= Received: (qmail 113622 invoked by alias); 18 Oct 2019 19:55:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 110798 invoked by uid 89); 18 Oct 2019 19:55:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_FAIL autolearn=ham version=3.3.1 spammy=practically, REG_DEAD, reg_dead, disappear X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (209.51.188.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Oct 2019 19:55:34 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iLYLR-00054R-Ti for gcc-patches@gcc.gnu.org; Fri, 18 Oct 2019 15:55:31 -0400 Received: from [217.140.110.172] (port=42746 helo=foss.arm.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iLYLR-000549-LH for gcc-patches@gcc.gnu.org; Fri, 18 Oct 2019 15:55:29 -0400 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 026DD1692; Fri, 18 Oct 2019 12:49:20 -0700 (PDT) Received: from eagle.buzzard.freeserve.co.uk (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 83C123F6C4; Fri, 18 Oct 2019 12:49:19 -0700 (PDT) From: Richard Earnshaw To: gcc-patches@gcc.gnu.org Cc: Richard Earnshaw Subject: [PATCH 11/29] [arm] Reduce cost of insns that are simple reg-reg moves. Date: Fri, 18 Oct 2019 20:48:42 +0100 Message-Id: <20191018194900.34795-12-Richard.Earnshaw@arm.com> In-Reply-To: <20191018194900.34795-1-Richard.Earnshaw@arm.com> References: <20191018194900.34795-1-Richard.Earnshaw@arm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.140.110.172 Consider this sequence during combine: Trying 18, 7 -> 22: 18: r118:SI=r122:SI REG_DEAD r122:SI 7: r114:SI=0x1-r118:SI-ltu(cc:CC_RSB,0) REG_DEAD r118:SI REG_DEAD cc:CC_RSB 22: r1:SI=r114:SI REG_DEAD r114:SI Failed to match this instruction: (set (reg:SI 1 r1 [+4 ]) (minus:SI (geu:SI (reg:CC_RSB 100 cc) (const_int 0 [0])) (reg:SI 122))) Successfully matched this instruction: (set (reg:SI 114) (geu:SI (reg:CC_RSB 100 cc) (const_int 0 [0]))) Successfully matched this instruction: (set (reg:SI 1 r1 [+4 ]) (minus:SI (reg:SI 114) (reg:SI 122))) allowing combination of insns 18, 7 and 22 original costs 4 + 4 + 4 = 12 replacement costs 8 + 4 = 12 The costs are all correct, but we really don't want this combination to take place. The original costs contain an insn that is a simple move of one pseudo register to another and it is extremely likely that register allocation will eliminate this insn entirely. On the other hand, the resulting sequence really does expand into a sequence that costs 12 (ie 3 insns). We don't want to prevent combine from eliminating such moves, as this can expose more combine opportunities, but we shouldn't rate them as profitable in themselves. We can do this be adjusting the costs slightly so that the benefit of eliminating such a simple insn is reduced. We only do this before register allocation; after allocation we give such insns their full cost. * config/arm/arm.c (arm_insn_cost): New function. (TARGET_INSN_COST): Override default definition. --- gcc/config/arm/arm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index b91b52f6d51..e33b6b14d28 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -181,6 +181,7 @@ static bool arm_have_conditional_execution (void); static bool arm_cannot_force_const_mem (machine_mode, rtx); static bool arm_legitimate_constant_p (machine_mode, rtx); static bool arm_rtx_costs (rtx, machine_mode, int, int, int *, bool); +static int arm_insn_cost (rtx_insn *, bool); static int arm_address_cost (rtx, machine_mode, addr_space_t, bool); static int arm_register_move_cost (machine_mode, reg_class_t, reg_class_t); static int arm_memory_move_cost (machine_mode, reg_class_t, bool); @@ -510,6 +511,8 @@ static const struct attribute_spec arm_attribute_table[] = #define TARGET_RTX_COSTS arm_rtx_costs #undef TARGET_ADDRESS_COST #define TARGET_ADDRESS_COST arm_address_cost +#undef TARGET_INSN_COST +#define TARGET_INSN_COST arm_insn_cost #undef TARGET_SHIFT_TRUNCATION_MASK #define TARGET_SHIFT_TRUNCATION_MASK arm_shift_truncation_mask @@ -11486,6 +11489,24 @@ arm_rtx_costs (rtx x, machine_mode mode ATTRIBUTE_UNUSED, int outer_code, return result; } +static int +arm_insn_cost (rtx_insn *insn, bool speed) +{ + int cost; + + /* Don't cost a simple reg-reg move at a full insn cost: such moves + will likely disappear during register allocation. */ + if (!reload_completed + && GET_CODE (PATTERN (insn)) == SET + && REG_P (SET_DEST (PATTERN (insn))) + && REG_P (SET_SRC (PATTERN (insn)))) + return 2; + cost = pattern_cost (PATTERN (insn), speed); + /* If the cost is zero, then it's likely a complex insn. We don't want the + cost of these to be less than something we know about. */ + return cost ? cost : COSTS_N_INSNS (2); +} + /* All address computations that can be done are free, but rtx cost returns the same for practically all of them. So we weight the different types of address here in the order (most pref first):