From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 75B253857817; Wed, 10 Nov 2021 15:51:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75B253857817 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5128] Grow sbr_vector in ranger's on-entry cache as needed. X-Act-Checkin: gcc X-Git-Author: Andrew MacLeod X-Git-Refname: refs/heads/master X-Git-Oldrev: 5ba247ade1cc0ca06a0f7d3483b0520ba98bf2d2 X-Git-Newrev: eaec20fde587e0695b100dcba5ff56944c3ae8c0 Message-Id: <20211110155135.75B253857817@sourceware.org> Date: Wed, 10 Nov 2021 15:51:35 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Nov 2021 15:51:35 -0000 https://gcc.gnu.org/g:eaec20fde587e0695b100dcba5ff56944c3ae8c0 commit r12-5128-geaec20fde587e0695b100dcba5ff56944c3ae8c0 Author: Andrew MacLeod Date: Wed Nov 10 16:49:50 2021 +0100 Grow sbr_vector in ranger's on-entry cache as needed. 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. 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. Diff: --- 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.