From patchwork Wed Sep 14 12:50:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1207 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp2799604wrt; Wed, 14 Sep 2022 05:51:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR68X0rfZkucMcPV+x3mDuyXvG1s1g7szqApLtEMuAXgt2gE+yBwZIa66jz/ns7Kt6XbRpln X-Received: by 2002:a17:907:7632:b0:76f:f6e7:36cf with SMTP id jy18-20020a170907763200b0076ff6e736cfmr26723593ejc.442.1663159867627; Wed, 14 Sep 2022 05:51:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663159867; cv=none; d=google.com; s=arc-20160816; b=YrY3oBqwXoD5ZmGG9g9wsrqhrl//y14xwJ5XDhUjU+VYKh93fECMJHVRJsvOXLjcmq ZORbIRg4CUvxtu/gTUe0cnJ48yRtRCAlW7pPg6FdFm3ruN70yQ2N9FaHwTLRd2HKAxm1 vsajnzwa65ehSasZ+caLtBjVlFLo2XbnHhrvK6g2DZ0KK2vjBEV/wFFow2c1Sg0+76H5 Q5Vch9hR+j/jucuCtF0T816LfbtXQkycsuTkH8XAJJ3jJybFvNGeSgFsvI72JRVbD7nA 3Pt5b6MzliyiI+4QmBW0mRIfJClDFwGRLTFur++naQC2siokEIJ1+CFDti1OWcJUPB/B VojQ== 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=pqc9IafyOdhyLeULhh/ke5ju4n+1mrvNrEK4AF9FJ9I=; b=gMSfbaueBUmbCOhIX9YE1YJ1/BeDcaIeX7tW8/rbLC9wKV4hx0MydWnspuYMIpwRzm 94WjLKpHEJ069Un1PHiJY7+DyE14Ngt5kMANrEw3Chzv3ZnvlX/ofYEt1/gdKk67lv0n PQo3636HDowr9YwUhiCh8IQn/s+GhCLVpRirWklYoocsfLmZM+N3nAmM3MRdZg33hoMo 54sqKNjYgM0XxT3whxl8oy7ZDwmbHtgb+bR4Og8skQR+j3IQWqXxmdXOvvOmOeyOrexn yTVjS2oAjyg4lPXFSZF3YArCm9ct1J8J7npPkZJr0kaEmEdyNxehUqNcgOO5KB7bZHv6 lNIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ltMyGm7p; 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 hg2-20020a1709072cc200b0073094a56feesi10838473ejc.546.2022.09.14.05.51.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 05:51:07 -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=ltMyGm7p; 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 1B4253857BA2 for ; Wed, 14 Sep 2022 12:51:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B4253857BA2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663159863; bh=pqc9IafyOdhyLeULhh/ke5ju4n+1mrvNrEK4AF9FJ9I=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ltMyGm7ptSOkQLl2lXzFR2CWBywpRFKUGw31DQVIGa1iTI4OLRf/Z/zKAsMk3f34h mIRr0U5c02FnX41HYqwmFlnbcRIXy/1e4Tl+FOCRILy4NOjFhLvOGkdwPXBf4q2gfL xLKc24XjN2uhhQ3+yttdsMQHP8hgo9vqwCiiOgVQ= 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 [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 4AE233857B85 for ; Wed, 14 Sep 2022 12:50:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4AE233857B85 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 0372D1F978 for ; Wed, 14 Sep 2022 12:50:02 +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 E5607134B3 for ; Wed, 14 Sep 2022 12:50:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 42TfNvnNIWMaCAAAMHmgww (envelope-from ) for ; Wed, 14 Sep 2022 12:50:01 +0000 Date: Wed, 14 Sep 2022 14:50:01 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106938 - cleanup abnormal edges after inlining MIME-Version: 1.0 Message-Id: <20220914125001.E5607134B3@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.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?1743949521213008727?= X-GMAIL-MSGID: =?utf-8?q?1743949521213008727?= After inlining and IPA transforms we run fixup_cfg to fixup CFG effects in other functions. But that fails to clean abnormal edges from non-pure/const calls which might no longer be necessary when ->calls_setjmp is false. The following ensures this happens and refactors things so we call EH/abnormal cleanup only on the last stmt in a block. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/106938 * tree-cfg.cc (execute_fixup_cfg): Purge dead abnormal edges for all last stmts in a block. Do EH cleanup only on the last stmt in a block. * gcc.dg/pr106938.c: New testcase. --- gcc/testsuite/gcc.dg/pr106938.c | 36 +++++++++++++++++++++++++++++++++ gcc/tree-cfg.cc | 13 ++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr106938.c diff --git a/gcc/testsuite/gcc.dg/pr106938.c b/gcc/testsuite/gcc.dg/pr106938.c new file mode 100644 index 00000000000..7365a8c29fb --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106938.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fno-ipa-pure-const -fno-tree-ccp -Wuninitialized" } */ + +int n; + +void +undefined (void); + +__attribute__ ((returns_twice)) int +zero (void) +{ + return 0; +} + +void +bar (int) +{ + int i; + + for (i = 0; i < -1; ++i) + n = 0; +} + +__attribute__ ((simd)) void +foo (void) +{ + int uninitialized; + + undefined (); + + while (uninitialized < 1) /* { dg-warning "uninitialized" } */ + { + bar (zero ()); + ++uninitialized; + } +} diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 5cb6db337f9..48c5c4de51f 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -9828,16 +9828,12 @@ execute_fixup_cfg (void) int flags = gimple_call_flags (stmt); if (flags & (ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE)) { - if (gimple_purge_dead_abnormal_call_edges (bb)) - todo |= TODO_cleanup_cfg; - if (gimple_in_ssa_p (cfun)) { todo |= TODO_update_ssa | TODO_cleanup_cfg; update_stmt (stmt); } } - if (flags & ECF_NORETURN && fixup_noreturn_call (stmt)) todo |= TODO_cleanup_cfg; @@ -9867,10 +9863,15 @@ execute_fixup_cfg (void) } } - if (maybe_clean_eh_stmt (stmt) + gsi_next (&gsi); + } + if (gimple *last = last_stmt (bb)) + { + if (maybe_clean_eh_stmt (last) && gimple_purge_dead_eh_edges (bb)) todo |= TODO_cleanup_cfg; - gsi_next (&gsi); + if (gimple_purge_dead_abnormal_call_edges (bb)) + todo |= TODO_cleanup_cfg; } /* If we have a basic block with no successors that does not