From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id C59923857831 for ; Wed, 19 Oct 2022 08:55:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C59923857831 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A8B2620382 for ; Wed, 19 Oct 2022 08:55:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666169730; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=TNVUM5W8FJ5SxCmhUJAWHGZIo+3qm5zKx1VSblXqlRE=; b=xZ6COzlHekgZ4UhegBQwi2j/DmuHxK0al82ABdE+0Cih4sJvlYqqMoGqvk73d4YBQ0/cxV Jj4KpeqxFos5NWxFsp0lCizqniEUVQmxWbr0ww5pR6AM95UbdVgITH65B6FACQpuwc2BZE MNRahhltO0vAB4zZgFrbyOWYJjfpgto= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666169730; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=TNVUM5W8FJ5SxCmhUJAWHGZIo+3qm5zKx1VSblXqlRE=; b=h06Y8uryTIxk2IlPUvplalstQk6mSNAGnbzrJakrvdk09Od48lzZMLufb4N0DyajMETtyY tG05+zoQsPJSsFAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9691513345 for ; Wed, 19 Oct 2022 08:55:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cPmdI4K7T2O+bwAAMHmgww (envelope-from ) for ; Wed, 19 Oct 2022 08:55:30 +0000 Date: Wed, 19 Oct 2022 10:55:30 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106781 - adjust cgraph lhs removal MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20221019085530.9691513345@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP 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: The following matches up the cgraph code removing LHS of a noreturn call with what fixup_noreturn_call does which gets along without inserting a definition, fixing the ICE resulting from having no place to actually insert that new def. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/106781 * cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee): Copy LHS removal from fixup_noreturn_call. * gcc.dg/pr106781.c: New testcase. --- gcc/cgraph.cc | 14 ++++++-------- gcc/testsuite/gcc.dg/pr106781.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr106781.c diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 0417b059965..5851b2ffc6c 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -1411,7 +1411,6 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e) { tree decl = gimple_call_fndecl (e->call_stmt); gcall *new_stmt; - gimple_stmt_iterator gsi; if (e->speculative) { @@ -1572,18 +1571,17 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e) && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (new_stmt))) || should_remove_lhs_p (lhs))) { + gimple_call_set_lhs (new_stmt, NULL_TREE); + /* We need to fix up the SSA name to avoid checking errors. */ if (TREE_CODE (lhs) == SSA_NAME) { tree var = create_tmp_reg_fn (DECL_STRUCT_FUNCTION (e->caller->decl), TREE_TYPE (lhs), NULL); - var = get_or_create_ssa_default_def - (DECL_STRUCT_FUNCTION (e->caller->decl), var); - gimple *set_stmt = gimple_build_assign (lhs, var); - gsi = gsi_for_stmt (new_stmt); - gsi_insert_before_without_update (&gsi, set_stmt, GSI_SAME_STMT); - update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), set_stmt); + SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, var); + SSA_NAME_DEF_STMT (lhs) = gimple_build_nop (); + set_ssa_default_def (DECL_STRUCT_FUNCTION (e->caller->decl), + var, lhs); } - gimple_call_set_lhs (new_stmt, NULL_TREE); update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt); } diff --git a/gcc/testsuite/gcc.dg/pr106781.c b/gcc/testsuite/gcc.dg/pr106781.c new file mode 100644 index 00000000000..339c28c41df --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106781.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wno-div-by-zero" } */ + +int n; + +__attribute__ ((noinline, returns_twice)) static int +bar (int) +{ + n /= 0; + + return n; +} + +int +foo (int x) +{ + return bar (x); +} -- 2.35.3