diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2022-02-07 15:52:16 -0500 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2022-02-09 09:09:54 -0500 |
commit | c6bb1db76b3ac127aff7dacf391fc1798a94bb7d (patch) | |
tree | ece35b744603236671d2ee0e8cc8fdf1c8f06828 /gcc/gimple-range-cache.h | |
parent | da2bf62d9e2a25f2d6a99176144c250b51fbdee7 (diff) | |
download | gcc-c6bb1db76b3ac127aff7dacf391fc1798a94bb7d.zip gcc-c6bb1db76b3ac127aff7dacf391fc1798a94bb7d.tar.gz gcc-c6bb1db76b3ac127aff7dacf391fc1798a94bb7d.tar.bz2 |
Register non-null side effects properly.
This patch adjusts uses of nonnull to accurately reflect "somewhere in block".
It also adds the ability to register statement side effects within a block
for ranger which will apply for the rest of the block.
PR tree-optimization/104288
gcc/
* gimple-range-cache.cc (non_null_ref::set_nonnull): New.
(non_null_ref::adjust_range): Move to header.
(ranger_cache::range_of_def): Don't check non-null.
(ranger_cache::entry_range): Don't check non-null.
(ranger_cache::range_on_edge): Check for nonnull on normal edges.
(ranger_cache::update_to_nonnull): New.
(non_null_loadstore): New.
(ranger_cache::block_apply_nonnull): New.
* gimple-range-cache.h (class non_null_ref): Update prototypes.
(non_null_ref::adjust_range): Move to here and inline.
(class ranger_cache): Update prototypes.
* gimple-range-path.cc (path_range_query::range_defined_in_block): Do
not search dominators.
(path_range_query::adjust_for_non_null_uses): Ditto.
* gimple-range.cc (gimple_ranger::range_of_expr): Check on-entry for
def overrides. Do not check nonnull.
(gimple_ranger::range_on_entry): Check dominators for nonnull.
(gimple_ranger::range_on_edge): Check for nonnull on normal edges..
(gimple_ranger::register_side_effects): New.
* gimple-range.h (gimple_ranger::register_side_effects): New.
* tree-vrp.cc (rvrp_folder::fold_stmt): Call register_side_effects.
gcc/testsuite/
* gcc.dg/pr104288.c: New.
Diffstat (limited to 'gcc/gimple-range-cache.h')
-rw-r--r-- | gcc/gimple-range-cache.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index b54b688..589b649 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -36,12 +36,41 @@ public: 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); + bool set_nonnull (basic_block bb, tree name); private: vec <bitmap> m_nn; void process_name (tree name); bitmap_obstack m_bitmaps; }; +// 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. + +inline bool +non_null_ref::adjust_range (irange &r, tree name, basic_block bb, + bool search_dom) +{ + // Non-call exceptions mean we could throw in the middle of the + // block, so just punt on those for now. + if (cfun->can_throw_non_call_exceptions) + return false; + // We only care about the null / non-null property of pointers. + if (!POINTER_TYPE_P (TREE_TYPE (name))) + return false; + if (r.undefined_p () || r.lower_bound () != 0 || r.upper_bound () == 0) + return false; + // Check if pointers have any non-null dereferences. + if (non_null_deref_p (name, bb, search_dom)) + { + // Remove zero from the range. + unsigned prec = TYPE_PRECISION (TREE_TYPE (name)); + r.intersect (wi::one (prec), wi::max_value (prec, UNSIGNED)); + return true; + } + return false; +} + // This class manages a vector of pointers to ssa_block ranges. It // provides the basis for the "range on entry" cache for all // SSA names. @@ -106,6 +135,8 @@ public: void propagate_updated_value (tree name, basic_block bb); + void block_apply_nonnull (gimple *s); + void update_to_nonnull (basic_block bb, tree name); non_null_ref m_non_null; gori_compute m_gori; |