From patchwork Fri Oct 18 19:48:41 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: 176950 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp1292890ocf; Fri, 18 Oct 2019 12:56:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXHpScy/Q7oQfcezm1Pf0RxhsYDbSZoqw2MTaaeqv7aQkd4/oEojuXo36mhhlOEmBxg7Ak X-Received: by 2002:a17:906:4a97:: with SMTP id x23mr10174902eju.218.1571428570251; Fri, 18 Oct 2019 12:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571428570; cv=none; d=google.com; s=arc-20160816; b=sqMIoLoC3nR1+yusXTduiTTwes/lmHHA8lWVyCqiHpB1kkRmpMdTXaMyoTCd1siN85 WDTgxZL5gGNrdV5VztxjXmvGjjVBfgJkiD/0gKg4EvwCCV+Q3XDNW9Ncc3DP+DeXU19/ 4XJUl27X5U2aqvZxub9HJYCPn4TsIZVaoWQ32YyfjPKHTLPsDCZl/pALGw/8CHF7oo57 zwTFOWlShaqRsyITfd0sDjXTZIo61SHdfS4io5dNWSlXGjeK71QKemdfi598Q9oEmaoe 6G89lqLDphFSGBod3mQlj5rnVCVJ5XiFXZ/KxQESo7XmVPDoC9tONU+GTxYJSvthgJDM 1B4A== 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=7QfccpviGV4QHEErlt00UTttOelmtu2JbU0wwpcDCjc=; b=zPCiyOJOhP01F8x9x3LyiKbOXqgAV/jFWFX3SLH6aA7nSqHz1bnJDDIQJw0klAHm1I HQJlJVLjBqE2c0LAqzwirfn6HvL+0x9yie6OneFiYg39PDoG8StA/23iZM3ueaI8spNh GQzzYYErl11FP6S2440D+AzztG6wsiFAxt1CkeqrR3zlySoF68HKX5myMaieYdMnv9WO x8bxKuRp5Cv8gEs4ytAb742Bi25Uz0TUUhtEc9Rdd6NSVEWatPEMHECUldmLVSDB5INZ ZbDUrxloYUS0XTHNPFRw/6mbeke3aXpizkwi5UzPccQaSZntNK3n6ZmwaQNJnHD8DSKz 5e6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=absEKTSm; spf=pass (google.com: domain of gcc-patches-return-511315-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-511315-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 g5si5062094edb.324.2019.10.18.12.56.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Oct 2019 12:56:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-511315-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=absEKTSm; spf=pass (google.com: domain of gcc-patches-return-511315-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-511315-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=nQ/yTyi4xXJn0axQ uTx58bLSST4GrhTr4y9e9Un+VdFTQ1E5xs5DhfyMeGgIztZR7XW+mh3Ie1xkOJJm pZmckwEplJM8U0ucfAqydrh3U3FVWMgoVl3Q7UV5pXZ2UcuOzbACoeoQnLrYc6Os 8WnBpVB+70jguTDUZq3OOPkhFvo= 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=WQA6J1T750MXg8+cT6GrvL sLXNA=; b=absEKTSmnJrY8QnQFb4q0h/hVbobOEZXuNSMeTmCly2YlD96tshWAU Y+kiKOpwdkoK6vi7wTHQzKMtM4FxLdYvjyVL+g4/mw3HCIflrEmDP9zC8tAb/Iqe dfhQhjQPChRdz2e5cil5CfDx9qvedG2kj19Sx4TGeCjU2pIkxHlhk= Received: (qmail 111649 invoked by alias); 18 Oct 2019 19:55:39 -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 110346 invoked by uid 89); 18 Oct 2019 19:55:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=expressing, HX-Languages-Length:2913, outer_code X-HELO: foss.arm.com Received: from Unknown (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Oct 2019 19:55:30 +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 4E82A1691; Fri, 18 Oct 2019 12:49:19 -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 CFF943F6C4; Fri, 18 Oct 2019 12:49:18 -0700 (PDT) From: Richard Earnshaw To: gcc-patches@gcc.gnu.org Cc: Richard Earnshaw Subject: [PATCH 10/29] [arm] Correct cost calculations involving borrow for subtracts. Date: Fri, 18 Oct 2019 20:48:41 +0100 Message-Id: <20191018194900.34795-11-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 The rtx_cost calculations when a borrow operation was being performed were not being calculated correctly. The borrow is free as part of the subtract-with-carry instructions. This patch recognizes the various idioms that can describe this and returns the correct costs. * config/arm/arm.c (arm_rtx_costs_internal, case MINUS): Handle borrow operations. --- gcc/config/arm/arm.c | 49 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index dfbd5cde5eb..b91b52f6d51 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -10049,15 +10049,46 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code, rtx shift_by_reg = NULL; rtx shift_op; rtx non_shift_op; + rtx op0 = XEXP (x, 0); + rtx op1 = XEXP (x, 1); - shift_op = shifter_op_p (XEXP (x, 0), &shift_by_reg); + /* Factor out any borrow operation. There's more than one way + of expressing this; try to recognize them all. */ + if (GET_CODE (op0) == MINUS) + { + if (arm_borrow_operation (op1, SImode)) + { + op1 = XEXP (op0, 1); + op0 = XEXP (op0, 0); + } + else if (arm_borrow_operation (XEXP (op0, 1), SImode)) + op0 = XEXP (op0, 0); + } + else if (GET_CODE (op1) == PLUS + && arm_borrow_operation (XEXP (op1, 0), SImode)) + op1 = XEXP (op1, 0); + else if (GET_CODE (op0) == NEG + && arm_borrow_operation (op1, SImode)) + { + /* Negate with carry-in. For Thumb2 this is done with + SBC R, X, X lsl #1 (ie X - 2X - C) as Thumb lacks the + RSC instruction that exists in Arm mode. */ + if (speed_p) + *cost += (TARGET_THUMB2 + ? extra_cost->alu.arith_shift + : extra_cost->alu.arith); + *cost += rtx_cost (XEXP (op0, 0), mode, MINUS, 0, speed_p); + return true; + } + + shift_op = shifter_op_p (op0, &shift_by_reg); if (shift_op == NULL) { - shift_op = shifter_op_p (XEXP (x, 1), &shift_by_reg); - non_shift_op = XEXP (x, 0); + shift_op = shifter_op_p (op1, &shift_by_reg); + non_shift_op = op0; } else - non_shift_op = XEXP (x, 1); + non_shift_op = op1; if (shift_op != NULL) { @@ -10087,10 +10118,10 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code, return true; } - if (CONST_INT_P (XEXP (x, 0))) + if (CONST_INT_P (op0)) { int insns = arm_gen_constant (MINUS, SImode, NULL_RTX, - INTVAL (XEXP (x, 0)), NULL_RTX, + INTVAL (op0), NULL_RTX, NULL_RTX, 1, 0); *cost = COSTS_N_INSNS (insns); if (speed_p) @@ -10101,7 +10132,11 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code, else if (speed_p) *cost += extra_cost->alu.arith; - return false; + /* Don't recurse as we don't want to cost any borrow that + we've stripped. */ + *cost += rtx_cost (op0, mode, MINUS, 0, speed_p); + *cost += rtx_cost (op1, mode, MINUS, 1, speed_p); + return true; } if (GET_MODE_CLASS (mode) == MODE_INT