From patchwork Wed May 23 06:47:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 136634 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp517936lji; Tue, 22 May 2018 23:48:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoVNUKVUeCXyM/eX5KrKJ1IKzG6Nr/NKzjH6onzEnPG6TO4cXkG1BulfdLVsGHHad4snpup X-Received: by 2002:a62:9fca:: with SMTP id v71-v6mr1627472pfk.233.1527058109190; Tue, 22 May 2018 23:48:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527058109; cv=none; d=google.com; s=arc-20160816; b=IlKQY2tYGZl6mFuoKvidWQBjStkc6XNAxTQe3lmIUCKG0DkicqCYtz38KC+pBUnchq 75kSZ7/YDS5Bvk+AP9OXyD4P2RSP3mbAWRfQUq89qtkGjlxCUOshnlu7ng9mIwTeBPvp gd5CiGRDq0ZnQZtH7fqyvK8lwcTyMSfD/rKrL2AeZ8IISdm2XNi7pJamQS2EkEf/BICV KRW+lokTfyeXgOfIKoKE2mkA7VkELqmlKGhjFmPfDP37Il3tvsN/izdgYw28GYbWOj0i 7FxKK//p3jyAHLbi3gj17B51qgqFWv0CqJsbzvA//7JnZNsGecbibaZrBQ9eWHtO7IKk HiBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=QOsxE70/7i+a4GUWUEosVMjppi+oKQJ+9MT/hpose8M=; b=ew94WqTfgmJewYakhleu8mCabNan7CeuFegtGVQAVHJmtFzjXZDUJ278OxkLSg0PCH zcQsfrJHiS2EoC5Qx44z7J6h2I6Du5631mOeDUPeG3IqKfsTAhmEJy0bMhUUM0g53W3z Kp/ehU4IQ6TvC3wkEeTYRYoGaFRYHd2j2JPrx+OaxatQMTe60AdErdyTnM8KQTsh97rE cJ9CL+J4Ep3y3j+XQ8hseZVzBZtj67IxJ8HNCQw0mIKNX3nVvjDO5Boio9UFFP7Ofgg+ T+7j124tVtjO6oIE0hYOgByD/S54NQMvm93/KK6CL5xTLZSTCMFR2hDiUiuUUe70GxKM 7NRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=io8ezfiu; spf=pass (google.com: domain of gcc-patches-return-478227-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478227-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l13-v6si1902289pga.589.2018.05.22.23.48.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 23:48:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-478227-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=io8ezfiu; spf=pass (google.com: domain of gcc-patches-return-478227-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478227-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.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:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=I242v44Ya1RWjVShMjnvXJAMEWyumw3ig5wsoqIhIyZFcTswRUhND L5eDLXgcg0nmGavM7q9rkuJLrmjwZRc1g20pu/ZdD935EVoXTB5GpmYvk0hRLP0w NV6O1QvqdPFYkc6gJ/3ofv2sTDmHqoO61R3c4oLqnAxmFWGg1SGCKw= 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:subject:date:message-id:mime-version:content-type; s= default; bh=EGoMIDbrebykYs2nA9TYDbFSW4U=; b=io8ezfiudLcV1HLgYrNm S+X1bEqWsFxx0lc0dj5+m9iTmO/mbJwdW56V1z9dAzrLjR/VjTS3wr5CZLn7e/Pi up+s4xqGemtc/mviMyydcFWvq4sRh/C3KVJeNyOPG7yrKcxqYKwk87j9zcFtUGI4 Qh95yzXhBNmljzV8BrAjUI4= Received: (qmail 13585 invoked by alias); 23 May 2018 06:48:06 -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 12990 invoked by uid 89); 23 May 2018 06:48:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f193.google.com Received: from mail-wr0-f193.google.com (HELO mail-wr0-f193.google.com) (209.85.128.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 May 2018 06:47:59 +0000 Received: by mail-wr0-f193.google.com with SMTP id p3-v6so5516322wrn.7 for ; Tue, 22 May 2018 23:47:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=QOsxE70/7i+a4GUWUEosVMjppi+oKQJ+9MT/hpose8M=; b=bilSUFKM87tHHHji/mNf/1FL6v0KIu+DCMPs1c0vV9yLkG/MtnCtcMX8RFN6es7amR ktKxGJX7E7wMp2jCc8XV4IQo+y5xCPxdDAQdG4YQNdRFD8rbvOUiyKr56fwYxlbiTRuK O2pvdcy0U6wEP5F3Rnk6W9sN+4mwl08ts3efWnmz1u/Lskr9rI73Up/2oAsYbAdxRwWG ZDFs5EhB0T3eEsB1ihvG4MJxlzCdI/koH0CBnGAVyBv55vx359xCtb5HXUNn4kmThWo+ GRzSPxwzNhOJvMKdaOP1TO7l4nC1wteakcHm4QkEZJGL1p1bmOZ+oFhlVTRSfR3UjUHQ VxCQ== X-Gm-Message-State: ALKqPwdXdD5HXf+douppRyKd83B01ANvvEEE/GPUVCVn1G3fw0WSoPW9 9Lo5h6IpVHhEqheUlS4Qq8LfnbqZexI= X-Received: by 2002:adf:c613:: with SMTP id n19-v6mr1072244wrg.177.1527058077503; Tue, 22 May 2018 23:47:57 -0700 (PDT) Received: from localhost (201.69.7.51.dyn.plus.net. [51.7.69.201]) by smtp.gmail.com with ESMTPSA id h12-v6sm2661423wmc.7.2018.05.22.23.47.56 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 23:47:56 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Try harder to preserve operand ties in maybe_legitimize_operands Date: Wed, 23 May 2018 07:47:56 +0100 Message-ID: <87in7elvfn.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 maybe_legitimize_operands normally goes through each operand in turn and legitimises it in isolation. For example, if two operands to an instruction initially have constant value C, and the instruction requires both operands to be registers, the function ends up forcing C into a register twice and passing two different registers to the instruction. I think we should try a bit harder to preserve the rtx_equal_p property, if it's easy to do. Some targets can optimise that case better than they would the general case of all operands being different. This is particularly true for SVE after the upcoming changes to the IFN_COND_* routines. This is hard to test on its own, but is covered by the upcoming IFN_COND_* patches. Tested on aarch64-linux-gnu (with and without SLP, and with and without the follow-on patch that needs it), aarch64_be-elf and x86_64-linux-gnu. OK to install? Richard 2018-05-23 Richard Sandiford gcc/ * optabs.c (can_reuse_operands_p): New function. (maybe_legitimize_operands): Try to reuse the results for earlier operands. Index: gcc/optabs.c =================================================================== --- gcc/optabs.c 2018-03-17 08:30:19.229122223 +0000 +++ gcc/optabs.c 2018-05-23 07:45:57.699793258 +0100 @@ -7207,6 +7207,44 @@ create_convert_operand_from_type (struct TYPE_UNSIGNED (type)); } +/* Return true if the requirements on operands OP1 and OP2 of instruction + ICODE are similar enough for the result of legitimizing OP1 to be + reusable for OP2. OPNO1 and OPNO2 are the operand numbers associated + with OP1 and OP2 respectively. */ + +static inline bool +can_reuse_operands_p (enum insn_code icode, + unsigned int opno1, unsigned int opno2, + const struct expand_operand *op1, + const struct expand_operand *op2) +{ + /* Check requirements that are common to all types. */ + if (op1->type != op2->type + || op1->mode != op2->mode + || (insn_data[(int) icode].operand[opno1].mode + != insn_data[(int) icode].operand[opno2].mode)) + return false; + + /* Check the requirements for specific types. */ + switch (op1->type) + { + case EXPAND_OUTPUT: + /* Outputs must remain distinct. */ + return false; + + case EXPAND_FIXED: + case EXPAND_INPUT: + case EXPAND_ADDRESS: + case EXPAND_INTEGER: + return true; + + case EXPAND_CONVERT_TO: + case EXPAND_CONVERT_FROM: + return op1->unsigned_p == op2->unsigned_p; + } + gcc_unreachable (); +} + /* Try to make operands [OPS, OPS + NOPS) match operands [OPNO, OPNO + NOPS) of instruction ICODE. Return true on success, leaving the new operand values in the OPS themselves. Emit no code on failure. */ @@ -7215,16 +7253,35 @@ create_convert_operand_from_type (struct maybe_legitimize_operands (enum insn_code icode, unsigned int opno, unsigned int nops, struct expand_operand *ops) { - rtx_insn *last; - unsigned int i; + rtx_insn *last = get_last_insn (); + rtx *orig_values = XALLOCAVEC (rtx, nops); + for (unsigned int i = 0; i < nops; i++) + { + orig_values[i] = ops[i].value; + + /* First try reusing the result of an earlier legitimization. + This avoids duplicate rtl and ensures that tied operands + remain tied. + + This search is linear, but NOPS is bounded at compile time + to a small number (current a single digit). */ + unsigned int j = 0; + for (; j < i; ++j) + if (can_reuse_operands_p (icode, opno + j, opno + i, &ops[j], &ops[i]) + && rtx_equal_p (orig_values[j], orig_values[i]) + && insn_operand_matches (icode, opno + i, ops[j].value)) + { + ops[i].value = copy_rtx (ops[j].value); + break; + } - last = get_last_insn (); - for (i = 0; i < nops; i++) - if (!maybe_legitimize_operand (icode, opno + i, &ops[i])) - { - delete_insns_since (last); - return false; - } + /* Otherwise try legitimizing the operand on its own. */ + if (j == i && !maybe_legitimize_operand (icode, opno + i, &ops[i])) + { + delete_insns_since (last); + return false; + } + } return true; }