From patchwork Thu Jul 15 12:20:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1505661 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@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=wojBkdT+; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4GQYQ56WPcz9s5R for ; Thu, 15 Jul 2021 22:21:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EA51398200E for ; Thu, 15 Jul 2021 12:21:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EA51398200E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626351689; bh=vmSlkUIAOhUje3VEip3ydcQJfKm/oIvSgcbkF0+D/9M=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wojBkdT+OduOCxJq6f75D+7d8cgGdFMCcnH0Xe7HnguN2SN+73wfCDjCyRlvPkNMV EyHyLGUffg9zNZFFVDrE5IPVBBoCS7w0XbkmNvuw3/4ijIokNlIcmHviW+vy96ZIAQ 1hnMF+TePiT1gTQwp4iEHfYm22xTmH+qG3U7/mC8= 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 EB6C63857007 for ; Thu, 15 Jul 2021 12:21:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EB6C63857007 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-QaU3yaXkNFy1VPQxgqauWQ-1; Thu, 15 Jul 2021 08:21:03 -0400 X-MC-Unique: QaU3yaXkNFy1VPQxgqauWQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B0EA803F5B for ; Thu, 15 Jul 2021 12:21:03 +0000 (UTC) Received: from abulafia.quesejoda.com (ovpn-112-155.ams2.redhat.com [10.36.112.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B04A960854; Thu, 15 Jul 2021 12:21:02 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 16FCKxBD2002071 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 15 Jul 2021 14:21:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 16FCKxJ32002070; Thu, 15 Jul 2021 14:20:59 +0200 To: GCC patches , Andrew MacLeod Subject: [PUSHED] Abstract out non_null adjustments in ranger. Date: Thu, 15 Jul 2021 14:20:54 +0200 Message-Id: <20210715122054.2002001-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 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_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" There are 4 exact copies of the non-null range adjusting code in the ranger. This patch abstracts the functionality into a separate method. As a follow-up I would like to remove the varying_p check, since I have seen incoming ranges such as [0, 0xff....ef] which are not varying, but are not-null. Removing the varying restriction catches those. Tested on x86-64 Linux. Pushed to trunk. p.s. Andrew, what are your thoughts on removing the varying_p() check as a follow-up? gcc/ChangeLog: * gimple-range-cache.cc (non_null_ref::adjust_range): New. (ranger_cache::range_of_def): Call adjust_range. (ranger_cache::entry_range): Same. * gimple-range-cache.h (non_null_ref::adjust_range): New. * gimple-range.cc (gimple_ranger::range_of_expr): Call adjust_range. (gimple_ranger::range_on_entry): Same. --- gcc/gimple-range-cache.cc | 35 ++++++++++++++++++++++++++--------- gcc/gimple-range-cache.h | 2 ++ gcc/gimple-range.cc | 8 ++------ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 98ecdbbd68e..23597ade802 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -81,6 +81,29 @@ non_null_ref::non_null_deref_p (tree name, basic_block bb, bool search_dom) return false; } +// If NAME has a non-null dereference in block BB, adjust R with the +// non-zero information from non_null_deref_p, and return TRUE. If +// SEARCH_DOM is true, non_null_deref_p should search the dominator tree. + +bool +non_null_ref::adjust_range (irange &r, tree name, basic_block bb, + bool search_dom) +{ + // Check if pointers have any non-null dereferences. Non-call + // exceptions mean we could throw in the middle of the block, so just + // punt for now on those. + if (!cfun->can_throw_non_call_exceptions + && r.varying_p () + && non_null_deref_p (name, bb, search_dom)) + { + int_range<2> nz; + nz.set_nonzero (TREE_TYPE (name)); + r.intersect (nz); + return true; + } + return false; +} + // Allocate an populate the bitmap for NAME. An ON bit for a block // index indicates there is a non-null reference in that block. In // order to populate the bitmap, a quick run of all the immediate uses @@ -857,9 +880,8 @@ ranger_cache::range_of_def (irange &r, tree name, basic_block bb) r = gimple_range_global (name); } - if (bb && r.varying_p () && m_non_null.non_null_deref_p (name, bb, false) && - !cfun->can_throw_non_call_exceptions) - r = range_nonzero (TREE_TYPE (name)); + if (bb) + m_non_null.adjust_range (r, name, bb, false); } // Get the range of NAME as it occurs on entry to block BB. @@ -878,12 +900,7 @@ ranger_cache::entry_range (irange &r, tree name, basic_block bb) if (!m_on_entry.get_bb_range (r, name, bb)) range_of_def (r, name); - // Check if pointers have any non-null dereferences. Non-call - // exceptions mean we could throw in the middle of the block, so just - // punt for now on those. - if (r.varying_p () && m_non_null.non_null_deref_p (name, bb, false) && - !cfun->can_throw_non_call_exceptions) - r = range_nonzero (TREE_TYPE (name)); + m_non_null.adjust_range (r, name, bb, false); } // Get the range of NAME as it occurs on exit from block BB. diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index ecf63dc01b3..f842e9c092a 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -34,6 +34,8 @@ public: non_null_ref (); ~non_null_ref (); bool non_null_deref_p (tree name, basic_block bb, bool search_dom = true); + bool adjust_range (irange &r, tree name, basic_block bb, + bool search_dom = true); private: vec m_nn; void process_name (tree name); diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 1851339c528..b210787d0b7 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -69,9 +69,7 @@ gimple_ranger::range_of_expr (irange &r, tree expr, gimple *stmt) if (def_stmt && gimple_bb (def_stmt) == bb) { 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)); + m_cache.m_non_null.adjust_range (r, expr, bb, true); } else // Otherwise OP comes from outside this block, use range on entry. @@ -95,9 +93,7 @@ gimple_ranger::range_on_entry (irange &r, basic_block bb, tree name) 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)); + m_cache.m_non_null.adjust_range (r, name, bb, true); } // Calculate the range for NAME at the end of block BB and return it in R.