From patchwork Wed Jan 17 18:21:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1887595 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.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=F/HBuhoE; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=VTzD4uiu; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=hWbu/uEH; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=p47fEKsr; 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 4TFZ3S4vnKz23f1 for ; Thu, 18 Jan 2024 05:22:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89F263858C56 for ; Wed, 17 Jan 2024 18:22:10 +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 08FED3858CDB for ; Wed, 17 Jan 2024 18:21:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08FED3858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 08FED3858CDB 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=1705515712; cv=none; b=aIg+FTipmnHL/f51YH4cdi1YlS/DeS9iYAb5UfDLIwhJRtVesPsu6cLCKoBeuPrLi8IadfEuW2+SfhPvYuZ1drcNK75SF2zGvzcDO9liR7ItslkkC5+CWSpgbISALzx8u2Nd2Oo4C6xKu3HG/BLA8MPd+2YUy/TM2Bgabmc5358= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705515712; c=relaxed/simple; bh=LP1/V87coz/B1H53DjPvb3tHQZ8cTYSf7TdskHxUZN0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=ZqVQ+VlViG4pUXslMmMB93CzUDgp7mURBgY+o7QmwZkd+XgWapz0jxp6fzMgsLdigW/h9gEEe3j0/AZPdovDjmYWx84O9KWHjdI4eYYTYYqprXs55KwIWrj1Ih2TO1MaKEZt5fqH1vzPnNeAeDT5xu1qAw51P636ZBe8x7JWBcg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.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 smtp-out2.suse.de (Postfix) with ESMTPS id D6C181FCE0; Wed, 17 Jan 2024 18:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705515710; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eWvKqBPki5s2APyg5UsjIVltDztIRgudvWalEnsxjZs=; b=F/HBuhoEHYVH6ObTRSO4nxLLbeO5bbiuxx3UwOcpsfqelfVebIEKctxW8CQh08HSLxbZDm /lp7xzttY2bGdTdFi6v5XNPJgSgPU342PJdr5kizwCoFqbztsEm/p+IkAM+FpQnH8u2bAE PVJ55QAxSZLW3NwwcVGOmfd1Txu1ZRY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705515710; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eWvKqBPki5s2APyg5UsjIVltDztIRgudvWalEnsxjZs=; b=VTzD4uiuoAz7cEM4sBgeCEg27BekoariN8hZDgD5O7Gx0eG3fzKoAGj/ZiCIMVOSFXTqo8 893oehA9hf7xfCCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1705515709; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eWvKqBPki5s2APyg5UsjIVltDztIRgudvWalEnsxjZs=; b=hWbu/uEHkdT05bJJ2ZJwM+K+SWegTSjD/NRhRM+IjuEfIBmn7FnyRlDtPtUj2ry8iKlUTq CZbD00hZXrlYpb4hN4sPaPLC9SR2AXc5dy2EKjGLHcv6Jcp29y9UP1y55K1NZUWxmgXT3v 9e5pHxvrs77LytwehUFsPXbfCB0dHos= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1705515709; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=eWvKqBPki5s2APyg5UsjIVltDztIRgudvWalEnsxjZs=; b=p47fEKsrIpJSdBZUFeAjrBHu2zXg8ewx+Z3AhEOxyCU6yAF79u0ZGz/EWtnOv3UwUe3l9o 4S+goa4XzYV0UcDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D14C413751; Wed, 17 Jan 2024 18:21:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id /cAUM70aqGXLTwAAD6G6ig (envelope-from ); Wed, 17 Jan 2024 18:21:49 +0000 From: Martin Jambor To: GCC Patches Cc: Richard Biener Subject: [PATCH] sra: Disqualify bases of operands of asm gotos User-Agent: Notmuch/0.38.1 (https://notmuchmail.org) Emacs/29.1 (x86_64-suse-linux-gnu) Date: Wed, 17 Jan 2024 19:21:49 +0100 Message-ID: MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; TO_DN_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; INVALID_MSGID(1.70)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Score: -0.90 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, INVALID_MSGID, 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 Hi, PR 110422 shows that SRA can ICE assuming there is a single edge outgoing from a block terminated with an asm goto. We need that for BB-terminating statements so that any adjustments they make to the aggregates can be copied over to their replacements. Because we can't have that after ASM gotos, we need to punt. Bootstrapped and tested on x86_64-linux, OK for master? It will need some tweaking for release branches, is it in principle OK for them too (after testing)? Thanks, Martin gcc/ChangeLog: 2024-01-17 Martin Jambor PR tree-optimization/110422 * tree-sra.cc (scan_function): Disqualify bases of operands of asm gotos. gcc/testsuite/ChangeLog: 2024-01-17 Martin Jambor PR tree-optimization/110422 * gcc.dg/torture/pr110422.c: New test. --- gcc/testsuite/gcc.dg/torture/pr110422.c | 10 +++++++++ gcc/tree-sra.cc | 29 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr110422.c diff --git a/gcc/testsuite/gcc.dg/torture/pr110422.c b/gcc/testsuite/gcc.dg/torture/pr110422.c new file mode 100644 index 00000000000..2e171a7a19e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110422.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ + +struct T { int x; }; +int foo(void) { + struct T v; + asm goto("" : "+r"(v.x) : : : lab); + return 0; +lab: + return -5; +} diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index 6a1141b7377..f8e71ec48b9 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -1559,15 +1559,32 @@ scan_function (void) case GIMPLE_ASM: { gasm *asm_stmt = as_a (stmt); - for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++) + if (stmt_ends_bb_p (asm_stmt) + && !single_succ_p (gimple_bb (asm_stmt))) { - t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i)); - ret |= build_access_from_expr (t, asm_stmt, false); + for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++) + { + t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i)); + disqualify_base_of_expr (t, "OP of asm goto."); + } + for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++) + { + t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i)); + disqualify_base_of_expr (t, "OP of asm goto."); + } } - for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++) + else { - t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i)); - ret |= build_access_from_expr (t, asm_stmt, true); + for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++) + { + t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i)); + ret |= build_access_from_expr (t, asm_stmt, false); + } + for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++) + { + t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i)); + ret |= build_access_from_expr (t, asm_stmt, true); + } } } break;