From patchwork Tue May 25 23:30:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483797 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=Brxpgn5C; dkim-atps=neutral Received: from sourceware.org (server2.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 4FqVhF4wSzz9sCD for ; Wed, 26 May 2021 09:31:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 567613857413; Tue, 25 May 2021 23:31:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 567613857413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985466; bh=RK4ahGWIEBlunnJ2fY60/0nEFsnlVl2yTceDdiu/Mts=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Brxpgn5CpdmQf55i5cOluzSHam3cjT/Vpqhc+svxW2O2YlC0K+3tzMIAym2yDnFGr fv2vkPim1cowI1kf0BsDhaODcsF9szDM91a+gJufxL9SNO6z/EczJsyxDu1NsLsBHu FT0JirkBfikcmS0BSzTnBSwkZM5ktV1ThwkTrvu4= 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 ESMTP id 58EF5385803D for ; Tue, 25 May 2021 23:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 58EF5385803D Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-554-bIRBhL7yO_-9yWczeD_DNg-1; Tue, 25 May 2021 19:31:02 -0400 X-MC-Unique: bIRBhL7yO_-9yWczeD_DNg-1 Received: by mail-qv1-f72.google.com with SMTP id l19-20020a0ce5130000b02901b6795e3304so31988294qvm.2 for ; Tue, 25 May 2021 16:31:02 -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=RK4ahGWIEBlunnJ2fY60/0nEFsnlVl2yTceDdiu/Mts=; b=iAmAD+3Fy5lf6qRa4laj73V0b4O+8flVKW9hGp45m/3tkQ42TH/Xfzyc7yqIEdQc8i LQREJ+85Ibll+oNkZgoZeKLLnGELhNJsmlN46v9RYN8mRBBztagm2EhagZtnLY0WpcNW rex7OQFtliuMBGkLl21hAKdSrnGyOcnj5wgTQMCImoxmuAq2n3ZDuTD3zexpdNFc5kQF vWFtNUkC16NRGC7dOwI1XQYHHTGLAbokw6kGgGvQgv36kzTOsOaZIHVZ1uj1JZp1S2bk iFRzlKurYv0Xk3NDc0a7A/+uAeWGcWA+7fWcAwNygaVyCJuVtI0BB3/FYphUcTWxLD0U 2n9w== X-Gm-Message-State: AOAM532C59k2w9mdV/jh3lqls+6TRzyR+2VupuDZnPY46bcRlQ9zxW5L BYmYzkI7LBoerR40UE/bhJzKbhexnoO3rIPoH3HLd7j+Oi74T2Hz/df0KRfYUUiH+PXfj3ATU0A uiq3u+R+nNd5YtFycuA== X-Received: by 2002:a05:622a:446:: with SMTP id o6mr36001500qtx.246.1621985461474; Tue, 25 May 2021 16:31:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ6DflOZfmFxjqTjifrWmvENbN7HxB337XnrKo9c18UMmkvp8Rj5oq8Cod3grZ1trBnGhy7w== X-Received: by 2002:a05:622a:446:: with SMTP id o6mr36001494qtx.246.1621985461329; Tue, 25 May 2021 16:31:01 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id t6sm467498qkh.117.2021.05.25.16.31.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:31:00 -0700 (PDT) To: gcc-patches Subject: [PATCH 5/8] Tweak location of non-null calls. revamp ranger debug, output. Message-ID: <129c9d2a-db45-15d9-3188-ac470a785688@redhat.com> Date: Tue, 25 May 2021 19:30:59 -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=-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_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" Just some minor tweaking of the location of calls to non_null_deref_p, as well as debug output. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 35c78c6fc54721e067ed3a30ddd9184b45c5981d Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 14:41:16 -0400 Subject: [PATCH 5/8] Tweak location of non-null calls. revamp ranger debug output. range_on_entry shouldnt be checking non-null, but we sometimes should after calling it. change the debug output a bit. * gimple-range.cc (gimple_ranger::range_of_expr): Non-null should be checked only after range_of_stmt, not range_on_entry. (gimple_ranger::range_on_entry): Check for non-null in any predecessor block, if it is not already non-null. (gimple_ranger::range_on_exit): DOnt check for non-null after range on entry call. (gimple_ranger::dump_bb): New. Split from dump. (gimple_ranger::dump): Adjust. * gimple-range.h (class gimple_ranger): Adjust. --- gcc/gimple-range.cc | 149 ++++++++++++++++++++++---------------------- gcc/gimple-range.h | 1 + 2 files changed, 74 insertions(+), 76 deletions(-) diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 06e9804494b..593ddb1c3f8 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -976,23 +976,16 @@ gimple_ranger::range_of_expr (irange &r, tree expr, gimple *stmt) // If name is defined in this block, try to get an range from S. if (def_stmt && gimple_bb (def_stmt) == bb) - range_of_stmt (r, def_stmt, expr); + { + range_of_stmt (r, def_stmt, expr); + if (!cfun->can_throw_non_call_exceptions && r.varying_p () && + m_cache.m_non_null.non_null_deref_p (expr, bb)) + r = range_nonzero (TREE_TYPE (expr)); + } else // Otherwise OP comes from outside this block, use range on entry. range_on_entry (r, bb, expr); - // No range yet, see if there is a dereference in the block. - // We don't care if it's between the def and a use within a block - // because the entire block must be executed anyway. - // FIXME:?? For non-call exceptions we could have a statement throw - // which causes an early block exit. - // in which case we may need to walk from S back to the def/top of block - // to make sure the deref happens between S and there before claiming - // there is a deref. Punt for now. - if (!cfun->can_throw_non_call_exceptions && r.varying_p () && - m_cache.m_non_null.non_null_deref_p (expr, bb)) - r = range_nonzero (TREE_TYPE (expr)); - return true; } @@ -1010,6 +1003,10 @@ gimple_ranger::range_on_entry (irange &r, basic_block bb, tree name) // Now see if there is any on_entry value which may refine it. if (m_cache.block_range (entry_range, bb, name)) r.intersect (entry_range); + + if (!cfun->can_throw_non_call_exceptions && r.varying_p () && + m_cache.m_non_null.non_null_deref_p (name, bb)) + r = range_nonzero (TREE_TYPE (name)); } // Calculate the range for NAME at the end of block BB and return it in R. @@ -1032,13 +1029,7 @@ gimple_ranger::range_on_exit (irange &r, basic_block bb, tree name) if (s) range_of_expr (r, name, s); else - { - range_on_entry (r, bb, name); - // See if there was a deref in this block, if applicable - if (!cfun->can_throw_non_call_exceptions && r.varying_p () && - m_cache.m_non_null.non_null_deref_p (name, bb)) - r = range_nonzero (TREE_TYPE (name)); - } + range_on_entry (r, bb, name); gcc_checking_assert (r.undefined_p () || range_compatible_p (r.type (), TREE_TYPE (name))); } @@ -1166,80 +1157,86 @@ gimple_ranger::export_global_ranges () // Print the known table values to file F. void -gimple_ranger::dump (FILE *f) +gimple_ranger::dump_bb (FILE *f, basic_block bb) { - basic_block bb; - - FOR_EACH_BB_FN (bb, cfun) - { - unsigned x; - edge_iterator ei; - edge e; - int_range_max range; - fprintf (f, "\n=========== BB %d ============\n", bb->index); - m_cache.dump (f, bb); + unsigned x; + edge_iterator ei; + edge e; + int_range_max range; + fprintf (f, "\n=========== BB %d ============\n", bb->index); + m_cache.dump (f, bb); - dump_bb (f, bb, 4, TDF_NONE); + ::dump_bb (f, bb, 4, TDF_NONE); - // Now find any globals defined in this block. - for (x = 1; x < num_ssa_names; x++) + // Now find any globals defined in this block. + for (x = 1; x < num_ssa_names; x++) + { + tree name = ssa_name (x); + if (gimple_range_ssa_p (name) && SSA_NAME_DEF_STMT (name) && + gimple_bb (SSA_NAME_DEF_STMT (name)) == bb && + m_cache.get_global_range (range, name)) { - tree name = ssa_name (x); - if (gimple_range_ssa_p (name) && SSA_NAME_DEF_STMT (name) && - gimple_bb (SSA_NAME_DEF_STMT (name)) == bb && - m_cache.get_global_range (range, name)) + if (!range.varying_p ()) { - if (!range.varying_p ()) - { - print_generic_expr (f, name, TDF_SLIM); - fprintf (f, " : "); - range.dump (f); - fprintf (f, "\n"); - } - + print_generic_expr (f, name, TDF_SLIM); + fprintf (f, " : "); + range.dump (f); + fprintf (f, "\n"); } + } + } - // And now outgoing edges, if they define anything. - FOR_EACH_EDGE (e, ei, bb->succs) + // And now outgoing edges, if they define anything. + FOR_EACH_EDGE (e, ei, bb->succs) + { + for (x = 1; x < num_ssa_names; x++) { - for (x = 1; x < num_ssa_names; x++) + tree name = gimple_range_ssa_p (ssa_name (x)); + if (name && m_cache.outgoing_edge_range_p (range, e, name)) { - tree name = gimple_range_ssa_p (ssa_name (x)); - if (name && m_cache.outgoing_edge_range_p (range, e, name)) + gimple *s = SSA_NAME_DEF_STMT (name); + // Only print the range if this is the def block, or + // the on entry cache for either end of the edge is + // set. + if ((s && bb == gimple_bb (s)) || + m_cache.block_range (range, bb, name, false) || + m_cache.block_range (range, e->dest, name, false)) { - gimple *s = SSA_NAME_DEF_STMT (name); - // Only print the range if this is the def block, or - // the on entry cache for either end of the edge is - // set. - if ((s && bb == gimple_bb (s)) || - m_cache.block_range (range, bb, name, false) || - m_cache.block_range (range, e->dest, name, false)) + range_on_edge (range, e, name); + if (!range.varying_p ()) { - range_on_edge (range, e, name); - if (!range.varying_p ()) - { - fprintf (f, "%d->%d ", e->src->index, - e->dest->index); - char c = ' '; - if (e->flags & EDGE_TRUE_VALUE) - fprintf (f, " (T)%c", c); - else if (e->flags & EDGE_FALSE_VALUE) - fprintf (f, " (F)%c", c); - else - fprintf (f, " "); - print_generic_expr (f, name, TDF_SLIM); - fprintf(f, " : \t"); - range.dump(f); - fprintf (f, "\n"); - } + fprintf (f, "%d->%d ", e->src->index, + e->dest->index); + char c = ' '; + if (e->flags & EDGE_TRUE_VALUE) + fprintf (f, " (T)%c", c); + else if (e->flags & EDGE_FALSE_VALUE) + fprintf (f, " (F)%c", c); + else + fprintf (f, " "); + print_generic_expr (f, name, TDF_SLIM); + fprintf(f, " : \t"); + range.dump(f); + fprintf (f, "\n"); } } } } } +} + +// Print the known table values to file F. + +void +gimple_ranger::dump (FILE *f) +{ + basic_block bb; + + FOR_EACH_BB_FN (bb, cfun) + dump_bb (f, bb); - m_cache.dump (dump_file, (dump_flags & TDF_DETAILS) != 0); + m_cache.dump (f, false); } // If SCEV has any information about phi node NAME, return it as a range in R. diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index 53205066ab4..08035a53238 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -66,6 +66,7 @@ public: virtual void range_on_exit (irange &r, basic_block bb, tree name); void export_global_ranges (); void dump (FILE *f); + void dump_bb (FILE *f, basic_block bb); protected: bool fold_range_internal (irange &r, gimple *s, tree name); ranger_cache m_cache; -- 2.17.2