From patchwork Tue Apr 18 14:36:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 84892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2902052vqo; Tue, 18 Apr 2023 07:37:16 -0700 (PDT) X-Google-Smtp-Source: AKy350ZglVnG5b4zDxqVO6Yj8LhD1WXEBESBp5tCL9G2DTVeHhEQax/Jn+DX5/qN/MhKFpQZM7fw X-Received: by 2002:a17:906:6d15:b0:94a:a41b:558 with SMTP id m21-20020a1709066d1500b0094aa41b0558mr12066068ejr.54.1681828636222; Tue, 18 Apr 2023 07:37:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681828636; cv=none; d=google.com; s=arc-20160816; b=bamlFBCJcXGJL9RHWCIcJZCaXMUXjKl1Y6nzzIih/i/S6Vz4mzcEIPMYeS8qqggaII OYP73E682ZTc7ZnqqweAqNg80TokIYk6x1mn3hvrTIWJyObJ00Nu9IEdr9fLflqQl4yL xxdlwJ6dYkcHZvKyewhjX5qAfpECuKNPSNfk9qZt2Q+j1KZF/ISJdND8qoQio/jmIYV7 Q+wu6HdUfF0MQopsEoO2poAP3bXeT8L90HIXPChPsx2dIojdupVtSHRjfjnB4TbNc3HL LrifsR5NkUskoN8uNensSwiC95Ina42rzXReZQIoC5H/kXS/QnxK03ESvnXucvP3M6Ds VwOA== 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=3f4olpeijo/U7V/UDoYlsyHnEKhr0pKnT1qkrXrfxdQ=; b=NkeGWOIFMD9kR70ARbNthI3ptYfgy64u/Jg9ysYRIVpYJelqBKAdTzS5GS2UnDkJAT h10cGfBkRZ3gLBWj0/e0+OaHqNUE5UADnT+mj38uXQ+FAqG3K8FSLOYmupWM6j/rZC6+ Gz/PCsY3CGb3YVswxzAZhHwxjyWjd+FZuYtEqMxe4P6iiYPbu4dBw9AFHteJ1wdoFdxR 0FlocxiRPKzxsewUPD+U1ofpozYwI18+RBiyuRPymPUwbO1snZMuMxtaii+oXDAJaYpb c+/1fzZnkeSRpC2RIwBpymxN4pvd6NEmwTKzx5b3lP0s6WyyneG3MJK3hrvgfzJg5Ats J2Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b="LVbAA5K/"; 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 fg1-20020a1709069c4100b0094f61a2431csi5332588ejc.127.2023.04.18.07.37.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 07:37:16 -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="LVbAA5K/"; 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 00AFB3858C2C for ; Tue, 18 Apr 2023 14:37:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 79F643858D32 for ; Tue, 18 Apr 2023 14:36:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79F643858D32 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-x62f.google.com with SMTP id d9443c01a7336-1a68f2345c5so13848275ad.2 for ; Tue, 18 Apr 2023 07:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681828602; x=1684420602; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3f4olpeijo/U7V/UDoYlsyHnEKhr0pKnT1qkrXrfxdQ=; b=LVbAA5K/FMj9i/Bg6LWUlGr2HpjNRozbd95UTlxS2VSIcUZpxS+y8i9Aw2/FPKpHn5 xsxNzUoIAIPoDSFwZxIky8cVPNVLH5lv5nzwkqPvhx6vxI09+mdIC8OcAcpSvWbbd3V3 6yCs/VLm7ECFp0QO+9wlueafOkkjnxEF53BvX2Jx7Fk1GFpeFX0jWUC5WPcKIqMpOJUO ED2BGlb5ygl08bEuo3HsOi6kZeqPUDQ6NfdF/DvYlzLKqu+ypbJdnF08i/cUPzLi7AJh x/MFyuy31WuD3ZG9UstkLDF3bYtWdxFg8YIgOgmRiMKq2FB4K/dElUhrglV3Pf+PdRCx lSTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681828602; x=1684420602; 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=3f4olpeijo/U7V/UDoYlsyHnEKhr0pKnT1qkrXrfxdQ=; b=KtgS382AaYl1hHAGWr4uzEjTn5gNQi4iN53/o7zwHVcAXKy+yQNbnc0qF5iZypcelU ZD3+ccXGhEqqfw29nU15Z4TjduGspm4bVK3rv+AlSmfZ30VZGiA30l8gbMwW5NH1bUdR 0D1dTPcYZImNcHnC9mWB1nFTbRCe+o8Ihf4FoV4sRhLAn+DfHhhrD04kvLQxxVs/tm0z jYaNy75D8IeUbkoemVxZWgfIF9wssvV+n/PEmWKNBp+20En/O+SQlt6WWa+1YP9i9pVL 8U2lut4sZPkb8T+jt+jW6L8bu/SzKSSePA+t6HlDY1crMXYcXpW1VqSUZfeTC5Uzc2k3 NTzQ== X-Gm-Message-State: AAQBX9fxN1ZCbeccFd/S9u2AXR0fA7uUmHUZ0lVv6EVFhyg8gEsPLUTS W/Dz0ajffq/As6twfLUVt1fx/g+How6oUJ96EKl2xw== X-Received: by 2002:a17:903:230b:b0:1a6:a6e7:8846 with SMTP id d11-20020a170903230b00b001a6a6e78846mr2706701plh.40.1681828600703; Tue, 18 Apr 2023 07:36:40 -0700 (PDT) Received: from vineet-framework.ba.rivosinc.com ([71.202.114.183]) by smtp.gmail.com with ESMTPSA id d59-20020a17090a6f4100b0023cfa3f7c9fsm8703568pjk.10.2023.04.18.07.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 07:36:39 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, Jeff Law , Palmer Dabbelt , Philipp Tomsich , Christoph Mullner , gnu-toolchain@rivosinc.co, Vineet Gupta Subject: [PATCH] riscv: relax splitter restrictions for creating pseudos Date: Tue, 18 Apr 2023 07:36:35 -0700 Message-Id: <20230418143635.980594-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_STOCKGEN, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763525144400571154?= X-GMAIL-MSGID: =?utf-8?q?1763525144400571154?= [partial addressing of PR/109279] RISCV splitters have restrictions to not create pesudos due to a combine limitatation. And despite this being a split-during-combine limitation, all split passes take the hit due to way define*_split are used in gcc. With the original combine issue being fixed 61bee6aed2 ("combine: Don't record for UNDO_MODE pointers into regno_reg_rtx array [PR104985]") the RV splitters can now be relaxed. This improves the codegen in general. e.g. long long f(void) { return 0x0101010101010101ull; } Before li a0,0x01010000 addi a0,0x0101 slli a0,a0,16 addi a0,a0,0x0101 slli a0,a0,16 addi a0,a0,0x0101 ret With patch li a5,0x01010000 addi a5,a5,0x0101 mv a0,a5 slli a5,a5,32 add a0,a5,a0 ret This is testsuite clean, no regression w/ patch. ========= Summary of gcc testsuite ========= | # of unexpected case / # of unique unexpected case | gcc | g++ | gfortran | rv64imafdc/ lp64d/ medlow | 2 / 2 | 1 / 1 | 6 / 1 | rv64imac/ lp64/ medlow | 3 / 3 | 1 / 1 | 43 / 8 | rv32imafdc/ ilp32d/ medlow | 1 / 1 | 3 / 2 | 6 / 1 | rv32imac/ ilp32/ medlow | 1 / 1 | 3 / 2 | 43 / 8 | This came up as part of IRC chat on PR/109279 and was suggested by Andrew Pinski. Signed-off-by: Vineet Gupta --- gcc/config/riscv/riscv-protos.h | 4 +-- gcc/config/riscv/riscv.cc | 46 +++++++++++++-------------------- gcc/config/riscv/riscv.md | 8 +++--- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 5244e8dcbf0a..607ff6ea697b 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -44,10 +44,10 @@ extern int riscv_const_insns (rtx); extern int riscv_split_const_insns (rtx); extern int riscv_load_store_insns (rtx, rtx_insn *); extern rtx riscv_emit_move (rtx, rtx); -extern bool riscv_split_symbol (rtx, rtx, machine_mode, rtx *, bool); +extern bool riscv_split_symbol (rtx, rtx, machine_mode, rtx *); extern bool riscv_split_symbol_type (enum riscv_symbol_type); extern rtx riscv_unspec_address (rtx, enum riscv_symbol_type); -extern void riscv_move_integer (rtx, rtx, HOST_WIDE_INT, machine_mode, bool); +extern void riscv_move_integer (rtx, rtx, HOST_WIDE_INT, machine_mode); extern bool riscv_legitimize_move (machine_mode, rtx, rtx); extern rtx riscv_subword (rtx, bool); extern bool riscv_split_64bit_move_p (rtx, rtx); diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index f5b1f2111ba0..d630567438f6 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -689,8 +689,8 @@ 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, FALSE); - riscv_move_integer (lo, lo, loval, mode, FALSE); + 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); @@ -1342,12 +1342,9 @@ riscv_swap_instruction (rtx inst) are allowed, copy it into a new register, otherwise use DEST. */ static rtx -riscv_force_temporary (rtx dest, rtx value, bool in_splitter) +riscv_force_temporary (rtx dest, rtx value) { - /* We can't call gen_reg_rtx from a splitter, because this might realloc - the regno_reg_rtx array, which would invalidate reg rtx pointers in the - combine undo buffer. */ - if (can_create_pseudo_p () && !in_splitter) + if (can_create_pseudo_p ()) return force_reg (Pmode, value); else { @@ -1406,7 +1403,7 @@ static rtx riscv_unspec_offset_high (rtx temp, rtx addr, enum riscv_symbol_type symbol_type) { addr = gen_rtx_HIGH (Pmode, riscv_unspec_address (addr, symbol_type)); - return riscv_force_temporary (temp, addr, FALSE); + return riscv_force_temporary (temp, addr); } /* Load an entry from the GOT for a TLS GD access. */ @@ -1454,8 +1451,7 @@ static rtx riscv_tls_add_tp_le (rtx dest, rtx base, rtx sym) is guaranteed to be a legitimate address for mode MODE. */ bool -riscv_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out, - bool in_splitter) +riscv_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out) { enum riscv_symbol_type symbol_type; @@ -1471,7 +1467,7 @@ riscv_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out, case SYMBOL_ABSOLUTE: { rtx high = gen_rtx_HIGH (Pmode, copy_rtx (addr)); - high = riscv_force_temporary (temp, high, in_splitter); + high = riscv_force_temporary (temp, high); *low_out = gen_rtx_LO_SUM (Pmode, high, addr); } break; @@ -1530,9 +1526,8 @@ riscv_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset) overflow, so we need to force a sign-extension check. */ high = gen_int_mode (CONST_HIGH_PART (offset), Pmode); offset = CONST_LOW_PART (offset); - high = riscv_force_temporary (temp, high, FALSE); - reg = riscv_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg), - FALSE); + high = riscv_force_temporary (temp, high); + reg = riscv_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg)); } return plus_constant (Pmode, reg, offset); } @@ -1662,7 +1657,7 @@ riscv_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, return riscv_legitimize_tls_address (x); /* See if the address can split into a high part and a LO_SUM. */ - if (riscv_split_symbol (NULL, x, mode, &addr, FALSE)) + if (riscv_split_symbol (NULL, x, mode, &addr)) return riscv_force_address (addr, mode); /* Handle BASE + OFFSET. */ @@ -1693,24 +1688,19 @@ riscv_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, void riscv_move_integer (rtx temp, rtx dest, HOST_WIDE_INT value, - machine_mode orig_mode, bool in_splitter) + machine_mode orig_mode) { struct riscv_integer_op codes[RISCV_MAX_INTEGER_OPS]; machine_mode mode; int i, num_ops; rtx x; - /* We can't call gen_reg_rtx from a splitter, because this might realloc - the regno_reg_rtx array, which would invalidate reg rtx pointers in the - combine undo buffer. */ - bool can_create_pseudo = can_create_pseudo_p () && ! in_splitter; - mode = GET_MODE (dest); /* We use the original mode for the riscv_build_integer call, because HImode values are given special treatment. */ num_ops = riscv_build_integer (codes, value, orig_mode); - if (can_create_pseudo && num_ops > 2 /* not a simple constant */ + if (can_create_pseudo_p () && num_ops > 2 /* not a simple constant */ && num_ops >= riscv_split_integer_cost (value)) x = riscv_split_integer (value, mode); else @@ -1721,7 +1711,7 @@ riscv_move_integer (rtx temp, rtx dest, HOST_WIDE_INT value, for (i = 1; i < num_ops; i++) { - if (!can_create_pseudo) + if (!can_create_pseudo_p ()) x = riscv_emit_set (temp, x); else x = force_reg (mode, x); @@ -1745,12 +1735,12 @@ riscv_legitimize_const_move (machine_mode mode, rtx dest, rtx src) /* Split moves of big integers into smaller pieces. */ if (splittable_const_int_operand (src, mode)) { - riscv_move_integer (dest, dest, INTVAL (src), mode, FALSE); + riscv_move_integer (dest, dest, INTVAL (src), mode); return; } /* Split moves of symbolic constants into high/low pairs. */ - if (riscv_split_symbol (dest, src, MAX_MACHINE_MODE, &src, FALSE)) + if (riscv_split_symbol (dest, src, MAX_MACHINE_MODE, &src)) { riscv_emit_set (dest, src); return; @@ -1771,7 +1761,7 @@ riscv_legitimize_const_move (machine_mode mode, rtx dest, rtx src) if (offset != const0_rtx && (targetm.cannot_force_const_mem (mode, src) || can_create_pseudo_p ())) { - base = riscv_force_temporary (dest, base, FALSE); + base = riscv_force_temporary (dest, base); riscv_emit_move (dest, riscv_add_offset (NULL, base, INTVAL (offset))); return; } @@ -1780,7 +1770,7 @@ riscv_legitimize_const_move (machine_mode mode, rtx dest, rtx src) /* When using explicit relocs, constant pool references are sometimes not legitimate addresses. */ - riscv_split_symbol (dest, XEXP (src, 0), mode, &XEXP (src, 0), FALSE); + riscv_split_symbol (dest, XEXP (src, 0), mode, &XEXP (src, 0)); riscv_emit_move (dest, src); } @@ -2127,7 +2117,7 @@ riscv_legitimize_move (machine_mode mode, rtx dest, rtx src) if (splittable_const_int_operand (src, mode)) { reg = gen_reg_rtx (promoted_mode); - riscv_move_integer (reg, reg, INTVAL (src), mode, FALSE); + riscv_move_integer (reg, reg, INTVAL (src), mode); } else reg = force_reg (promoted_mode, src); diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index bc384d9aedf1..5425f38c307d 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -1668,7 +1668,7 @@ [(const_int 0)] { riscv_move_integer (operands[2], operands[0], INTVAL (operands[1]), - mode, TRUE); + mode); DONE; }) @@ -1677,11 +1677,11 @@ [(set (match_operand:P 0 "register_operand") (match_operand:P 1)) (clobber (match_operand:P 2 "register_operand"))] - "riscv_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL, TRUE)" + "riscv_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)" [(set (match_dup 0) (match_dup 3))] { riscv_split_symbol (operands[2], operands[1], - MAX_MACHINE_MODE, &operands[3], TRUE); + MAX_MACHINE_MODE, &operands[3]); }) ;; Pretend to have the ability to load complex const_int in order to get @@ -1698,7 +1698,7 @@ [(const_int 0)] { riscv_move_integer (operands[0], operands[0], INTVAL (operands[1]), - mode, TRUE); + mode); DONE; })