From patchwork Tue Jun 11 11:20:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1946256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=it2iwwHc; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=MwHkPQZV; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=it2iwwHc; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=MwHkPQZV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Vz5pV0Dggz20KL for ; Tue, 11 Jun 2024 21:21:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A81F9385DC20 for ; Tue, 11 Jun 2024 11:21:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 4F51C3858C48 for ; Tue, 11 Jun 2024 11:20:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F51C3858C48 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4F51C3858C48 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718104854; cv=none; b=A9vFPyRXaTkiYfvDId+Vk25QBNvTzYG1hKHcJ3wVhg2sxh3lP55z9+4sbd/wXD5Me9mpF690QZJ+FZPcxpmL8qc/EccHCn7kSkfzm7sGKtN5uzpUsS4Op20S7SFlNnoX8Zv1B6UPJeIoaYQU8Qhw4d8xJZ4yx/obSKkutr3HZ+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718104854; c=relaxed/simple; bh=pc3KHj7aBFOAsHYUs6cVMMynM/NeYkvaI1/UIOH2tU8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=YBG+mOIXETc5OLsrY3I32aoLFuVC7WoFttTabb48/vGavqe7/hUdrDOEzTt0Geakkx485azFo1wGsRPqcKA0olktEZgo105hBbM25KSg5mPHpj3FQVTafBg+7kChtpR/p965UUAnjv4mCnxgcZMXrz9GeNoTjdztrQN1qXkk46k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 451A520696; Tue, 11 Jun 2024 11:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718104850; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=yMZrl7SE+NJwm7xtX6tjTsYyTCGbfwbz2BOYUW9O/98=; b=it2iwwHcRDKMZupTLGSMu9mK2llRBJ2yHV3bSOkpB2ew47/po7J+lMVYROL0E4IRqGj/Yw KP2BLz+FEw1QamwM+eIV57wViyVynNpbhT/hTJGVK3Wkt1e8ioHOyjwX+wMH9WF4/7Pb7H CutVIPMgGv/817bSYHVYXCBHs/9iQTI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718104850; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=yMZrl7SE+NJwm7xtX6tjTsYyTCGbfwbz2BOYUW9O/98=; b=MwHkPQZVjfEkjuUyMsP/XYEKI/mE4wT5tY7xh8Mh4bAZJ1BwBjcg3mqyYMubiX8wvjeXBh cXh5vMqeRMapY3BQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718104850; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=yMZrl7SE+NJwm7xtX6tjTsYyTCGbfwbz2BOYUW9O/98=; b=it2iwwHcRDKMZupTLGSMu9mK2llRBJ2yHV3bSOkpB2ew47/po7J+lMVYROL0E4IRqGj/Yw KP2BLz+FEw1QamwM+eIV57wViyVynNpbhT/hTJGVK3Wkt1e8ioHOyjwX+wMH9WF4/7Pb7H CutVIPMgGv/817bSYHVYXCBHs/9iQTI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718104850; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=yMZrl7SE+NJwm7xtX6tjTsYyTCGbfwbz2BOYUW9O/98=; b=MwHkPQZVjfEkjuUyMsP/XYEKI/mE4wT5tY7xh8Mh4bAZJ1BwBjcg3mqyYMubiX8wvjeXBh cXh5vMqeRMapY3BQ== Date: Tue, 11 Jun 2024 13:20:50 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] middle-end/115426 - wrong gimplification of "rm" asm output operand MIME-Version: 1.0 X-Spam-Score: -1.74 X-Spam-Level: X-Spamd-Result: default: False [-1.74 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.94)[-0.943]; NEURAL_HAM_SHORT(-0.19)[-0.966]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[] X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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 Message-Id: <20240611112116.A81F9385DC20@sourceware.org> When the operand is gimplified to an extract of a register or a register we have to disallow memory as we otherwise fail to gimplify it properly. Instead of __asm__("" : "=rm" __imag ); we want __asm__("" : "=rm" D.2772); _1 = REALPART_EXPR ; r = COMPLEX_EXPR <_1, D.2772>; otherwise SSA rewrite will fail and generate wrong code with 'r' left bare in the asm output. Bootstrap and regtest in progress on x86_64-unknown-linux-gnu. I've made the testcase hopefully generic enough (the bug used =X which I'm not sure is portable - I've used _Complex int so 'r' has a chance to work). OK? Thanks, Richard. PR middle-end/115426 * gimplify.cc (gimplify_asm_expr): Handle "rm" output constraint gimplified to a register (operation). * gcc.dg/pr115426.c: New testcase. --- gcc/gimplify.cc | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/pr115426.c | 9 +++++++++ 2 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr115426.c diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 04875e8df29..450be45422f 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -7044,6 +7044,22 @@ gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) ret = tret; } + /* If the gimplified operand is a register we do not allow memory. */ + if (allows_mem + && (is_gimple_reg (TREE_VALUE (link)) + || (handled_component_p (TREE_VALUE (link)) + && is_gimple_reg (TREE_OPERAND (TREE_VALUE (link), 0))))) + { + if (allows_reg) + allows_mem = 0; + else + { + error ("impossible constraint in %"); + error ("non-memory output %d must stay in memory", i); + return GS_ERROR; + } + } + /* If the constraint does not allow memory make sure we gimplify it to a register if it is not already but its base is. This happens for complex and vector components. */ diff --git a/gcc/testsuite/gcc.dg/pr115426.c b/gcc/testsuite/gcc.dg/pr115426.c new file mode 100644 index 00000000000..8432f102992 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr115426.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu11" } */ + +_Complex int fcs() +{ + _Complex int r; + __asm__("" : "=rm" (__imag__ r)); + return r; +}