From patchwork Tue Oct 22 13:21:39 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: 177154 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp4856919ill; Tue, 22 Oct 2019 06:22:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWVy49rLvKKRLEUYfVbdKTpEfb1E0WXvh3RnFfBD306gXeJmWKNXtbf+uydTVJfYw9EeXw X-Received: by 2002:a17:906:6882:: with SMTP id n2mr27869311ejr.48.1571750522570; Tue, 22 Oct 2019 06:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571750522; cv=none; d=google.com; s=arc-20160816; b=O2Wmn4rKeV18zkpLU0oSL7LZ5uTIiinAHNc9OdNvQqykjmnejN4RtDmF4AY7uUpVGa l+2vlQ0EeZfecENQlG/ww2KkCTPZrfyKMHzaC6r4nmDlIMdkU9FrVDrV4+OggHa5/UqD DEojyzoWCMXHbeISNPHO6Pst6ykzc0uFEpVqWpHSrLac+TzUnez1A782qJNOyCRzoSIJ lK2Ajc5/lwd355QE6gRKeR6ZODV9koSuQfTyGLdoHJWRjRAUopx/YQnLOSZfRNiQlLsE Pq6SPhvV+53Qa9l/qKgXRa55aMSQZWycpoK/C/SafTM+Ph0+m6pfLt5XSG7+6q4jrLXH a7mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:date:message-id:subject:from:to :delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=pRylMzUqjXWz2lQucCw9xu9Ba8oWEnA+kSvWUgrefCc=; b=xu5YYTvrnRue65co0sYWXGQAJd0nE2ndA7lreFYFv6tMWJlFItyCnd80rjD1yA+cC0 +zXbC11FDRHcadBt8I84GX9wL4jUAy+dZOlXucK4+jj6+6s+x8HhNaCNns9n+4vykG6t QrwFXOkQQent8/kN58G9z9gg8SbNMlOdZND0s7pVpzZNU09DAMi4UoY/sLkt6xpiSTB2 TetxbWFz88IYyB6qUCNPwEdSIXCaCkxx4xXePbzEPZKDBLuS5PYurf0MyynIo9Hw5XTC Kfp9rD+95TEo0IutlN4iZ2uVJ0xlPbJtj9hJZiPZu2Z+CjZafPziJ/dSMOdGgcjLBJ7V MpXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gi5136+r; spf=pass (google.com: domain of gcc-patches-return-511499-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-511499-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 z7si12444510edb.160.2019.10.22.06.22.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Oct 2019 06:22:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-511499-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=Gi5136+r; spf=pass (google.com: domain of gcc-patches-return-511499-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-511499-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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=NVKMLU/huvNHJAYBMoCMePo7rNPvUXSHy44VFCfY+Pk4vqkQw+ 5ZUznVarZnH2onB0fLAeOUqbmkMgxKO8hfuC3EmOz1K4ZuAmMHv1PMuYTjxj5Ta4 KQq4lZlyvS5zg/ZWP62RAm1uTwJo88qryykWyyH2lWo6SBxJHRa3HmDIQ= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=9zrbYveGfum6oLBKozw51IW6DJU=; b=Gi5136+rP63N2iSoX9Ly L3XDcVmbAp1cphd2tPsPaOxWEGWUeebkCN+zhsIJN4vUbToX/7+dw4gDKZmpR8hy MB30w5rfBfps1SCDurf9vwWfzF7MbWWJG7YtN5b79Xfv67NKxLpg6k1Sx+8UQRKg okcMNoIEuP8l2LMQ+Y6vnGs= Received: (qmail 109408 invoked by alias); 22 Oct 2019 13:21:50 -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 109399 invoked by uid 89); 22 Oct 2019 13:21:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.3 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=HX-Languages-Length:2331 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; Tue, 22 Oct 2019 13:21:48 +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 187011762; Tue, 22 Oct 2019 06:21:41 -0700 (PDT) Received: from e120077-lin.cambridge.arm.com (e120077-lin.cambridge.arm.com [10.2.206.225]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 89FA93F71F; Tue, 22 Oct 2019 06:21:40 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" From: "Richard Earnshaw (lists)" Subject: [arm] Match subtraction from carry_operation Message-ID: <2894905c-7b63-2d66-aceb-d37eadbd20f2@arm.com> Date: Tue, 22 Oct 2019 14:21:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 On Arm we have both carry and borrow operations, but borrow is essentially '~carry'. Of course, with boolean logic ~carry is also 1-carry. GCC transforms (1 - X - LTU (cc, 0)) into (GEU (cc, 0) - X) Now the former matches a real insn in Arm state, using the RSC instruction with #1 as the immediate, but we currently do not recognize the canonicalized form. Nevertheless, given the above logic, this turns out to be quite straight forward as the original expression matches arm_borrow_operation and the revised form can be used with arm_carry_operation. Since we match this new pattern we also update rtx_costs to handle it. * config/arm/arm.md (rsbsi_carryin_reg): New pattern. * config/arm/arm.c (arm_rtx_costs_internal, case MINUS): Handle subtraction from a carry operation. Committed to trunk. R. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 5491ad0fb43..5c2c48f4253 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -10107,6 +10107,13 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code, *cost += rtx_cost (XEXP (op0, 0), mode, MINUS, 0, speed_p); return true; } + /* (Carry_op - reg) can be done as RSC Rd, Rn, #1 on Arm. + Note we do mean ~borrow here. */ + else if (TARGET_ARM && arm_carry_operation (op0, SImode)) + { + *cost += rtx_cost (op1, mode, code, 1, speed_p); + return true; + } shift_op = shifter_op_p (op0, &shift_by_reg); if (shift_op == NULL) diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index 039fdd02479..ae77cc377f6 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -1649,6 +1649,19 @@ (define_insn "subsi3_carryin" (set_attr "type" "adc_reg,adc_imm,alu_shift_imm")] ) +;; Special canonicalization of the above when operand1 == (const_int 1): +;; in this case the 'borrow' needs to treated like subtracting from the carry. +(define_insn "rsbsi_carryin_reg" + [(set (match_operand:SI 0 "s_register_operand" "=r") + (minus:SI (match_operand:SI 1 "arm_carry_operation" "") + (match_operand:SI 2 "s_register_operand" "r")))] + "TARGET_ARM" + "rsc%?\\t%0, %2, #1" + [(set_attr "conds" "use") + (set_attr "predicable" "yes") + (set_attr "type" "adc_imm")] +) + (define_insn "cmpsi3_carryin_out" [(set (reg: CC_REGNUM) (compare: