From patchwork Wed Feb 15 15:34:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 57601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp257662wrn; Wed, 15 Feb 2023 07:35:29 -0800 (PST) X-Google-Smtp-Source: AK7set+04robkgAxWeRWXjf62MhXyMehKPBycLyeWBdozmF7OPm4xHVs7cjfoVotoHBMSpqBG3sj X-Received: by 2002:a17:907:2bca:b0:8b1:319c:c29c with SMTP id gv10-20020a1709072bca00b008b1319cc29cmr2636146ejc.70.1676475329241; Wed, 15 Feb 2023 07:35:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676475329; cv=none; d=google.com; s=arc-20160816; b=xHjRRX7NGm4Wk4WDAslsmZTRoyJBdv/GqV+LmzKso0aUdiaVm9pTg+2P/AKYXBl1LH U2M8Dn24RnnRFn6uYrnu5U4RrZbQSaMBQGqXkh9dxHYBN/VM/CC8ADwvc5RYXEWC4tHz 6xFugeZxBgG9cqZx6pHeKNcY/w4NGqOdZMjxno7xyj7fPK4qedw+hQvsoDLt9+2CeZvF XXLFlxhn7B7l6sU5H6HUmE6hgMGyGM45K+8kYWm9EElC4w5758fZsXG/O/qxXNm17nm8 oNTRMls2m9M24uTmeED2ey4jEM0YK3g4BJE/jnh74Gl7Kh2Lqh8uKqtpWngpN8sRG1MP OcYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:date:message-id :content-transfer-encoding:mime-version:subject:to:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=26xUzVitiQbxw0eB7Yh4CFA/eceQofrWhiWtrVvNvd4=; b=V9Q8EBr84NwbXgYdDkXGAjQOXvxos33G82steuo4iZYnNbybf3wqxr4eIjhgZkWMMd ns742qomPLdj7/smmxnfEZWVJ7A32+MKvH3OScTBawjGb6xr4IUDqaUBiPPgwuRzuYYy NKZqycEqBNL+/Dn2FZrXC4VNNkmeUonzlZF31hyN0MMpC4KS3QCXXcF6bjkLKaq8FCrg rSI4ktnICpqWF499wihYIQmV6WEcsU8bZkIrncfVNmRhQw6fedJvVt2xLoRRrbM2TpT1 DMz9NRj/RvL2Nk4WhYuggICvlZx7ZY+q8IDaPIR3tMONPmvZJ+77xoEweoogsOJTvpbJ DbGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mrdHqg7U; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id mr30-20020a170907829e00b00888c44d9d86si20834529ejc.508.2023.02.15.07.35.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 07:35:29 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mrdHqg7U; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A4BFE3857C55 for ; Wed, 15 Feb 2023 15:35:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4BFE3857C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676475323; bh=26xUzVitiQbxw0eB7Yh4CFA/eceQofrWhiWtrVvNvd4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mrdHqg7UA4jsG6qcGOysuxmG1Q7DZtjHb8olnQjXF7cLbw/Ncp5UuMlaUCTqCODYp /NMthRrzk+cfUVis5DbbanmzDrG94l9zlIJBAmeSDj9UxFAn8oV/841PwY7AEQ9ucb iKVqpujNEASISef7Ul8aQ9IHIH4shreKa2q7lbUc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by sourceware.org (Postfix) with ESMTPS id 4BDA13858C60 for ; Wed, 15 Feb 2023 15:34:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4BDA13858C60 To: Subject: [PATCH] reload: Handle generating reloads that also clobbers flags MIME-Version: 1.0 Message-ID: <20230215153432.0663D2042E@pchp3.se.axis.com> Date: Wed, 15 Feb 2023 16:34:32 +0100 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP 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: , X-Patchwork-Original-From: Hans-Peter Nilsson via Gcc-patches From: Hans-Peter Nilsson Reply-To: Hans-Peter Nilsson 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?1757911795061817693?= X-GMAIL-MSGID: =?utf-8?q?1757911795061817693?= Regtested cris-elf with its LEGITIMIZE_RELOAD_ADDRESS disabled, where it regresses gcc.target/cris/rld-legit1.c; as expected, because that test guards proper function of its LEGITIMIZE_RELOAD_ADDRESS i.e., that there's no sign of decomposed address elements. LRA also causes a similar decomposition (and worse, in even smaller bits), but it can create valid insns as-is. Unfortunately, it doesn't have something equivalent to LEGITIMIZE_RELOAD_ADDRESS so it generates worse code for cases where that hook helped reload. I fear reload-related patches these days are treated like a redheaded stepchild and even worse as this one is intended for stage 1. Either way, I need to create a reference to it, and it's properly tested and has been a help when working towards LRA, thus might help other targets: ok to install for the next stage 1? -- >8 -- When LEGITIMIZE_RELOAD_ADDRESS for cris-elf is disabled, this code is now required for reload to generate valid insns from some reload-decomposed addresses, for example the (plus:SI (sign_extend:SI (mem:HI (reg/v/f:SI 32 [ a ]) [1 *a_6(D)+0 S2 A8])) (reg/v/f:SI 33 [ y ])) generated in gcc.target/cris/rld-legit1.c (a valid address but with two registers needing reload). Now after decc0:ing, most SET insns for former cc0 targets need to be a parallel with a clobber of the flags register. Such targets typically have TARGET_FLAGS_REGNUM set to a valid register. * reload1.cc (emit_insn_if_valid_for_reload_1): Rename from emit_insn_if_valid_for_reload. (emit_insn_if_valid_for_reload): Call new helper, and if a SET fails to be recognized, also try emitting a parallel that clobbers TARGET_FLAGS_REGNUM, as applicable. --- gcc/reload1.cc | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/gcc/reload1.cc b/gcc/reload1.cc index 7dcef50437b8..9ec2cb9baf4b 100644 --- a/gcc/reload1.cc +++ b/gcc/reload1.cc @@ -8377,11 +8377,11 @@ emit_reload_insns (class insn_chain *chain) reg_reloaded_dead |= reg_reloaded_died; } -/* Go through the motions to emit INSN and test if it is strictly valid. - Return the emitted insn if valid, else return NULL. */ + +/* Helper for emit_insn_if_valid_for_reload. */ static rtx_insn * -emit_insn_if_valid_for_reload (rtx pat) +emit_insn_if_valid_for_reload_1 (rtx pat) { rtx_insn *last = get_last_insn (); int code; @@ -8403,6 +8403,29 @@ emit_insn_if_valid_for_reload (rtx pat) return NULL; } +/* Go through the motions to emit INSN and test if it is strictly valid. + Return the emitted insn if valid, else return NULL. */ + +static rtx_insn * +emit_insn_if_valid_for_reload (rtx pat) +{ + rtx_insn *insn = emit_insn_if_valid_for_reload_1 (pat); + + if (insn) + return insn; + + /* If the pattern is a SET, and this target has a single + flags-register, try again with a PARALLEL that clobbers that + register. */ + if (targetm.flags_regnum == INVALID_REGNUM || GET_CODE (pat) != SET) + return NULL; + + rtx flags_clobber = gen_hard_reg_clobber (CCmode, targetm.flags_regnum); + rtx parpat = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, pat, flags_clobber)); + + return emit_insn_if_valid_for_reload (parpat); +} + /* Emit code to perform a reload from IN (which may be a reload register) to OUT (which may also be a reload register). IN or OUT is from operand OPNUM with reload type TYPE.