From 79f71ec6fca0e093d27cb238d7c75dccb3a55d65 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Thu, 15 Jul 2021 12:38:36 +0200 Subject: Abstract out non_null adjustments in ranger. 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. 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 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'gcc/gimple-range-cache.cc') diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 98ecdbb..23597ad 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. -- cgit v1.1