From patchwork Tue Jan 26 01:59:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joern Wolfgang Rennecke X-Patchwork-Id: 1431461 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" header.d=riscy-ip.com header.i=@riscy-ip.com header.a=rsa-sha256 header.s=default header.b=RNmLJlqA; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DPqfs4bncz9sWD for ; Tue, 26 Jan 2021 12:59:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF107396E84F; Tue, 26 Jan 2021 01:59:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway32.websitewelcome.com (gateway32.websitewelcome.com [192.185.145.107]) by sourceware.org (Postfix) with ESMTPS id 45160385803F for ; Tue, 26 Jan 2021 01:59:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 45160385803F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=riscy-ip.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=joern.rennecke@riscy-ip.com Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 87ADB7D0896 for ; Mon, 25 Jan 2021 19:59:19 -0600 (CST) Received: from just2023.justhost.com ([173.254.28.231]) by cmsmtp with SMTP id 4DdXl5pnKuDoA4DdXlE4gT; Mon, 25 Jan 2021 19:59:19 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=riscy-ip.com; s=default; h=Content-Type:Subject:To:MIME-Version:From:Date: Message-ID:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=YOQdWzA/60QPQRR3OFpBPHLtIacbqyC1Gtyl6SylWO8=; b=RNmLJlqA0JtqWsPewDiFJO/HB3 JOAvoi0NEKKtPELHaIBYtHsJxJ9tuVnLjLQZDmBzOigB1eO1mdauYj0BCFkOgcZVoOqDUJPUIfA8L VtNDjphrqv0T5APxgLueDpfVtsWuv3AIvNfy4CcSFnPaX5J2B0ybkH6vfKT8+E7zZW1D7EVCeldf+ ahEbmXNqOsWUmu+SYWkxzC3dtH9getbYmsFzZB5By41W9JVA+75hBX7FVtqkjnXcdpVreScOczW7C TNjBbM9+08mPRX5kF6Qr6XWSSiZZh0erdoWUBf6SH7qbXmupfHzEDZsadDt6Ukx0/iqHMJdXHiur5 f0GvdQ6w==; Received: from cust213-dsl91-135-11.idnet.net ([91.135.11.213]:56474 helo=[192.168.1.129]) by just2023.justhost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1l4DdW-002brG-UF for gcc-patches@gcc.gnu.org; Mon, 25 Jan 2021 18:59:19 -0700 Message-ID: <600F7774.3060700@riscy-ip.com> Date: Tue, 26 Jan 2021 01:59:16 +0000 From: Joern Wolfgang Rennecke User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: GCC Patches Subject: RFA: avoid changing MEMs to mode with higher alignment than underlying memory X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - just2023.justhost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - riscy-ip.com X-BWhitelist: no X-Source-IP: 91.135.11.213 X-Source-L: No X-Exim-ID: 1l4DdW-002brG-UF X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: cust213-dsl91-135-11.idnet.net ([192.168.1.129]) [91.135.11.213]:56474 X-Source-Auth: joern.rennecke@riscy-ip.com X-Email-Count: 1 X-Source-Cap: cmlzY3lpcGM7cmlzY3lpcGM7anVzdDIwMjMuanVzdGhvc3QuY29t X-Local-Domain: yes X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" esirisc has a sub-target that has DImode with 4 byte alignment, and DFmode with 8 byte alignment. For code like g++.dg/torture/pr39713.C , the optimizes changes the mode of a MEM from DImode to DFmode even if the required alignment is not available. Appended is is the target-independent part of the fix. Required target changes were to make sure that (subreg:DF: (mem:DI ...)) is handled or rejected as an operandad as appropriate, and a secondary reload to a suitable register and in a suitable mode are done where needed (GENERAL_REGS in DImode in our case). Bootstrapped and regression tested in gcc version d6f1cf644c45b76a27b6a6869dedaa030e3c7570 on x86_64 GNU/Linux. 2021-01-14 Joern Rennecke * combine.c (gen_lowpart_for_combine): Reject change to MEM with mode with higher alignment than given. * expr.c (expand_expr_real_1 ): When don't discard mode of a MEM before checking alignment. For STRICT_ALIGNMENT, try to load a reg in the inner mode. * simplify-rtx.c (simplify_subreg): Reject change to MEM with mode with higher alignment than given. diff --git a/gcc/combine.c b/gcc/combine.c index 3294575..966fa4a 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -11793,6 +11793,10 @@ gen_lowpart_for_combine (machine_mode omode, rtx x) || mode_dependent_address_p (XEXP (x, 0), MEM_ADDR_SPACE (x))) goto fail; + if (GET_MODE_ALIGNMENT (omode) > GET_MODE_ALIGNMENT (imode) + && GET_MODE_ALIGNMENT (omode) > MEM_ALIGN (x)) + goto fail; + /* If we want to refer to something bigger than the original memref, generate a paradoxical subreg instead. That will force a reload of the original memref X. */ diff --git a/gcc/expr.c b/gcc/expr.c index 04ef5ad..1f0117c 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -11362,7 +11362,9 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, { if (!REG_P (op0) && !MEM_P (op0)) op0 = force_reg (GET_MODE (op0), op0); - op0 = gen_lowpart (mode, op0); + rtx tmp = gen_lowpart (mode, op0); + if (!MEM_P (tmp)) + op0 = tmp; } } /* If both types are integral, convert from one mode to the other. */ @@ -11383,6 +11385,8 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, force_const_mem for constants because we don't allow pool constants to change mode. */ tree inner_type = TREE_TYPE (treeop0); + /* ??? Should probably modify the INNER_TYPE to bigger alignemnt if + TYPE requires it. */ gcc_assert (!TREE_ADDRESSABLE (exp)); @@ -11430,6 +11434,14 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, } else if (STRICT_ALIGNMENT) { + machine_mode inner_mode = TYPE_MODE (TREE_TYPE (treeop0)); + if (GET_MODE (op0) == inner_mode + && targetm.can_change_mode_class + (inner_mode, mode, GENERAL_REGS)) + { + op0 = force_reg (inner_mode, op0); + return gen_lowpart (mode, op0); + } poly_uint64 mode_size = GET_MODE_SIZE (mode); poly_uint64 temp_size = mode_size; if (GET_MODE (op0) != BLKmode) diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 571e233..766e0d0 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -7206,6 +7206,9 @@ simplify_context::simplify_subreg (machine_mode outermode, rtx op, if (MEM_P (op) && ! mode_dependent_address_p (XEXP (op, 0), MEM_ADDR_SPACE (op)) + /* Don't imply a larger alignment than is available. */ + && (GET_MODE_ALIGNMENT (outermode) <= GET_MODE_ALIGNMENT (innermode) + || GET_MODE_ALIGNMENT (outermode) <= MEM_ALIGN (op)) /* Allow splitting of volatile memory references in case we don't have instruction to move the whole thing. */ && (! MEM_VOLATILE_P (op)