From patchwork Wed Oct 19 08:55:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 4605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp208194wrs; Wed, 19 Oct 2022 01:56:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4GoKhzRZGTyUVSE/SDuzKQmWG14c0QbwElFkkF++RlpRLQrhuo+tB9P9fENXAZ7LoYdiuZ X-Received: by 2002:a17:906:cc0b:b0:78d:f3b9:ab15 with SMTP id ml11-20020a170906cc0b00b0078df3b9ab15mr5782881ejb.367.1666169794426; Wed, 19 Oct 2022 01:56:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169794; cv=none; d=google.com; s=arc-20160816; b=zGuXLYk0es0Rg0X0xmaz6BxoRjwJu9ZUt9hHWky7swCPY1HUIKW0jhDtYIj3MlWB9Q CFaLMbOMXPjdY3VE6pCbcLM3c8gpJY7thZb/nrAdL3nj6X0iNGGjHiEEVr2WbN5JzoGZ /UcTzzd+ywKB3CtljJqmlADOVD91PEnp8y9bqfrM3q8/FHe+2EeyL17tlxTQ01jrmB09 +oyw66peI+cQD+NtrTrNsiUnVuMbz7197yy1gxEMbvtxHrUspeyVp909rtgrmXXzYaup cu9N0vKvSTcuhe+AGQIcYmY7pwpckR+BuwjZoUglwAzPvm3ttL1vmsNuwbSwTLTKQjmL SWLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=TNVUM5W8FJ5SxCmhUJAWHGZIo+3qm5zKx1VSblXqlRE=; b=ncx1wmEyYFPnCQvXfcgxTOhtJ1HEiJraWJn7gaPXm5Yer+8wjkEOZi1T2IIznDii9M j5UYch0p0RQELxMutQxAanNlpVcZx/h7bcJr7DxEwpzbloztervtq2EutkARqCtHHavi EDpPjbz6VkAcAQiY/fJ9fS0L3EbmmW0x9uYRQo9nbA2gVb3o7nuuAF2HLxZ0giS9Hoc3 3GJeIw6n14bevS0HszQlp5D5gyIHGshZgQh1Bbd00p8NCqafr/FnnJBpUykVbZt20d7p ADSbuOJvTeSbz0kX/aQOPhaw/N8U4PaKRLreoy9ajDLtpeDg1bo8rxPbHYxrC46QH8NJ EqhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rZLizyVp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cs11-20020a170906dc8b00b0078d38624feesi13352964ejc.133.2022.10.19.01.56.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 01:56:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rZLizyVp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 913623856954 for ; Wed, 19 Oct 2022 08:56:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 913623856954 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666169776; bh=TNVUM5W8FJ5SxCmhUJAWHGZIo+3qm5zKx1VSblXqlRE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rZLizyVpi2o8UieWVvovRByUk+cmcVJl+RJDcBrooyPDz6Eh8uoeekFr8ocjpuNgO YOqlqVmz0m3Qy4T1oS00K5Q3M1Q3WGBuGYVLBlwsmU8GismcUno881mD1ST3qYOlFz nOxMImyTONGtApbt0/hQryH3D5zcgBUYJ6I4eE2o= 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: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 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) 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) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106781 - adjust cgraph lhs removal MIME-Version: 1.0 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 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: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747105658428917909?= X-GMAIL-MSGID: =?utf-8?q?1747105658428917909?= 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); +}