From patchwork Wed Nov 10 15:51:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 47415 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 652293857805 for ; Wed, 10 Nov 2021 15:51:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 652293857805 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636559518; bh=nzEcqXrvT51SQjetaUbTDFbqJI6dgialgeTrQOjLeRA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=C0gEbhFXUnKGT7O9eDSdef/dEPM10WBKwSMP8aZalLNjo0FF3n15S737m4dqGJta1 xJpr8OANIk5aWlIkYbOdlmS9n0laYbWS4SBr1268K/UAkPjomY1/u+wwIdYMA/YuhN XA65KeVioeKiSezgw5nsm0E2Hdtv6zqZ0Ed948sg= 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 ESMTPS id 8754F3857820 for ; Wed, 10 Nov 2021 15:51:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8754F3857820 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-441-Lukbv4PhPGi2lEkn6xnOPw-1; Wed, 10 Nov 2021 10:51:19 -0500 X-MC-Unique: Lukbv4PhPGi2lEkn6xnOPw-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 9407ACC621 for ; Wed, 10 Nov 2021 15:51:18 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.203]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD20460843; Wed, 10 Nov 2021 15:51:15 +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 1AAFpCx0639816 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 10 Nov 2021 16:51:13 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 1AAFpCkh639815; Wed, 10 Nov 2021 16:51:12 +0100 To: GCC patches Subject: [COMMITTED] Grow sbr_vector in ranger's on-entry cache as needed. Date: Wed, 10 Nov 2021 16:51:08 +0100 Message-Id: <20211110155108.639758-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_H2, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew MacLeod The on-entry cache does not expect the number of BBs to change. This could happen in various scenarios, recently in the suggestion to use ranger with loop unswitching and also with a work in progress to use the path solver in the loopch pass. This patch fixes both. This is a patch from Andrew, who tested it on x86-64 Linux. Pushed. gcc/ChangeLog: * gimple-range-cache.cc (sbr_vector::grow): New. (sbr_vector::set_bb_range): Call grow. (sbr_vector::get_bb_range): Same. (sbr_vector::bb_range_p): Remove assert. --- gcc/gimple-range-cache.cc | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index e5591bab0ef..a63e20e7e49 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -210,6 +210,7 @@ protected: int_range<2> m_undefined; tree m_type; irange_allocator *m_irange_allocator; + void grow (); }; @@ -229,13 +230,37 @@ sbr_vector::sbr_vector (tree t, irange_allocator *allocator) m_undefined.set_undefined (); } +// Grow the vector when the CFG has increased in size. + +void +sbr_vector::grow () +{ + int curr_bb_size = last_basic_block_for_fn (cfun); + gcc_checking_assert (curr_bb_size > m_tab_size); + + // Increase the max of a)128, b)needed increase * 2, c)10% of current_size. + int inc = MAX ((curr_bb_size - m_tab_size) * 2, 128); + inc = MAX (inc, curr_bb_size / 10); + int new_size = inc + curr_bb_size; + + // Allocate new memory, copy the old vector and clear the new space. + irange **t = (irange **)m_irange_allocator->get_memory (new_size + * sizeof (irange *)); + memcpy (t, m_tab, m_tab_size * sizeof (irange *)); + memset (t + m_tab_size, 0, (new_size - m_tab_size) * sizeof (irange *)); + + m_tab = t; + m_tab_size = new_size; +} + // Set the range for block BB to be R. bool sbr_vector::set_bb_range (const_basic_block bb, const irange &r) { irange *m; - gcc_checking_assert (bb->index < m_tab_size); + if (bb->index >= m_tab_size) + grow (); if (r.varying_p ()) m = &m_varying; else if (r.undefined_p ()) @@ -252,7 +277,8 @@ sbr_vector::set_bb_range (const_basic_block bb, const irange &r) bool sbr_vector::get_bb_range (irange &r, const_basic_block bb) { - gcc_checking_assert (bb->index < m_tab_size); + if (bb->index >= m_tab_size) + return false; irange *m = m_tab[bb->index]; if (m) { @@ -267,8 +293,9 @@ sbr_vector::get_bb_range (irange &r, const_basic_block bb) bool sbr_vector::bb_range_p (const_basic_block bb) { - gcc_checking_assert (bb->index < m_tab_size); - return m_tab[bb->index] != NULL; + if (bb->index < m_tab_size) + return m_tab[bb->index] != NULL; + return false; } // This class implements the on entry cache via a sparse bitmap.