From patchwork Fri Jul 14 02:08:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Endo X-Patchwork-Id: 1807491 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=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4R2FKB6XHTz20bt for ; Fri, 14 Jul 2023 12:09:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C32A93858407 for ; Fri, 14 Jul 2023 02:09:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mailout12.t-online.de (mailout12.t-online.de [194.25.134.22]) by sourceware.org (Postfix) with ESMTPS id 0B2203858CDB for ; Fri, 14 Jul 2023 02:08:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B2203858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=t-online.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=t-online.de Received: from fwd87.dcpf.telekom.de (fwd87.aul.t-online.de [10.223.144.113]) by mailout12.t-online.de (Postfix) with SMTP id 165EAACF4 for ; Fri, 14 Jul 2023 04:08:52 +0200 (CEST) Received: from localhost.localdomain ([115.165.108.210]) by fwd87.t-online.de with (TLSv1.3:TLS_AES_256_GCM_SHA384 encrypted) esmtp id 1qK8Ee-3sycHg0; Fri, 14 Jul 2023 04:08:45 +0200 Message-ID: <467fc2d9a524d2bbc0f9ae6d9317c17b23924b0c.camel@t-online.de> Subject: [SH][committed] Fix PR 101469 From: Oleg Endo To: gcc-patches Date: Fri, 14 Jul 2023 11:08:41 +0900 User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-TOI-EXPURGATEID: 150726::1689300525-F57EE704-D91D7B98/0/0 CLEAN NORMAL X-TOI-MSGID: 5b403417-f8e7-47a5-8f40-5f4690a5ffc6 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, The attached patch fixes PR 101469. Tested by the original reporter Rin Okuyama on NetBSD with GCC 10.5. Applied to master, GCC 11, GCC 12, GCC 13 after 'make all' sanity check. Cheers, Oleg gcc/ChangeLog: PR target/101469 * config/sh/sh.md (peephole2): Handle case where eliminated reg is also used by the address of the following memory operand. diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md index 4622dba0121..76e7774cef3 100644 --- a/gcc/config/sh/sh.md +++ b/gcc/config/sh/sh.md @@ -10680,6 +10680,45 @@ && peep2_reg_dead_p (2, operands[1]) && peep2_reg_dead_p (3, operands[0])" [(const_int 0)] { + if (MEM_P (operands[3]) && reg_overlap_mentioned_p (operands[0], operands[3])) + { + // Take care when the eliminated operand[0] register is part of + // the destination memory address. + rtx addr = XEXP (operands[3], 0); + + if (REG_P (addr)) + operands[3] = replace_equiv_address (operands[3], operands[1]); + + else if (GET_CODE (addr) == PLUS && REG_P (XEXP (addr, 0)) + && CONST_INT_P (XEXP (addr, 1)) + && REGNO (operands[0]) == REGNO (XEXP (addr, 0))) + operands[3] = replace_equiv_address (operands[3], + gen_rtx_PLUS (SImode, operands[1], XEXP (addr, 1))); + + else if (GET_CODE (addr) == PLUS && REG_P (XEXP (addr, 0)) + && REG_P (XEXP (addr, 1))) + { + // register + register address @(R0, Rn) + // can change only the Rn in the address, not R0. + if (REGNO (operands[0]) == REGNO (XEXP (addr, 0)) + && REGNO (XEXP (addr, 0)) != 0) + { + operands[3] = replace_equiv_address (operands[3], + gen_rtx_PLUS (SImode, operands[1], XEXP (addr, 1))); + } + else if (REGNO (operands[0]) == REGNO (XEXP (addr, 1)) + && REGNO (XEXP (addr, 1)) != 0) + { + operands[3] = replace_equiv_address (operands[3], + gen_rtx_PLUS (SImode, XEXP (addr, 0), operands[1])); + } + else + FAIL; + } + else + FAIL; + } + emit_insn (gen_addsi3 (operands[1], operands[1], operands[2])); sh_peephole_emit_move_insn (operands[3], operands[1]); })