From patchwork Tue Aug 16 13:59:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp2022918pxh; Tue, 16 Aug 2022 07:00:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Ubn3biNfSLN3aDYZo5r2GRMaFFb5VCi0Qejzo54BTSJecpkjnYBpbQzRsaQmgcysoKoA3 X-Received: by 2002:a05:6402:27cf:b0:43f:f6a:3286 with SMTP id c15-20020a05640227cf00b0043f0f6a3286mr18837859ede.1.1660658428646; Tue, 16 Aug 2022 07:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660658428; cv=none; d=google.com; s=arc-20160816; b=UIb8Y1aIo3PKI51WoNyfmHka/YBVOh06Et98SFTi+Aow2KafF+/oE4Eu8EXtJXMTVx i4UEPV6uonrEDJy+vi2SVaftq2fy3YFFnJnDcWh35gOROk8nltft5qMKEmgCI8cN6LE9 4OGnsZaNTL+6xkZl2AG9xspKMLckwfkRGKRp0E2AERkv97QdleSjh75Da0D4YaadnZUi 1e9QEItfsVmjcSA1RymYjORqRE9dMFRDbtwait6vJF4+196xu0UCqsn/SxCu/XJwUeUx e94zsYgfJ80y9Ye+0VmVFR6vqYBDXv8Ajxd1VQN+ae3Cn5bGAi0WQs/nunvvu7Pw+ZEi PLAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=GRCkzLkXaN5bH4cJpooqZkZaxEpF4WD0uvfmJWNU4J4=; b=dFZyNY91W3zFgOSdUNG1lydAb8VG0ZZaW4N/giA2528A4FW0amqFMESc2ExPZ0o3fk sKlVh5c9e76SHEGBFbA0Vc0iE/rAf0FnagFATrLwmwtKp4lC9qrVjrBkpOpqeNQfStL+ 6pvV7CTYEF6TDHK5LDKprjrk1/FXxXeCLIY8wld4GK0RA7sYvqt2Yr9U3PsqDYFT24L0 Ln9i1PgYlBEzV2JT53fU0TTPviaT6myzLSEPrvPfJN1K9hx8XGWtxXswiT0jddnZbc9n a5pNNRzWx4mbuzrdFvDz87sqS1QHoqinlwt+/NphvY+pSYV7T96Y5F6Dtrjbve6gyk0g DAcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="iT/QfxoF"; 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 r18-20020a170906c29200b0073146c420dbsi8473800ejz.479.2022.08.16.07.00.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:00:28 -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="iT/QfxoF"; 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 773983858436 for ; Tue, 16 Aug 2022 14:00:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 773983858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660658427; bh=GRCkzLkXaN5bH4cJpooqZkZaxEpF4WD0uvfmJWNU4J4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=iT/QfxoFGv4VIYMmifFayzk1efveXdBpOfRD/wghldQHj9vQjytwKxEnXT+xoG9IP 3R5jLd38fxVFOPrjDpRfr3qCdzBATyGROhQshdbD6i7Yr7kKWJFZ8c0BVu1hEeGfs0 W1b6J/m1mCc/4tsndjAjKsZsJ5aoTDACxKM3sEHI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E188F3858C2F for ; Tue, 16 Aug 2022 13:59:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E188F3858C2F Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-256-UnYhir-COWalWa6e1HzDuw-1; Tue, 16 Aug 2022 09:59:38 -0400 X-MC-Unique: UnYhir-COWalWa6e1HzDuw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07635299E766; Tue, 16 Aug 2022 13:59:38 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B96E4492C3B; Tue, 16 Aug 2022 13:59:36 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 27GDxXoC226002 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 16 Aug 2022 15:59:33 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 27GDxXqb226001; Tue, 16 Aug 2022 15:59:33 +0200 To: Richard Biener Subject: [PATCH] Avoid further recomputations in path_range_query once path is finalized. Date: Tue, 16 Aug 2022 15:59:30 +0200 Message-Id: <20220816135930.225960-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: GCC patches 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?1741326572334131519?= X-GMAIL-MSGID: =?utf-8?q?1741326572334131519?= [Richi, I'm trying to make things more obvious for others working for the cose base. What do you think?] This makes a few things explicit to avoid misuse. First, we add a flag to differentiate between a path whose depdenency ranges are being computed, and a path that is finalized and no further calculations should be done. I've also enhanced the comments to document what queries are supported. Finally, I added some asserts to make sure range_of_expr is only used on the final conditional once the path has been finalized. Unfortunately, the forward threader builds dummy statements it passes to the path solver. Most of these don't have a BB associated with them. I've cleared the BB field for the one that still had one, to make the asserts above work. No difference in thread counts over my cc1 .ii files. gcc/ChangeLog: * gimple-range-path.cc (path_range_query::path_range_query): Initialized m_path_finalized. (path_range_query::internal_range_of_expr): Avoid further recomputations once path is finalized. Take basic_block instead of stmt as argument. (path_range_query::range_of_expr): Document. Add asserts. (path_range_query::compute_ranges): Set m_path_finalized. * gimple-range-path.h (path_range_query::internal_range_of_expr): Replace statement argument with basic block. (class path_range_query): Add m_path_finalized. * tree-ssa-threadedge.cc (jump_threader::simplify_control_stmt_condition): Clear BB field in dummy_switch. --- gcc/gimple-range-path.cc | 50 ++++++++++++++++++++++++++++++++++---- gcc/gimple-range-path.h | 7 +++++- gcc/tree-ssa-threadedge.cc | 1 + 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index c99d77dd340..a8412dd090b 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -40,7 +40,8 @@ path_range_query::path_range_query (bool resolve, gimple_ranger *ranger) : m_cache (new ssa_global_cache), m_has_cache_entry (BITMAP_ALLOC (NULL)), m_resolve (resolve), - m_alloced_ranger (!ranger) + m_alloced_ranger (!ranger), + m_path_finalized (false) { if (m_alloced_ranger) m_ranger = new gimple_ranger; @@ -159,7 +160,7 @@ path_range_query::range_on_path_entry (vrange &r, tree name) // Return the range of NAME at the end of the path being analyzed. bool -path_range_query::internal_range_of_expr (vrange &r, tree name, gimple *stmt) +path_range_query::internal_range_of_expr (vrange &r, tree name, basic_block bb) { if (!r.supports_type_p (TREE_TYPE (name))) return false; @@ -174,8 +175,16 @@ path_range_query::internal_range_of_expr (vrange &r, tree name, gimple *stmt) return true; } - if (stmt - && range_defined_in_block (r, name, gimple_bb (stmt))) + // Avoid further recomputations once the path has been finalized. + if (m_path_finalized) + { + gimple_range_global (r, name); + return true; + } + + // We're being called as part of the calculation of ranges for exit + // dependencies. Set the cache as we traverse the path top-down. + if (bb && range_defined_in_block (r, name, bb)) { if (TREE_CODE (name) == SSA_NAME) { @@ -192,10 +201,37 @@ path_range_query::internal_range_of_expr (vrange &r, tree name, gimple *stmt) return true; } +// This, as well as range_of_stmt, are the main entry points for +// making queries about a path. +// +// Once the ranges for the exit dependencies have been pre-calculated, +// the path is considered finalized, and the only valid query is +// asking the range of a NAME at the end of the path. +// +// Note that this method can also be called internally before the path +// is finalized, as part of the path traversal pre-calculating the +// ranges for exit dependencies. In this case, it may be called on +// statements that are not the final conditional as described above. + bool path_range_query::range_of_expr (vrange &r, tree name, gimple *stmt) { - if (internal_range_of_expr (r, name, stmt)) + basic_block bb = stmt ? gimple_bb (stmt) : NULL; + + // Once a path is finalized, the only valid queries are of the final + // statement in the exit block. + if (flag_checking && m_path_finalized && stmt) + { + // The forward threader may query dummy statements without a + // basic block. + if (bb) + { + gcc_assert (stmt == last_stmt (bb)); + gcc_assert (bb == exit_bb ()); + } + } + + if (internal_range_of_expr (r, name, bb)) { if (r.undefined_p ()) m_undefined_path = true; @@ -608,6 +644,7 @@ path_range_query::compute_ranges (const vec &path, set_path (path); m_undefined_path = false; + m_path_finalized = false; if (dependencies) bitmap_copy (m_exit_dependencies, dependencies); @@ -642,6 +679,7 @@ path_range_query::compute_ranges (const vec &path, move_next (); } + m_path_finalized = true; if (DEBUG_SOLVER) { @@ -730,6 +768,8 @@ jt_fur_source::query_relation (tree op1, tree op2) } // Return the range of STMT at the end of the path being analyzed. +// +// See notes in range_of_expr as to what are considered valid queries. bool path_range_query::range_of_stmt (vrange &r, gimple *stmt, tree) diff --git a/gcc/gimple-range-path.h b/gcc/gimple-range-path.h index 3cb794e34a9..61a7d0f656e 100644 --- a/gcc/gimple-range-path.h +++ b/gcc/gimple-range-path.h @@ -46,7 +46,7 @@ public: void debug (); private: - bool internal_range_of_expr (vrange &r, tree name, gimple *); + bool internal_range_of_expr (vrange &r, tree name, basic_block); bool defined_outside_path (tree name); void range_on_path_entry (vrange &r, tree name); path_oracle *get_path_oracle () { return (path_oracle *)m_oracle; } @@ -113,6 +113,11 @@ private: // True if m_ranger was allocated in this class and must be freed at // destruction. bool m_alloced_ranger; + +// Once the ranges for the exit dependencies have been pre-calculated, +// the path is considered finalized and this is set to TRUE. +// Otherwise, the path is being analyzed. + bool m_path_finalized; }; #endif // GCC_TREE_SSA_THREADSOLVER_H diff --git a/gcc/tree-ssa-threadedge.cc b/gcc/tree-ssa-threadedge.cc index e64e4f209f7..213796c10cc 100644 --- a/gcc/tree-ssa-threadedge.cc +++ b/gcc/tree-ssa-threadedge.cc @@ -451,6 +451,7 @@ jump_threader::simplify_control_stmt_condition (edge e, gimple *stmt) possible, the simplified value will be a CASE_LABEL_EXPR of the label that is proven to be taken. */ gswitch *dummy_switch = as_a (gimple_copy (stmt)); + gimple_set_bb (dummy_switch, NULL); gimple_switch_set_index (dummy_switch, cached_lhs); cached_lhs = m_simplifier->simplify (dummy_switch, stmt, e->src, m_state);