From patchwork Wed Mar 22 12:29:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 73400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2313777wrt; Wed, 22 Mar 2023 05:30:37 -0700 (PDT) X-Google-Smtp-Source: AK7set8Qm7Lu8hLc+BNQaHzjqOoL26r/aNWRchS5Rj1IgvzA2rXdo4I5tfM2poGIC/npaqW6u7Gb X-Received: by 2002:a17:906:46ca:b0:922:ae30:3c23 with SMTP id k10-20020a17090646ca00b00922ae303c23mr5939694ejs.18.1679488237739; Wed, 22 Mar 2023 05:30:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679488237; cv=none; d=google.com; s=arc-20160816; b=PwfEhgjdvhgi0TGCvVLkDwNAueR3RimCXGo4E6wkRGzKo7ssds0crj+JSkZz0e3VHf 66Z6zAGN12xH8HQ3EIDM8sWCshCEivvbgv9e0kI4CwmiJ1tUJyZolksEoYKCqYmFpG8x rSgpauDMYf6riNqP5WvqZAMY1yjZ7/zhlNm/XWqhHUipsNaneizUN3a2WZLrpc8ndjB8 P3cIPz2N5OaJ1hE9i/HYQisKYmO7akvUPBGf7ppVOLbrNFwAicj806TXGUaIrwzBzZqJ QJnDxx+KgU5elxJUHJyqPRgh/4c80bymWB81Mi3x8uwCeL/BQTu1jjv+CNm0CDnQX2wI xx2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=N89F5dDoglYz9eZnr5zihuGhhO2g+e8q+W35WVPjt7o=; b=VFn7DIYrzLFD+RFrxUz922aJ8fe0Mj414xCLUYFR838mUI07PELXjTUvpdQANbaGAk /KNKUkqXAfGWvLmQJfGCctlC4SEePttZ4XH7TgV9nIm8t4DLxdASRBSMdXPPGdEW/m/5 r2gb8mUfSl60b1GO51rUYOCoBqRtbJ/20ohQofLq9ghe8wA/8SA/WNJl/8GX0vcJQ1KZ c7ZEh99ELbUDdR0FHK8iYl1CDhWcKGIJb5ZT3qTb2tCXK2S4CMdp1DJf8qo7cFkZP4ma i80lI31RyTlJUfo1gf8n0h0xOLs0twr0PY/gnO6IVmnBHh9Eyadxn/D/vVMGfVssHpNC Xyrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=M5ACZbqm; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h24-20020a170906719800b009334efbad65si10263555ejk.163.2023.03.22.05.30.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 05:30:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=M5ACZbqm; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 8709B385B519 for ; Wed, 22 Mar 2023 12:30:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8709B385B519 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679488236; bh=N89F5dDoglYz9eZnr5zihuGhhO2g+e8q+W35WVPjt7o=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=M5ACZbqm1WrPPS/AlArOJ0xF7iieQlzbk5xvHCwwArj4BSBGomNXkTzZllAlDxeY8 iA0afn29XCyYXrKa50NohUvKecyy88AuJewBQ7y1N1zsyzhZ11OmuAEUKhQ7ziHnSs TYC0qZ6Jm9sMHCFx267aHlyP9wcTeiPJ6UV7xS4k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id CD0683858C52 for ; Wed, 22 Mar 2023 12:29:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD0683858C52 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7056533AD9; Wed, 22 Mar 2023 12:29:52 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 3BA412C141; Wed, 22 Mar 2023 12:29:52 +0000 (UTC) Date: Wed, 22 Mar 2023 12:29:52 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] tree-optimization/109237 - last_stmt is possibly slow User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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 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" Message-Id: <20230322123036.8709B385B519@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761071058215907901?= X-GMAIL-MSGID: =?utf-8?q?1761071058215907901?= Most uses of last_stmt are interested in control transfer stmts and for the testcase gimple_purge_dead_eh_edges shows up in the profile. But last_stmt looks past trailing debug stmts but those would be rejected by GIMPLEs verify_flow_info. The following adds possible_ctrl_stmt besides last_stmt which does not look past trailing debug stmts and adjusts gimple_purge_dead_eh_edges. I've put checking code into possible_ctrl_stmt that it will not miss a control statement if the real last stmt is a debug stmt. The alternative would be to change last_stmt, explicitely introducing last_nondebug_stmt. I remember we chickened out and made last_stmt conservative here but not anticipating the compile-time issues this creates. I count 227 last_stmt and 12 last_and_only_stmt uses. Bootstrapped and tested on x86_64-unknown-linux-gnu. Any opinions? I probably lean towards s/last_stmt/last_nondebug_stmt/ in next stage1 and then adding last_stmt and changing some uses back - through for maintainance that's going to be a nightmare (or maybe not, a "wrong" last_stmt should be safe to backport and a last_nondebug_stmt will fail to build). Richard. PR tree-optimization/109237 * tree-cfg.h (possible_ctrl_stmt): New function returning the last stmt not skipping debug stmts. (gimple_purge_dead_eh_edges): Use it. --- gcc/tree-cfg.cc | 22 +++++++++++++++++++++- gcc/tree-cfg.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index a9fcc7fd050..e167596209b 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -2947,6 +2947,26 @@ first_non_label_stmt (basic_block bb) return !gsi_end_p (i) ? gsi_stmt (i) : NULL; } +/* Return the last statement of a basic block BB that's possibly control + altering. Compared to last_stmt this will return a debug stmt if that + is the last stmt. */ + +gimple * +possible_ctrl_stmt (basic_block bb) +{ + gimple_stmt_iterator i = gsi_last_bb (bb); + if (gsi_end_p (i)) + return NULL; + if (flag_checking && is_gimple_debug (gsi_stmt (i))) + { + /* Verify that if the real last stmt is a debug stmt the + last non-debug stmt isn't control altering. */ + gimple *last = last_stmt (bb); + gcc_assert (!last || !stmt_ends_bb_p (last)); + } + return gsi_stmt (i); +} + /* Return the last statement in basic block BB. */ gimple * @@ -8990,7 +9010,7 @@ gimple_purge_dead_eh_edges (basic_block bb) bool changed = false; edge e; edge_iterator ei; - gimple *stmt = last_stmt (bb); + gimple *stmt = possible_ctrl_stmt (bb); if (stmt && stmt_can_throw_internal (cfun, stmt)) return false; diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h index 9b56a68fe9d..7c6a9a4f16b 100644 --- a/gcc/tree-cfg.h +++ b/gcc/tree-cfg.h @@ -61,6 +61,7 @@ extern bool assert_unreachable_fallthru_edge_p (edge); extern void delete_tree_cfg_annotations (function *); extern gphi *get_virtual_phi (basic_block); extern gimple *first_stmt (basic_block); +extern gimple *possible_ctrl_stmt (basic_block); extern gimple *last_stmt (basic_block); extern gimple *last_and_only_stmt (basic_block); extern bool verify_gimple_in_seq (gimple_seq, bool = true);