From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 620D83858D38; Wed, 3 Jan 2024 23:39:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 620D83858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 620D83858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704325180; cv=none; b=R9d7N8iuQBgIysL5EC//uV5pKaQqdQBXLU5YHGsxVBeAiNiwNbgXtD6d9bsVrKZHOhSohhOhhOkfHKZFTiqSwdb8XWFLEgGXWs5d8PzjuzH9Md/QF0QgWudnK1lC/dZsWwjeU00RymXS2Wi6MLsgDsQDLVrdZnsljPOO0nL5IFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704325180; c=relaxed/simple; bh=gB5XFYiH5AJTIWTbfyh9BZccjd5AGnXdn6DOHdsV1Do=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=R9l4G0dU9AZBkuS+114DwoJ13D3DgFEe6ESllHIB1P2UUvx1AD2mKLdWCbK6RaV0gyO5lbqYBfgdx4CrJ2tQIKiHmBY3TX8X5HbwXMlPc0JtEheyWGk6Q84imNWrlG05sLFPgcYoExhrREVTKGEff8KAYfs2B40cOkoIXOVWOcc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D67CBC15; Wed, 3 Jan 2024 15:40:24 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4F2053F5A1; Wed, 3 Jan 2024 15:39:38 -0800 (PST) From: Richard Sandiford To: YunQiang Su Mail-Followup-To: YunQiang Su ,gcc-patches@gcc.gnu.org, pinskia@gmail.com, jeffreyalaw@gmail.com, rguenther@suse.de, richard.sandiford@arm.com Cc: gcc-patches@gcc.gnu.org, pinskia@gmail.com, jeffreyalaw@gmail.com, rguenther@suse.de Subject: Re: [PATCH v3] EXPR: Emit an truncate if 31+ bits polluted for SImode References: <20231223085858.4136369-1-syq@gcc.gnu.org> Date: Wed, 03 Jan 2024 23:39:37 +0000 In-Reply-To: <20231223085858.4136369-1-syq@gcc.gnu.org> (YunQiang Su's message of "Sat, 23 Dec 2023 16:58:58 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-21.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT,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 List-Id: YunQiang Su writes: > On TRULY_NOOP_TRUNCATION_MODES_P (DImode, SImode)) == true platforms, > if 31 or above bits is polluted by an bitops, we will need an > truncate. Let's emit one, and mark let's use the same hardreg > as in and out, the RTL may like: > > (insn 21 20 24 2 (set (subreg/s/u:SI (reg/v:DI 200 [ val ]) 0) > (truncate:SI (reg/v:DI 200 [ val ]))) "../xx.c":7:29 -1 > (nil)) > > We use /s/u flags to mark it as really needed, as in > combine_simplify_rtx, this insn may be considered as truncated, > so let's skip this combination. > > gcc/ChangeLog: > PR: 104914. > * combine.cc (try_combine): Skip combine with truncate if > dest is subreg and has /u/s flags on platforms > TRULY_NOOP_TRUNCATION_MODES_P (DImode, SImode)) == true. > * expr.cc (expand_assignment): Emit a truncate insn, if > 31+ bits is polluted for SImode. > > gcc/testsuite/ChangeLog: > PR: 104914. > * gcc.target/mips/pr104914.c: New testcase. Sorry for not looking at this earlier. I've got a bit lost in the various threads, so apologies if this has been discussed already but I think the fix is: diff --git a/gcc/expr.cc b/gcc/expr.cc index 4f42c0ff487..9847eba19fe 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -6275,9 +6275,8 @@ expand_assignment (tree to, tree from, bool nontemporal) else { rtx to_rtx1 - = lowpart_subreg (subreg_unpromoted_mode (to_rtx), - SUBREG_REG (to_rtx), - subreg_promoted_mode (to_rtx)); + = convert_to_mode (subreg_unpromoted_mode (to_rtx), + SUBREG_REG (to_rtx), false); result = store_field (to_rtx1, bitsize, bitpos, bitregion_start, bitregion_end, mode1, from, get_alias_set (to), (completely untested apart from the test case). That should still produce a subreg on most targets, but generates the required trunc on MIPS. Thanks, Richard