From patchwork Thu Nov 23 03:04:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Jie X-Patchwork-Id: 168709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp232598vqx; Wed, 22 Nov 2023 21:27:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeRgfXLUmQ5p94e/BiDHxeY/22q9byFpcWxAWFZjF1FtP6K+Pg715f0cMZQzsDrrcJ7kaR X-Received: by 2002:ac8:5802:0:b0:423:7651:9480 with SMTP id g2-20020ac85802000000b0042376519480mr5936880qtg.10.1700717221747; Wed, 22 Nov 2023 21:27:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700717221; cv=pass; d=google.com; s=arc-20160816; b=pyZ5ajFoBWzzmtFzAfiwo6N6ZnUfUYocwxug2VqFYTlNRxVI33TT1N3qaPW5Dnp+as XXUlOTYEPTO+NsN5SqmbEZPhCB61k93QfwoNZ6z769nVZlTivUXNGTNZzOqHssxEg/hI XPrt/KsCwk3oewT6GOeJE1y87JAcEDkStepfq4urvusQtmoyWjfakD32yX/ld5u0kY7R JLoVk6CeO6h/+ddzxF/DV7+8UxhFKBhqMYk5CHG+bckMBdi9VDyHi0XYpLdzBPPe7yXS FYiyCWKb4BxVnh4QIbD5oKPNPfkt9OElJpYJea68ZwXdH+kaDl3Aa7I/epANtG2IzXwF /C9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=k/OIT+yfmInZ9vv+78UhC5HO79Smm0k0cq5Mjw/hiNk=; fh=FCC/Zx3UOwReG8Kz3H/ln+uGOf+6klnWwvVPHAnfABw=; b=cYWNhYX//euppzR4qEKDsZ0qpNwio1TWqgfKVo419Eo03+baW2zQgAx7Gy8OYIt9c8 f9DOmxkHs+9v8hWYVNvfIxXdvpRjm/Y1PoKMij7T2ZvNzHJtVmXNMWe5zRCepTRFvkj/ GOQnig4Y64h1KZdYDrqbqs4H7rAunUtllTFy0QCqZ1yWWcWLhLX3gHTDr8z2D1KqtQcr 2Oki95ISqCzuocqaMYzHJn3+oe6iMkIp37j8iiZf7r3/9iCGnDDhkRa2zDGNBmbAH6eY YfZF0yYAnu+QESjMlr+dNGFuPSg/2JBNXkrIm+IrSU4KCx0bA53+O2yhbx/J1Q5rZS4P NnMg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bv8-20020a05622a0a0800b004238be74299si480594qtb.644.2023.11.22.21.27.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 21:27:01 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18D7A395ACEA for ; Thu, 23 Nov 2023 03:05:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id E5B1738618DC for ; Thu, 23 Nov 2023 03:05:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5B1738618DC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E5B1738618DC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700708714; cv=none; b=qthPHC21i+JOCL8+BtgDH8ASXMkyWmq8vhiJuWxnCjTCh/NGgNgfUEpDbb9djZPuWlFooQvuxjMvPWrAXeEtEdHv6A38utvU8VYGSlprbywvFamNiXGCo2WjuyXYU3+fZ2TDI2QQjuzpn7HEdjezT+vj3RkKRp1rsiieorZiQmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700708714; c=relaxed/simple; bh=IpvtdSttDuxiBAAFjjdHuhIoWxYDEvNuUilUc3Fka9I=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=CQkIc4RN2r0umg5cD2fRFtYgRnhUpVVraN3ihBpgMgTZxco9L76eJFhNYpJL24wUWSVd1YzWUvnstdjalZEdGz+Jxy7MIqhmS4wTVhaWEanK7Mb1KI47QZMdR7HT2dUtU29KMBiz21tIay5w+EL7CoFT4yEzG8e10rWyAgjk8jU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.20.4.191]) by gateway (Coremail) with SMTP id _____8AxTetjwV5lxys8AA--.48418S3; Thu, 23 Nov 2023 11:05:08 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.191]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dxnd5ZwV5lA0RKAA--.34212S4; Thu, 23 Nov 2023 11:05:06 +0800 (CST) From: Guo Jie To: gcc-patches@gcc.gnu.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, i@xen0n.name, xry111@xry111.site, Guo Jie Subject: [PATCH v2] LoongArch: Optimize the loading of immediate numbers with the same high and low 32-bit values Date: Thu, 23 Nov 2023 11:04:17 +0800 Message-Id: <20231123030417.29993-1-guojie@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dxnd5ZwV5lA0RKAA--.34212S4 X-CM-SenderInfo: xjxryx3h6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoWxAF1ruw1xuF1kCF1fWr1rAFc_yoW5tF1fpa y2vrnYqr48JF93GFn7J345Gws3Jrs3G3ya93ZIqryxursxJ3sIgF18G39ruF1UGayUXry2 g3WS9ayaga13Z3cCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU1QVy3UUUUU== X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783331261361444433 X-GMAIL-MSGID: 1783331261361444433 For the following immediate load operation in gcc/testsuite/gcc.target/loongarch/imm-load1.c: long long r = 0x0101010101010101; Before this patch: lu12i.w $r15,16842752>>12 ori $r15,$r15,257 lu32i.d $r15,0x1010100000000>>32 lu52i.d $r15,$r15,0x100000000000000>>52 After this patch: lu12i.w $r15,16842752>>12 ori $r15,$r15,257 bstrins.d $r15,$r15,63,32 gcc/ChangeLog: * config/loongarch/loongarch.cc (enum loongarch_load_imm_method): Add new method. (loongarch_build_integer): Add relevant implementations for new method. (loongarch_move_integer): Ditto. gcc/testsuite/ChangeLog: * gcc.target/loongarch/imm-load1.c: Change old check. --- Update in v2: 1. Correct the format of ChangeLog. 2. Avoid left shift of negative value in loongarch_build_integer. --- gcc/config/loongarch/loongarch.cc | 22 ++++++++++++++++++- .../gcc.target/loongarch/imm-load1.c | 3 ++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index d05743bec87..f95507e2348 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -142,12 +142,16 @@ struct loongarch_address_info METHOD_LU52I: Load 52-63 bit of the immediate number. + + METHOD_MIRROR: + Copy 0-31 bit of the immediate number to 32-63bit. */ enum loongarch_load_imm_method { METHOD_NORMAL, METHOD_LU32I, - METHOD_LU52I + METHOD_LU52I, + METHOD_MIRROR }; struct loongarch_integer_op @@ -1556,11 +1560,23 @@ loongarch_build_integer (struct loongarch_integer_op *codes, int sign31 = (value & (HOST_WIDE_INT_1U << 31)) >> 31; int sign51 = (value & (HOST_WIDE_INT_1U << 51)) >> 51; + + uint32_t hival = (uint32_t) (value >> 32); + uint32_t loval = (uint32_t) value; + /* Determine whether the upper 32 bits are sign-extended from the lower 32 bits. If it is, the instructions to load the high order can be ommitted. */ if (lu32i[sign31] && lu52i[sign31]) return cost; + /* If the lower 32 bits are the same as the upper 32 bits, just copy + the lower 32 bits to the upper 32 bits. */ + else if (loval == hival) + { + codes[cost].method = METHOD_MIRROR; + codes[cost].curr_value = value; + return cost + 1; + } /* Determine whether bits 32-51 are sign-extended from the lower 32 bits. If so, directly load 52-63 bits. */ else if (lu32i[sign31]) @@ -3230,6 +3246,10 @@ loongarch_move_integer (rtx temp, rtx dest, unsigned HOST_WIDE_INT value) gen_rtx_AND (DImode, x, GEN_INT (0xfffffffffffff)), GEN_INT (codes[i].value)); break; + case METHOD_MIRROR: + gcc_assert (mode == DImode); + emit_insn (gen_insvdi (x, GEN_INT (32), GEN_INT (32), x)); + break; default: gcc_unreachable (); } diff --git a/gcc/testsuite/gcc.target/loongarch/imm-load1.c b/gcc/testsuite/gcc.target/loongarch/imm-load1.c index 2ff02971239..f64cc2956a3 100644 --- a/gcc/testsuite/gcc.target/loongarch/imm-load1.c +++ b/gcc/testsuite/gcc.target/loongarch/imm-load1.c @@ -1,6 +1,7 @@ /* { dg-do compile } */ /* { dg-options "-mabi=lp64d -O2" } */ -/* { dg-final { scan-assembler "test:.*lu52i\.d.*\n\taddi\.w.*\n\.L2:" } } */ +/* { dg-final { scan-assembler-not "test:.*lu52i\.d.*\n\taddi\.w.*\n\.L2:" } } */ +/* { dg-final { scan-assembler "test:.*lu12i\.w.*\n\tbstrins\.d.*\n\.L2:" } } */ extern long long b[10];