From patchwork Fri Jun 30 23:33:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 1802168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20221208.gappssmtp.com header.i=@rivosinc-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=3t24Qwqz; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QtBTb3X0Zz20ZV for ; Sat, 1 Jul 2023 09:33:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 96A5A385735E for ; Fri, 30 Jun 2023 23:33:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id B27073858D33 for ; Fri, 30 Jun 2023 23:33:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B27073858D33 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-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-26307d808a4so1646266a91.1 for ; Fri, 30 Jun 2023 16:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1688168000; x=1690760000; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=N0O1z2PVtt5WJkQ2O8TYppLCC5yhgaHDQjWpdcrf2eM=; b=3t24QwqzjOf7MXNvOmZfO9YXeM5KEy5GaqPXQt7J3okxDHVB8YTLVxRPr5E7Ril1a1 SPeNg6HfSZhgcpX03v11GrWfKAH3V4heSnXirCjW2WRHh27RdLe4qCtMYajWMWAge1lv tgHo0bTKJkkTGBMj+AV9NPaSZg3MERbSXZnZMxngWeEc0KGNnbWN5nZ6NY+1uV5ZpHcr lbhzWVvogkFHbHLEgqJZRq/glxo5gncel2F/KkWF8WZzJjbQN2HiYWPkfp5X4tSNsiGS SYzZYI1Tb24W2WIC4jFLLLgEB3r4tTejzIcvwq5oT5nLwhgRYoOfycWbmFjMEcWlp2Sn i6fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688168000; x=1690760000; 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=N0O1z2PVtt5WJkQ2O8TYppLCC5yhgaHDQjWpdcrf2eM=; b=lAupECiexh0ga+IVh+oVVR97u5XSEusxwARsYbtcUevwG9Ids9tJN9udeD/ALzjyN2 m7HjvifN9YlzycG55FPLCmWMB9fRXZcxdy6zdzx7Sk4yyHv5jXRcjqRAfiyybh70VFcY zJ6rnopTHs3ZgyxCul81uOd5k+yOKFY99CbeV6rQ6AW9jFnytKUnngiTHEm03rV6MCdR 9vR2U7c5tgomlVSezQz5EDE2ALmkVMVuD488ITygZxpCjIfcqCc6evcnX+EES5OV49at fBGg1ekoSJUvrk181nNSB3yvekDxg6fFSHu4ug/CS5FTsng85YgIZ0Qf8NHOL/ADvbZk 8TyQ== X-Gm-Message-State: ABy/qLYLwbbdJC/TDuflbbPei6U9qv50dhGBBOe9XYMl3/JD6iIJ6Nzg 3LxsTzXbNSPXieBzrSs9J8skv6VVmJ0fP9Mffeo= X-Google-Smtp-Source: APBJJlE3dcxlZRwOVt/gjFtK7L3jKjqp8GcVsGDVuU7kDRXqYRORgTI/DwLYC67aMrpNPWTNOELSxw== X-Received: by 2002:a17:90a:4985:b0:261:1141:b716 with SMTP id d5-20020a17090a498500b002611141b716mr3516016pjh.33.1688168000383; Fri, 30 Jun 2023 16:33:20 -0700 (PDT) Received: from vineet-framework.. ([71.202.114.183]) by smtp.gmail.com with ESMTPSA id g1-20020a17090a714100b00262e9fbd5fbsm9246307pjs.32.2023.06.30.16.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 16:33:19 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, Jeff Law , Palmer Dabbelt , gnu-toolchain@rivosinc.com, Vineet Gupta Subject: [PATCH] RISC-V: improve codegen for repeating large constants [3] Date: Fri, 30 Jun 2023 16:33:15 -0700 Message-Id: <20230630233315.212700-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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, WEIRD_PORT 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Ran into a minor snafu in const splitting code when playing with test case from an old PR/23813. long long f(void) { return 0xF0F0F0F0F0F0F0F0ull; } This currently generates li a5,-252645376 addi a5,a5,241 li a0,-252645376 slli a5,a5,32 addi a0,a0,240 add a0,a5,a0 ret The signed math in hival extraction introduces an additional bit, causing loval == hival check to fail. | riscv_split_integer (val=-1085102592571150096, mode=E_DImode) at ../gcc/config/riscv/riscv.cc:702 | 702 unsigned HOST_WIDE_INT loval = sext_hwi (val, 32); | (gdb)n | 703 unsigned HOST_WIDE_INT hival = sext_hwi ((val - loval) >> 32, 32); | (gdb) | 704 rtx hi = gen_reg_rtx (mode), lo = gen_reg_rtx (mode); | (gdb) p/x val | $2 = 0xf0f0f0f0f0f0f0f0 | (gdb) p/x loval | $3 = 0xfffffffff0f0f0f0 | (gdb) p/x hival | $4 = 0xfffffffff0f0f0f1 ^^^ Fix that by eliding the subtraction in shift. With patch: li a5,-252645376 addi a5,a5,240 slli a0,a5,32 add a0,a0,a5 ret gcc/ChangeLog: * config/riscv/riscv.cc (riscv_split_integer): hival computation do elide subtraction of loval. * (riscv_split_integer_cost): Ditto. * (riscv_build_integer): Ditto Signed-off-by: Vineet Gupta --- I wasn't planning to do any more work on large const stuff, but just ran into it this on a random BZ entry when trying search for redundant constant stuff. The test seemed too good to pass :-) --- gcc/config/riscv/riscv.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 5ac187c1b1b4..377d3aac794b 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -643,7 +643,7 @@ riscv_build_integer (struct riscv_integer_op *codes, HOST_WIDE_INT value, && (value > INT32_MAX || value < INT32_MIN)) { unsigned HOST_WIDE_INT loval = sext_hwi (value, 32); - unsigned HOST_WIDE_INT hival = sext_hwi ((value - loval) >> 32, 32); + unsigned HOST_WIDE_INT hival = sext_hwi (value >> 32, 32); struct riscv_integer_op alt_codes[RISCV_MAX_INTEGER_OPS]; struct riscv_integer_op hicode[RISCV_MAX_INTEGER_OPS]; int hi_cost, lo_cost; @@ -674,7 +674,7 @@ riscv_split_integer_cost (HOST_WIDE_INT val) { int cost; unsigned HOST_WIDE_INT loval = sext_hwi (val, 32); - unsigned HOST_WIDE_INT hival = sext_hwi ((val - loval) >> 32, 32); + unsigned HOST_WIDE_INT hival = sext_hwi (val >> 32, 32); struct riscv_integer_op codes[RISCV_MAX_INTEGER_OPS]; cost = 2 + riscv_build_integer (codes, loval, VOIDmode); @@ -700,7 +700,7 @@ static rtx riscv_split_integer (HOST_WIDE_INT val, machine_mode mode) { unsigned HOST_WIDE_INT loval = sext_hwi (val, 32); - unsigned HOST_WIDE_INT hival = sext_hwi ((val - loval) >> 32, 32); + unsigned HOST_WIDE_INT hival = sext_hwi (val >> 32, 32); rtx hi = gen_reg_rtx (mode), lo = gen_reg_rtx (mode); riscv_move_integer (lo, lo, loval, mode);