From patchwork Tue Aug 27 20:21:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 1977462 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=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wtf8t0Yshz1yg0 for ; Wed, 28 Aug 2024 06:22:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 029F6385F018 for ; Tue, 27 Aug 2024 20:22:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-out.m-online.net (mail-out.m-online.net [IPv6:2001:a60:0:28:0:1:25:1]) by sourceware.org (Postfix) with ESMTPS id 63C5B385DDFC for ; Tue, 27 Aug 2024 20:21:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63C5B385DDFC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nefkom.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 63C5B385DDFC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:a60:0:28:0:1:25:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724790105; cv=none; b=CYUDYQVPklIGkvm9GzpCiwyaIVxv9E1N/dn/GZU3TWnNQ1UI6phRAEW9GQzyVB9WIKRgPlVLRhoTBlHhGeDslu/B+D8LDIP4LctApw8lvNe/4368yEW6E1wsxTYi8ln6WdxZ+AaNLAEb73p4QpY/VIEIhgvT04t2nqu5HM/CEXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724790105; c=relaxed/simple; bh=Gjiu2fl+ClI0P4FwQg94r65zb5z8JaFPyGcIH3esAVg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PpkWwhVG/ctG+4wkqJhytgCdxzviy4EW2mtG09kYuarAeSJk/EGCUZ8dwyIp8KyDIV5UBPdvzegYvkpA1Bs0zpWii3H1p51PlRAdmJaw5vPy2EBLO5T7PNz8oc3nNcjjaQ0P6tJC9miofm0BrcVsoj0LfUVOy28CiUxZUC5XkLA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4Wtf8P11Lmz1sbMy for ; Tue, 27 Aug 2024 22:21:40 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 4Wtf8N2S8fz1qqlS for ; Tue, 27 Aug 2024 22:21:40 +0200 (CEST) X-Virus-Scanned: amavis at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavis, port 10024) with ESMTP id F-6ICnY6_Vr0 for ; Tue, 27 Aug 2024 22:21:39 +0200 (CEST) X-Auth-Info: 68tWcpNtoQ2Sfmt+FWlufU1cdpt/dBnX+ebOGNCYBbxBWRZ+KUvwuD+08HwIe7i/ Received: from igel.home (aftr-82-135-83-223.dynamic.mnet-online.de [82.135.83.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA for ; Tue, 27 Aug 2024 22:21:39 +0200 (CEST) Received: by igel.home (Postfix, from userid 1000) id 4E74F2C1A16; Tue, 27 Aug 2024 22:21:39 +0200 (CEST) From: Andreas Schwab To: gcc-patches@gcc.gnu.org Subject: m68k: Accept ASHIFT like MULT in address operand X-Yow: If our behavior is strict, we do not need fun! Date: Tue, 27 Aug 2024 22:21:39 +0200 Message-ID: <878qwhu370.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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.30 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 When LRA pulls an address operand out of a MEM it caninoicalizes a containing MULT into ASHIFT. Adjust the address decomposer to recognize this form. PR target/116413 * config/m68k/m68k.cc (m68k_decompose_index): Accept ASHIFT like MULT. (m68k_rtx_costs) [PLUS]: Likewise. (m68k_legitimize_address): Likewise. --- gcc/config/m68k/m68k.cc | 58 ++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/gcc/config/m68k/m68k.cc b/gcc/config/m68k/m68k.cc index 21c94981d22..7986e92c511 100644 --- a/gcc/config/m68k/m68k.cc +++ b/gcc/config/m68k/m68k.cc @@ -1503,12 +1503,14 @@ m68k_legitimize_address (rtx x, rtx oldx, machine_mode mode) #define COPY_ONCE(Y) if (!copied) { Y = copy_rtx (Y); copied = ch = 1; } - if (GET_CODE (XEXP (x, 0)) == MULT) + if (GET_CODE (XEXP (x, 0)) == MULT + || GET_CODE (XEXP (x, 0)) == ASHIFT) { COPY_ONCE (x); XEXP (x, 0) = force_operand (XEXP (x, 0), 0); } - if (GET_CODE (XEXP (x, 1)) == MULT) + if (GET_CODE (XEXP (x, 1)) == MULT + || GET_CODE (XEXP (x, 1)) == ASHIFT) { COPY_ONCE (x); XEXP (x, 1) = force_operand (XEXP (x, 1), 0); @@ -2069,16 +2071,29 @@ m68k_decompose_index (rtx x, bool strict_p, struct m68k_address *address) /* Check for a scale factor. */ scale = 1; - if ((TARGET_68020 || TARGET_COLDFIRE) - && GET_CODE (x) == MULT - && GET_CODE (XEXP (x, 1)) == CONST_INT - && (INTVAL (XEXP (x, 1)) == 2 - || INTVAL (XEXP (x, 1)) == 4 - || (INTVAL (XEXP (x, 1)) == 8 - && (TARGET_COLDFIRE_FPU || !TARGET_COLDFIRE)))) + if (TARGET_68020 || TARGET_COLDFIRE) { - scale = INTVAL (XEXP (x, 1)); - x = XEXP (x, 0); + if (GET_CODE (x) == MULT + && GET_CODE (XEXP (x, 1)) == CONST_INT + && (INTVAL (XEXP (x, 1)) == 2 + || INTVAL (XEXP (x, 1)) == 4 + || (INTVAL (XEXP (x, 1)) == 8 + && (TARGET_COLDFIRE_FPU || !TARGET_COLDFIRE)))) + { + scale = INTVAL (XEXP (x, 1)); + x = XEXP (x, 0); + } + /* LRA uses ASHIFT instead of MULT outside of MEM. */ + else if (GET_CODE (x) == ASHIFT + && GET_CODE (XEXP (x, 1)) == CONST_INT + && (INTVAL (XEXP (x, 1)) == 1 + || INTVAL (XEXP (x, 1)) == 2 + || (INTVAL (XEXP (x, 1)) == 3 + && (TARGET_COLDFIRE_FPU || !TARGET_COLDFIRE)))) + { + scale = 1 << INTVAL (XEXP (x, 1)); + x = XEXP (x, 0); + } } /* Check for a word extension. */ @@ -2246,8 +2261,10 @@ m68k_decompose_address (machine_mode mode, rtx x, ??? do_tablejump creates these addresses before placing the target label, so we have to assume that unplaced labels are jump table references. It seems unlikely that we would ever generate indexed - accesses to unplaced labels in other cases. */ + accesses to unplaced labels in other cases. Do not accept it in + PIC mode, since the label address will need to be loaded from memory. */ if (GET_CODE (x) == PLUS + && !flag_pic && m68k_jump_table_ref_p (XEXP (x, 1)) && m68k_decompose_index (XEXP (x, 0), strict_p, address)) { @@ -3068,12 +3085,17 @@ m68k_rtx_costs (rtx x, machine_mode mode, int outer_code, /* An lea costs about three times as much as a simple add. */ if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG - && GET_CODE (XEXP (x, 0)) == MULT - && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG - && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT - && (INTVAL (XEXP (XEXP (x, 0), 1)) == 2 - || INTVAL (XEXP (XEXP (x, 0), 1)) == 4 - || INTVAL (XEXP (XEXP (x, 0), 1)) == 8)) + && ((GET_CODE (XEXP (x, 0)) == MULT + && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && (INTVAL (XEXP (XEXP (x, 0), 1)) == 2 + || INTVAL (XEXP (XEXP (x, 0), 1)) == 4 + || INTVAL (XEXP (XEXP (x, 0), 1)) == 8)) + || (GET_CODE (XEXP (x, 0)) == ASHIFT + && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && ((unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) + <= 3)))) { /* lea an@(dx:l:i),am */ *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 2 : 3);