From patchwork Tue May 25 23:31:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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@gcc.gnu.org; receiver=) Authentication-Results: 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=f5hfRzvV; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVj36Nhxz9sCD for ; Wed, 26 May 2021 09:31:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D68A4393A430; Tue, 25 May 2021 23:31:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D68A4393A430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985509; bh=9DBMqujEvJ0DafMHgPTIgriRu7O6TdGsIy+bkj86d5I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=f5hfRzvVqTk6NMcNOSOvL8vA242Img6gwwf/aglrfNqf7TfmPbmiNrSSi9TKqHQ8f FOXihib1Tq7+aeiWwzwEH9bIOjxWNZh75ixr9aGmgPPYZL9imts2JTnvoR2SkfH6Au TG2PTDl3nUiGCe8wCIR6gOUD9vm02l1uYTCv0AtE= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 9ED1F385803D for ; Tue, 25 May 2021 23:31:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9ED1F385803D Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-0FDM7A4jO3ybxneDhe2pWg-1; Tue, 25 May 2021 19:31:44 -0400 X-MC-Unique: 0FDM7A4jO3ybxneDhe2pWg-1 Received: by mail-qk1-f200.google.com with SMTP id b203-20020a3767d40000b02903a6207bfef5so15378721qkc.1 for ; Tue, 25 May 2021 16:31:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=9DBMqujEvJ0DafMHgPTIgriRu7O6TdGsIy+bkj86d5I=; b=Q8OaRCVH8fNpSbz8DyfIF3gudrt5HiwWH4CNE05P0wxDTxjLxKypiZHgEZ4DAaDF4A sDnEE4bMovyOyAVSfOeeE9UtrhAKDgg8luWMVTDnVi5WVXniDl+S5A5LtETITnaq+uLp 7zj3IvdQmLWdvm13CY/x3pEtUjP7/EnSdUFxhYlw0STBBo5qYkGqHfS2uXkf3OcprCM3 EN7frL8zPrSj8bMMDeYpMYvXbEVhAUGE2uQ32/hjfrqUfdsZonYWn7ysulQKtgXhM+yN RLnp53IojXSzibwMWnvctbVjANNnAnBv+HgYjwNjrAQBU2I+GL474B1Vmwdqlr486Kt5 HTXQ== X-Gm-Message-State: AOAM5339Wq8Me+vTooDH5QaEQ9SpOxADuhBOTo3nsMJUt0joFuC3h5Qq RL4nXSHg4xTf0ycDfauZsEatCKymRsMdk0eMDopmLqRq54Knt2S1AflfHQivroDm5kRO6C/s3VS uXfb5qHoCG+5ZR8S+wQ== X-Received: by 2002:a05:622a:1489:: with SMTP id t9mr6770653qtx.191.1621985503763; Tue, 25 May 2021 16:31:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt5sid+5UGV+39Fw5CMVp7EXvLi+/OnuwGkp0FMdDj7owKA0dkOnoynAW7wOpgLWnQIeFEmA== X-Received: by 2002:a05:622a:1489:: with SMTP id t9mr6770646qtx.191.1621985503624; Tue, 25 May 2021 16:31:43 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id t21sm86376qkg.22.2021.05.25.16.31.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:31:43 -0700 (PDT) To: gcc-patches Subject: [PATCH 8/8] Remove the logical stmt cache for now. Message-ID: <94f38552-f3ab-4694-714c-71a152de7098@redhat.com> Date: Tue, 25 May 2021 19:31:42 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" We added the logical stmt depth limit back in January I think, and the logical stmt cache is not currently in use.   This patch removes that code so it doesn't have too be maintained thru these changes. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From a6e94287d31525b3ad0963ad22a92e9f3dbcd3cf Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 14:59:54 -0400 Subject: [PATCH 8/8] Remove the logical stmt cache for now. With the depth limiting, we are not currently using the logical stmt cache. * gimple-range-gori.cc (class logical_stmt_cache): Delete (logical_stmt_cache::logical_stmt_cache ): Delete. (logical_stmt_cache::~logical_stmt_cache): Delete. (logical_stmt_cache::cache_entry::dump): Delete. (logical_stmt_cache::get_range): Delete. (logical_stmt_cache::cached_name ): Delete. (logical_stmt_cache::same_cached_name): Delete. (logical_stmt_cache::cacheable_p): Delete. (logical_stmt_cache::slot_diagnostics ): Delete. (logical_stmt_cache::dump): Delete. (gori_compute_cache::gori_compute_cache): Delete. (gori_compute_cache::~gori_compute_cache): Delete. (gori_compute_cache::compute_operand_range): Delete. (gori_compute_cache::cache_stmt): Delete. * gimple-range-gori.h (gori_compute::compute_operand_range): Remove virtual. (class gori_compute_cache): Delete. --- gcc/gimple-range-gori.cc | 311 --------------------------------------- gcc/gimple-range-gori.h | 31 +--- 2 files changed, 2 insertions(+), 340 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 1a4ae45c986..a4c4bf507ba 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -1160,314 +1160,3 @@ gori_export_iterator::get_name () } return NULL_TREE; } - - -// -------------------------------------------------------------------------- - -// Cache for SSAs that appear on the RHS of a boolean assignment. -// -// Boolean assignments of logical expressions (i.e. LHS = j_5 > 999) -// have SSA operands whose range depend on the LHS of the assigment. -// That is, the range of j_5 when LHS is true is different than when -// LHS is false. -// -// This class caches the TRUE/FALSE ranges of such SSAs to avoid -// recomputing. - -class logical_stmt_cache -{ -public: - logical_stmt_cache (); - ~logical_stmt_cache (); - void set_range (tree lhs, tree name, const tf_range &); - bool get_range (tf_range &r, tree lhs, tree name) const; - bool cacheable_p (gimple *, const irange *lhs_range = NULL) const; - void dump (FILE *, gimple *stmt) const; - tree same_cached_name (tree lhs1, tree lh2) const; -private: - tree cached_name (tree lhs) const; - void slot_diagnostics (tree lhs, const tf_range &range) const; - struct cache_entry - { - cache_entry (tree name, const irange &t_range, const irange &f_range); - void dump (FILE *out) const; - tree name; - tf_range range; - }; - vec m_ssa_cache; -}; - -logical_stmt_cache::cache_entry::cache_entry (tree name, - const irange &t_range, - const irange &f_range) - : name (name), range (t_range, f_range) -{ -} - -logical_stmt_cache::logical_stmt_cache () -{ - m_ssa_cache.create (num_ssa_names + num_ssa_names / 10); - m_ssa_cache.safe_grow_cleared (num_ssa_names); -} - -logical_stmt_cache::~logical_stmt_cache () -{ - for (unsigned i = 0; i < m_ssa_cache.length (); ++i) - if (m_ssa_cache[i]) - delete m_ssa_cache[i]; - m_ssa_cache.release (); -} - -// Dump cache_entry to OUT. - -void -logical_stmt_cache::cache_entry::dump (FILE *out) const -{ - fprintf (out, "name="); - print_generic_expr (out, name, TDF_SLIM); - fprintf (out, " "); - range.true_range.dump (out); - fprintf (out, ", "); - range.false_range.dump (out); - fprintf (out, "\n"); -} - -// Update range for cache entry of NAME as it appears in the defining -// statement of LHS. - -void -logical_stmt_cache::set_range (tree lhs, tree name, const tf_range &range) -{ - unsigned version = SSA_NAME_VERSION (lhs); - if (version >= m_ssa_cache.length ()) - m_ssa_cache.safe_grow_cleared (num_ssa_names + num_ssa_names / 10); - - cache_entry *slot = m_ssa_cache[version]; - slot_diagnostics (lhs, range); - if (slot) - { - // The IL must have changed. Update the carried SSA name for - // consistency. Testcase is libgomp.fortran/doacross1.f90. - if (slot->name != name) - slot->name = name; - return; - } - m_ssa_cache[version] - = new cache_entry (name, range.true_range, range.false_range); -} - -// If there is a cached entry of NAME, set it in R and return TRUE, -// otherwise return FALSE. LHS is the defining statement where NAME -// appeared. - -bool -logical_stmt_cache::get_range (tf_range &r, tree lhs, tree name) const -{ - gcc_checking_assert (cacheable_p (SSA_NAME_DEF_STMT (lhs))); - if (cached_name (lhs) == name) - { - unsigned version = SSA_NAME_VERSION (lhs); - if (m_ssa_cache[version]) - { - r = m_ssa_cache[version]->range; - return true; - } - } - return false; -} - -// If the defining statement of LHS is in the cache, return the SSA -// operand being cached. That is, return SSA for LHS = SSA .RELOP. OP2. - -tree -logical_stmt_cache::cached_name (tree lhs) const -{ - unsigned version = SSA_NAME_VERSION (lhs); - - if (version >= m_ssa_cache.length ()) - return NULL; - - if (m_ssa_cache[version]) - return m_ssa_cache[version]->name; - return NULL; -} - -// Return TRUE if the cached name for LHS1 is the same as the -// cached name for LHS2. - -tree -logical_stmt_cache::same_cached_name (tree lhs1, tree lhs2) const -{ - tree name = cached_name (lhs1); - if (name && name == cached_name (lhs2)) - return name; - return NULL; -} - -// Return TRUE if STMT is a statement we are interested in caching. -// LHS_RANGE is any known range for the LHS of STMT. - -bool -logical_stmt_cache::cacheable_p (gimple *stmt, const irange *lhs_range) const -{ - if (gimple_code (stmt) == GIMPLE_ASSIGN - && types_compatible_p (TREE_TYPE (gimple_assign_lhs (stmt)), - boolean_type_node) - && TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME) - { - switch (gimple_expr_code (stmt)) - { - case TRUTH_AND_EXPR: - case BIT_AND_EXPR: - case TRUTH_OR_EXPR: - case BIT_IOR_EXPR: - return !lhs_range || range_is_either_true_or_false (*lhs_range); - default: - return false; - } - } - return false; -} - -// Output debugging diagnostics for the cache entry for LHS. RANGE is -// the new range that is being cached. - -void -logical_stmt_cache::slot_diagnostics (tree lhs, const tf_range &range) const -{ - gimple *stmt = SSA_NAME_DEF_STMT (lhs); - unsigned version = SSA_NAME_VERSION (lhs); - cache_entry *slot = m_ssa_cache[version]; - - if (!slot) - { - if (DEBUG_RANGE_CACHE) - { - fprintf (dump_file ? dump_file : stderr, "registering range for: "); - dump (dump_file ? dump_file : stderr, stmt); - } - return; - } - if (DEBUG_RANGE_CACHE) - fprintf (dump_file ? dump_file : stderr, - "reusing range for SSA #%d\n", version); - if (CHECKING_P && (slot->range.true_range != range.true_range - || slot->range.false_range != range.false_range)) - { - fprintf (stderr, "FATAL: range altered for cached: "); - dump (stderr, stmt); - fprintf (stderr, "Attempt to change to:\n"); - fprintf (stderr, "TRUE="); - range.true_range.dump (stderr); - fprintf (stderr, ", FALSE="); - range.false_range.dump (stderr); - fprintf (stderr, "\n"); - gcc_unreachable (); - } -} - -// Dump the cache information for STMT. - -void -logical_stmt_cache::dump (FILE *out, gimple *stmt) const -{ - tree lhs = gimple_assign_lhs (stmt); - cache_entry *entry = m_ssa_cache[SSA_NAME_VERSION (lhs)]; - - print_gimple_stmt (out, stmt, 0, TDF_SLIM); - if (entry) - { - fprintf (out, "\tname = "); - print_generic_expr (out, entry->name); - fprintf (out, " lhs(%d)= ", SSA_NAME_VERSION (lhs)); - print_generic_expr (out, lhs); - fprintf (out, "\n\tTRUE="); - entry->range.true_range.dump (out); - fprintf (out, ", FALSE="); - entry->range.false_range.dump (out); - fprintf (out, "\n"); - } - else - fprintf (out, "[EMPTY]\n"); -} - -gori_compute_cache::gori_compute_cache () -{ - m_cache = new logical_stmt_cache; -} - -gori_compute_cache::~gori_compute_cache () -{ - delete m_cache; -} - -// Caching version of compute_operand_range. If NAME, as it appears -// in STMT, has already been cached return it from the cache, -// otherwise compute the operand range as normal and cache it. - -bool -gori_compute_cache::compute_operand_range (irange &r, gimple *stmt, - const irange &lhs_range, tree name) -{ - bool cacheable = m_cache->cacheable_p (stmt, &lhs_range); - if (cacheable) - { - tree lhs = gimple_assign_lhs (stmt); - tf_range range; - if (m_cache->get_range (range, lhs, name)) - { - if (lhs_range.zero_p ()) - r = range.false_range; - else - r = range.true_range; - return true; - } - } - if (super::compute_operand_range (r, stmt, lhs_range, name)) - { - if (cacheable) - cache_stmt (stmt); - return true; - } - return false; -} - -// Cache STMT if possible. - -void -gori_compute_cache::cache_stmt (gimple *stmt) -{ - gcc_checking_assert (m_cache->cacheable_p (stmt)); - enum tree_code code = gimple_expr_code (stmt); - tree lhs = gimple_assign_lhs (stmt); - tree op1 = gimple_range_operand1 (stmt); - tree op2 = gimple_range_operand2 (stmt); - int_range_max r_true_side, r_false_side; - - // LHS = s_5 && 999. - if (TREE_CODE (op2) == INTEGER_CST) - { - range_operator *handler = range_op_handler (code, TREE_TYPE (lhs)); - int_range_max op2_range; - expr_range_at_stmt (op2_range, op2, stmt); - tree type = TREE_TYPE (op1); - handler->op1_range (r_true_side, type, m_bool_one, op2_range); - handler->op1_range (r_false_side, type, m_bool_zero, op2_range); - m_cache->set_range (lhs, op1, tf_range (r_true_side, r_false_side)); - } - // LHS = s_5 && b_8. - else if (tree cached_name = m_cache->same_cached_name (op1, op2)) - { - tf_range op1_range, op2_range; - bool ok = m_cache->get_range (op1_range, op1, cached_name); - ok = ok && m_cache->get_range (op2_range, op2, cached_name); - ok = ok && logical_combine (r_true_side, code, m_bool_one, - op1_range, op2_range); - ok = ok && logical_combine (r_false_side, code, m_bool_zero, - op1_range, op2_range); - gcc_checking_assert (ok); - if (ok) - m_cache->set_range (lhs, cached_name, - tf_range (r_true_side, r_false_side)); - } -} diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 8a85d6a2b79..f41dee3d8e5 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -158,8 +158,8 @@ public: void dump (FILE *f); protected: virtual void ssa_range_in_bb (irange &r, tree name, basic_block bb); - virtual bool compute_operand_range (irange &r, gimple *stmt, - const irange &lhs, tree name); + bool compute_operand_range (irange &r, gimple *stmt, + const irange &lhs, tree name); void expr_range_at_stmt (irange &r, tree expr, gimple *s); bool compute_logical_operands (irange &r, gimple *stmt, @@ -217,31 +217,4 @@ protected: unsigned y; }; -// This class adds a cache to gori_computes for logical expressions. -// bool result = x && y -// requires calcuation of both X and Y for both true and false results. -// There are 4 combinations [0,0][0,0] [0,0][1,1] [1,1][0,0] and [1,1][1,1]. -// Note that each pair of possible results for X and Y are used twice, and -// the calcuation of those results are the same each time. -// -// The cache simply checks if a stmt is cachable, and if so, saves both the -// true and false results for the next time the query is made. -// -// This is used to speed up long chains of logical operations which -// quickly become exponential. - -class gori_compute_cache : public gori_compute -{ -public: - gori_compute_cache (); - ~gori_compute_cache (); -protected: - virtual bool compute_operand_range (irange &r, gimple *stmt, - const irange &lhs, tree name); -private: - void cache_stmt (gimple *); - typedef gori_compute super; - class logical_stmt_cache *m_cache; -}; - #endif // GCC_GIMPLE_RANGE_GORI_H -- 2.17.2