From patchwork Wed May 24 21:19:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1785870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=PL8SUS5O; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QRPHC0SZSz20Pb for ; Thu, 25 May 2023 07:20:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E69EA384D193 for ; Wed, 24 May 2023 21:20:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E69EA384D193 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684963234; bh=23WmnUHFrwoYvA2oTx4PYQVO0WFaSEXi5M4OVa2UmTA=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=PL8SUS5OrA1lbOU8Al1ZsOne4YLSsTxs8GSri7VbsrEp1Kfkaw1QQEemdtoopmVUn aE57VL484iqMX4seHx8ecHSMf2Jp/PxuXUOOT/Qun3ivg9D/9LJGTFt7hqfCjbRQC0 +xIF2P2ODJqCgfO8A5pftBrgbaG0bxMGd0U1FSIs= 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 596933857343 for ; Wed, 24 May 2023 21:19:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 596933857343 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-hBeINsmePLOjXU08TB3Xeg-1; Wed, 24 May 2023 17:19:24 -0400 X-MC-Unique: hBeINsmePLOjXU08TB3Xeg-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6240a60181dso2589446d6.0 for ; Wed, 24 May 2023 14:19:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684963163; x=1687555163; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LO1Vafa56bb9ZL5nD2r3XeEA1usRx8y5+Ip5BXYQk6k=; b=WL8VCQXbK271tg+RyXA313zrhXVaGQmUKVD7ia+pv5EnupCTdwrTyLWXVIPVHz3IUz ldRxB6HeP0uWk605Bq0p4FQAXdtxTWnMTHwbZ7qi9XrSU0YfyDvsdNnyXRNleJMSRAPi yMBrNPQ16yKdbmEu1PSTbUO/tTa0LMbBxR5/y7gU4A29jLPm0NvDCCQkEZzZt8sxlAqV qhECjYkrDlLkjnaWgANnJ8b3rguQk5T2kSZHU9PMOJToxfd1Uf2edM8c+VGyWOQwO5cC ZWYG77G0yeeBcjMgmo5LcLPw2RUhjHl1SpWyzk4MLd/6yPgnnZTcTy2ZZ7lcKvFLc3c3 DHug== X-Gm-Message-State: AC+VfDxi23KFxHDNmbYF4ojCxDJIj44cCYvJEoUAwGVoCu+6AnHBLyYX +yizBvMbPqI5XEtQp2F0v8rXR5kUm9K+RxmLhqpDpJzeo/m1U+ALU/htANWjdQn5lT7F8zlS/Qb yLDPTiazw0ZPmYaGn68Iwj7GeQP/s2yQ4e1F9lKzKAKOLKyWKK7mqwS+SP9LfeREii+a+d8CzMf /mHw== X-Received: by 2002:a05:6214:29e9:b0:623:42c5:612f with SMTP id jv9-20020a05621429e900b0062342c5612fmr24039131qvb.49.1684963163197; Wed, 24 May 2023 14:19:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gDK0za9m4IcVaBU8eTpyi61XbV5Up0dJ32lSLCCnmhBO7Cjx5OZpproi6NxgG1Qs7vlTJwg== X-Received: by 2002:a05:6214:29e9:b0:623:42c5:612f with SMTP id jv9-20020a05621429e900b0062342c5612fmr24039104qvb.49.1684963162752; Wed, 24 May 2023 14:19:22 -0700 (PDT) Received: from ?IPV6:2607:fea8:51df:4200::933? ([2607:fea8:51df:4200::933]) by smtp.gmail.com with ESMTPSA id qd14-20020ad4480e000000b00625b4eb9126sm374204qvb.10.2023.05.24.14.19.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 14:19:22 -0700 (PDT) Message-ID: <5490c9c6-d4ea-a4f4-1718-238ef3caf9f5@redhat.com> Date: Wed, 24 May 2023 17:19:21 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [COMMITTED 2/4] - Make ssa_cache a range_query. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.4 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, RCVD_IN_MSPIKE_H2, 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" By having an ssa_cache inherit from a range_query, and then providing a range_of_expr routine which returns the current global value, we open up the possibility of folding statements and doing other interesting things with an ssa-cache. In particular, you can now call fold_range()  with an ssa-range cache and fold a stmt by retrieving the values which are stored in the cache. This patch also provides a ranger object with a  const_query() method which will allow access to the current global ranges ranger knows for folding.   There are times where we use get_global_range_query(), but we'd actually get more accuarte results if we have a ranger and use const_query ().    const_query should be  a superset of what get_global_range_query knows. There is 0 performance impact. Bootstraps on x86_64-pc-linux-gnu  with no regressions.  Pushed. Andrew From be6e6b93cc5d42a09a1f2be26dfdf7e3f897d296 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 24 May 2023 09:06:26 -0400 Subject: [PATCH 2/4] Make ssa_cache a range_query. By providing range_of_expr as a range_query, we can fold and do other interesting things using values from the global table. Make ranger's knonw globals available via const_query. * gimple-range-cache.cc (ssa_cache::range_of_expr): New. * gimple-range-cache.h (class ssa_cache): Inherit from range_query. (ranger_cache::const_query): New. * gimple-range.cc (gimple_ranger::const_query): New. * gimple-range.h (gimple_ranger::const_query): New prototype. --- gcc/gimple-range-cache.cc | 14 ++++++++++++++ gcc/gimple-range-cache.h | 5 ++++- gcc/gimple-range.cc | 8 ++++++++ gcc/gimple-range.h | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index f25abaffd34..52165d2405b 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -545,6 +545,20 @@ ssa_cache::~ssa_cache () delete m_range_allocator; } +// Enable a query to evaluate staements/ramnges based on picking up ranges +// from just an ssa-cache. + +bool +ssa_cache::range_of_expr (vrange &r, tree expr, gimple *stmt) +{ + if (!gimple_range_ssa_p (expr)) + return get_tree_range (r, expr, stmt); + + if (!get_range (r, expr)) + gimple_range_global (r, expr, cfun); + return true; +} + // Return TRUE if the global range of NAME has a cache entry. bool diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index 4fc98230430..afcf8d7de7b 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -52,7 +52,7 @@ private: // has been visited during this incarnation. Once the ranger evaluates // a name, it is typically not re-evaluated again. -class ssa_cache +class ssa_cache : public range_query { public: ssa_cache (); @@ -63,6 +63,8 @@ public: virtual void clear_range (tree name); virtual void clear (); void dump (FILE *f = stderr); + virtual bool range_of_expr (vrange &r, tree expr, gimple *stmt); + protected: vec m_tab; vrange_allocator *m_range_allocator; @@ -103,6 +105,7 @@ public: bool get_global_range (vrange &r, tree name) const; bool get_global_range (vrange &r, tree name, bool ¤t_p); void set_global_range (tree name, const vrange &r, bool changed = true); + range_query &const_query () { return m_globals; } void propagate_updated_value (tree name, basic_block bb); diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 4fae3f95e6a..01e62d3ff39 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -70,6 +70,14 @@ gimple_ranger::~gimple_ranger () m_stmt_list.release (); } +// Return a range_query which accesses just the known global values. + +range_query & +gimple_ranger::const_query () +{ + return m_cache.const_query (); +} + bool gimple_ranger::range_of_expr (vrange &r, tree expr, gimple *stmt) { diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index e3aa9475f5e..6587e4923ff 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -64,6 +64,7 @@ public: bool fold_stmt (gimple_stmt_iterator *gsi, tree (*) (tree)); void register_inferred_ranges (gimple *s); void register_transitive_inferred_ranges (basic_block bb); + range_query &const_query (); protected: bool fold_range_internal (vrange &r, gimple *s, tree name); void prefill_name (vrange &r, tree name); -- 2.40.1