Message ID | 20230518205716.3258223-1-vineetg@rivosinc.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp793418vqo; Thu, 18 May 2023 13:57:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6gPbVwb/O9ZbtRpUiV5vsCVLeqdt89VUkyLRLZ32E4NLEr0tXXWLaZLt/Uc6ZamssnviHe X-Received: by 2002:a17:907:36c6:b0:969:f677:11b4 with SMTP id bj6-20020a17090736c600b00969f67711b4mr369993ejc.37.1684443472980; Thu, 18 May 2023 13:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684443472; cv=none; d=google.com; s=arc-20160816; b=FRoklfXTvETQ6nP7WBcvHgxmzaCDaBNcxwyGi3xixHv4ynohsNjIgCwx7YNvz9qpJZ 4l/285MqAO+0QchPgbFbf1aj9qado4kxWpB9RJg2HmVX4FYfcSaUC2s+i10hby2ljO6T 6Y5RuJJUC1TswzaUAtkbk7bnHkJ5v7EXfU5hiu2N/EOXWV+BJ7jmBZtYYZHNHUAVQ9tI QJh6EbVxLwC5vvbn535K9dlOJ+Ly3QXQoqzECKutDkWhmpNputfxpMlOURorVUFUv+DJ RYXGGHv0+KpHRm4t9KDDwMzcno4HiBIn1j14hXUbNPLm/PwobJxqZeE0Kna14vwL2Qb0 Z5yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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:dkim-signature :dmarc-filter:delivered-to; bh=JeuwKewrwUQyFdTyEOHY5lDFHEzvByI7VmZujNmYsWE=; b=RV3MOaU/57NWqr7TrkjQgeBbW6h3kuwIN3RsE6Aa2xf5O4Lp3YgiCSpXSzzxQN8aZI FaVJupIgKILrtYkXVzTQ8myXZAsKV63J7EHLb0xhIO9TMJ1PBbiK/PP9WS3Gi3R6iL83 2DqubwZdeaomuLQOKxwVXdZk4FSoGHxghyVo8wJUSmZPPMt1MkYx5iGyuFt1slsBxPHt JXK+YGveewAr3TmIJdWv3C6Ajzn0ZiT0gYD41gIpW6YJnfqYe6YnVMt+WPX9H3uGr4wY p3Fs47drVHNr5rNyYGUSIGvUiIMRML0TrYoV3NIVL7pii623UxndDD0DsUlGlMiUwkgH 0X/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Wwzt9hS8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r17-20020aa7da11000000b00504b9fde619si1599445eds.24.2023.05.18.13.57.52 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 13:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Wwzt9hS8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 E10853857730 for <ouuuleilei@gmail.com>; Thu, 18 May 2023 20:57:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 7A82B3858D39 for <gcc-patches@gcc.gnu.org>; Thu, 18 May 2023 20:57:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A82B3858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1ae4c5e12edso20058955ad.3 for <gcc-patches@gcc.gnu.org>; Thu, 18 May 2023 13:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1684443442; x=1687035442; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JeuwKewrwUQyFdTyEOHY5lDFHEzvByI7VmZujNmYsWE=; b=Wwzt9hS88+t5+fIT4hGEByi/ECGoeASUmJUCIvZi3MlyGa7UjTn/j/zKet7a0kKZY5 vOvKcPnJ48r1Qom57rWqdKZuFUGIH1bajRC7jbeDwDomjLwBopWdDgsb0yNPae/DjKgU YBNIilWbJOPmHfIOzRaiV9qEOx5A5I25QtWeR1YhEpqfmJl/DUhD7nlThbCvOLs6F9GQ 3eVPE7dqWdM/08h27WXQhcxWD7l+AZ53I2mT/KanoPAshuzvamOhVITQslo62J9yrhwK Ix2M3EmXKKVIaxTufGu/LxrIHpElHlVODE0g0xld+7qFsgVk7zztsgOkTgkgrDiB0LpO D+wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684443442; x=1687035442; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JeuwKewrwUQyFdTyEOHY5lDFHEzvByI7VmZujNmYsWE=; b=Cw9Dr3H/IBXGjv8KcHOWPtDXcZudVwJRtD5w1KoSZC07P1/SVUItoXO7OPHqi9qpxX elA/eIQt5a/86PofHZXn5hhjuz7+FP5DpdzNBRtxylGl8AAfRFtv8WdJOFck6TonznIc g4emi6DOcEuWA3Qhxdz6HuPFeZZY+tuWbr0LWNpv5omI6Fx0rrxz+WX3bJ00rqqMEtFK +4gkMxcDhQndyY/D9WsMFCwZwaQR+32hV8HsSKLQheuDzpE1D4h1jhonidDlGOWXpo9B wHf1NoHY8pJSXnkUMetyk4p5rXM3+l/A47zKaGH83m/SomOX/A45bROCUaQAH1nAD/2V KVWw== X-Gm-Message-State: AC+VfDw9sXsclFBMfkYPw+36BbHuiWqY08L7a9eZFiOcNohoMlSMkij6 LZf9rleBs/uhXifi41YmgwjB3pvmqKXSyAwtHu4= X-Received: by 2002:a17:902:7289:b0:1ac:6084:1f4 with SMTP id d9-20020a170902728900b001ac608401f4mr423060pll.27.1684443442293; Thu, 18 May 2023 13:57:22 -0700 (PDT) Received: from vineet-framework.ba.rivosinc.com ([71.202.114.183]) by smtp.gmail.com with ESMTPSA id jj5-20020a170903048500b001ac82e8491csm1203644plb.282.2023.05.18.13.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 13:57:21 -0700 (PDT) From: Vineet Gupta <vineetg@rivosinc.com> To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, Jeff Law <jeffreyalaw@gmail.com>, Palmer Dabbelt <palmer@rivosinc.com>, Christoph Mullner <christoph.muellner@vrull.eu>, gnu-toolchain@rivosinc.com, Vineet Gupta <vineetg@rivosinc.com> Subject: [PATCH] RISC-V: improve codegen for large constants with same 32-bit lo and hi parts [2] Date: Thu, 18 May 2023 13:57:16 -0700 Message-Id: <20230518205716.3258223-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766266999341754415?= X-GMAIL-MSGID: =?utf-8?q?1766266999341754415?= |
Series |
RISC-V: improve codegen for large constants with same 32-bit lo and hi parts [2]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Vineet Gupta
May 18, 2023, 8:57 p.m. UTC
[part #2 of PR/109279]
SPEC2017 deepsjeng uses large constants which currently generates less than
ideal code. This fix improves codegen for large constants which have
same low and hi parts: e.g.
long long f(void) { return 0x0101010101010101ull; }
Before
li a5,0x1010000
addi a5,a5,0x101
mv a0,a5
slli a5,a5,32
add a0,a5,a0
ret
With patch
li a5,0x1010000
addi a5,a5,0x101
slli a0,a5,32
add a0,a0,a5
ret
This is testsuite clean.
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_split_integer): if loval is equal
to hival, ASHIFT the corresponding regs.
Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
---
gcc/config/riscv/riscv.cc | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
Comments
On 5/18/23 14:57, Vineet Gupta wrote: > [part #2 of PR/109279] > > SPEC2017 deepsjeng uses large constants which currently generates less than > ideal code. This fix improves codegen for large constants which have > same low and hi parts: e.g. > > long long f(void) { return 0x0101010101010101ull; } > > Before > li a5,0x1010000 > addi a5,a5,0x101 > mv a0,a5 > slli a5,a5,32 > add a0,a5,a0 > ret > > With patch > li a5,0x1010000 > addi a5,a5,0x101 > slli a0,a5,32 > add a0,a0,a5 > ret > > This is testsuite clean. > > gcc/ChangeLog: > > * config/riscv/riscv.cc (riscv_split_integer): if loval is equal > to hival, ASHIFT the corresponding regs. LGTM. Please install. Thanks for taking care of this! The updated sequence looks good. Jeff
On Fri, 19 May 2023 09:33:34 PDT (-0700), jeffreyalaw@gmail.com wrote: > > > On 5/18/23 14:57, Vineet Gupta wrote: >> [part #2 of PR/109279] >> >> SPEC2017 deepsjeng uses large constants which currently generates less than >> ideal code. This fix improves codegen for large constants which have >> same low and hi parts: e.g. >> >> long long f(void) { return 0x0101010101010101ull; } >> >> Before >> li a5,0x1010000 >> addi a5,a5,0x101 >> mv a0,a5 >> slli a5,a5,32 >> add a0,a5,a0 >> ret >> >> With patch >> li a5,0x1010000 >> addi a5,a5,0x101 >> slli a0,a5,32 >> add a0,a0,a5 >> ret >> >> This is testsuite clean. >> >> gcc/ChangeLog: >> >> * config/riscv/riscv.cc (riscv_split_integer): if loval is equal >> to hival, ASHIFT the corresponding regs. > LGTM. Please install. Thanks for taking care of this! The updated > sequence looks good. Works for me. Did you start that performance backports branch? Either way, I think this should go on it.
On 5/19/23 09:36, Palmer Dabbelt wrote: > Works for me. Did you start that performance backports branch? > Either way, I think this should go on it. Please note that there is a bit of dependency chain. Assuming the aforementioned branch is gcc 13.1 based, this change also needs my splitter relaxation fix g0530254413f8 to ensure incremental improvements to large const codegen.
On 5/19/23 09:33, Jeff Law wrote: > > > On 5/18/23 14:57, Vineet Gupta wrote: >> [part #2 of PR/109279] >> >> SPEC2017 deepsjeng uses large constants which currently generates >> less than >> ideal code. This fix improves codegen for large constants which have >> same low and hi parts: e.g. >> >> long long f(void) { return 0x0101010101010101ull; } >> >> Before >> li a5,0x1010000 >> addi a5,a5,0x101 >> mv a0,a5 >> slli a5,a5,32 >> add a0,a5,a0 >> ret >> >> With patch >> li a5,0x1010000 >> addi a5,a5,0x101 >> slli a0,a5,32 >> add a0,a0,a5 >> ret >> >> This is testsuite clean. >> >> gcc/ChangeLog: >> >> * config/riscv/riscv.cc (riscv_split_integer): if loval is equal >> to hival, ASHIFT the corresponding regs. > LGTM. Please install. Thanks for taking care of this! The updated > sequence looks good. > > Jeff
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 79122699b6f5..4e1bb2f14cf8 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -703,13 +703,18 @@ riscv_split_integer (HOST_WIDE_INT val, machine_mode mode) unsigned HOST_WIDE_INT hival = sext_hwi ((val - loval) >> 32, 32); rtx hi = gen_reg_rtx (mode), lo = gen_reg_rtx (mode); - riscv_move_integer (hi, hi, hival, mode); riscv_move_integer (lo, lo, loval, mode); - hi = gen_rtx_fmt_ee (ASHIFT, mode, hi, GEN_INT (32)); - hi = force_reg (mode, hi); + if (loval == hival) + hi = gen_rtx_ASHIFT (mode, lo, GEN_INT (32)); + else + { + riscv_move_integer (hi, hi, hival, mode); + hi = gen_rtx_ASHIFT (mode, hi, GEN_INT (32)); + } - return gen_rtx_fmt_ee (PLUS, mode, hi, lo); + hi = force_reg (mode, hi); + return gen_rtx_PLUS (mode, hi, lo); } /* Return true if X is a thread-local symbol. */