aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-range.cc
AgeCommit message (Collapse)AuthorFilesLines
2023-10-05Add a dom based ranger for fast VRP.Andrew MacLeod1-0/+300
Provide a dominator based implementation of a range query. * gimple-range.cc (dom_ranger::dom_ranger): New. (dom_ranger::~dom_ranger): New. (dom_ranger::range_of_expr): New. (dom_ranger::edge_range): New. (dom_ranger::range_on_edge): New. (dom_ranger::range_in_bb): New. (dom_ranger::range_of_stmt): New. (dom_ranger::maybe_push_edge): New. (dom_ranger::pre_bb): New. (dom_ranger::post_bb): New. * gimple-range.h (class dom_ranger): New.
2023-09-07Some ssa-names get incorrectly marked as always_current.Andrew MacLeod1-3/+7
When range_of_stmt invokes prefill_name to evaluate unvisited dependencies it should not mark already visited names as always_current. PR tree-optimization/110875 gcc/ * gimple-range.cc (gimple_ranger::prefill_name): Only invoke cache-prefilling routine when the ssa-name has no global value. gcc/testsuite/ * gcc.dg/pr110875.c: New.
2023-07-28Add a merge_range to ssa_cache and use it. add empty_p and param tweaks.Andrew MacLeod1-4/+2
* gimple-range-cache.cc (ssa_cache::merge_range): New. (ssa_lazy_cache::merge_range): New. * gimple-range-cache.h (class ssa_cache): Adjust protoypes. (class ssa_lazy_cache): Ditto. * gimple-range.cc (assume_query::calculate_op): Use merge_range.
2023-05-24Make ssa_cache a range_query.Andrew MacLeod1-0/+8
By providing range_of_expr as a range_query, we can fold and do other interesting things using values from the global table. Make ranger's knonw globals available via const_query. * gimple-range-cache.cc (ssa_cache::range_of_expr): New. * gimple-range-cache.h (class ssa_cache): Inherit from range_query. (ranger_cache::const_query): New. * gimple-range.cc (gimple_ranger::const_query): New. * gimple-range.h (gimple_ranger::const_query): New prototype.
2023-05-24Only update global value if it changes.Andrew MacLeod1-4/+4
Do not update and propagate a global value if it hasn't changed. PR tree-optimization/109695 * gimple-range-cache.cc (ranger_cache::get_global_range): Add changed param. * gimple-range-cache.h (ranger_cache::get_global_range): Ditto. * gimple-range.cc (gimple_ranger::range_of_stmt): Pass changed flag to set_global_range. (gimple_ranger::prefill_stmt_dependencies): Ditto.
2023-05-04Rename last_stmt to last_nondebug_stmtRichard Biener1-1/+1
The following renames last_stmt to last_nondebug_stmt which is what it really does. * tree-cfg.h (last_stmt): Rename to ... (last_nondebug_stmt): ... this. * tree-cfg.cc (last_stmt): Rename to ... (last_nondebug_stmt): ... this. (assign_discriminators): Adjust. (group_case_labels_stmt): Likewise. (gimple_can_duplicate_bb_p): Likewise. (execute_fixup_cfg): Likewise. * auto-profile.cc (afdo_propagate_circuit): Likewise. * gimple-range.cc (gimple_ranger::range_on_exit): Likewise. * omp-expand.cc (workshare_safe_to_combine_p): Likewise. (determine_parallel_type): Likewise. (adjust_context_and_scope): Likewise. (expand_task_call): Likewise. (remove_exit_barrier): Likewise. (expand_omp_taskreg): Likewise. (expand_omp_for_init_counts): Likewise. (expand_omp_for_init_vars): Likewise. (expand_omp_for_static_chunk): Likewise. (expand_omp_simd): Likewise. (expand_oacc_for): Likewise. (expand_omp_for): Likewise. (expand_omp_sections): Likewise. (expand_omp_atomic_fetch_op): Likewise. (expand_omp_atomic_cas): Likewise. (expand_omp_atomic): Likewise. (expand_omp_target): Likewise. (expand_omp): Likewise. (omp_make_gimple_edges): Likewise. * trans-mem.cc (tm_region_init): Likewise. * tree-inline.cc (redirect_all_calls): Likewise. * tree-parloops.cc (gen_parallel_loop): Likewise. * tree-ssa-loop-ch.cc (do_while_loop_p): Likewise. * tree-ssa-loop-ivcanon.cc (canonicalize_loop_induction_variables): Likewise. * tree-ssa-loop-ivopts.cc (stmt_after_ip_normal_pos): Likewise. (may_eliminate_iv): Likewise. * tree-ssa-loop-manip.cc (standard_iv_increment_position): Likewise. * tree-ssa-loop-niter.cc (do_warn_aggressive_loop_optimizations): Likewise. (estimate_numbers_of_iterations): Likewise. * tree-ssa-loop-split.cc (compute_added_num_insns): Likewise. * tree-ssa-loop-unswitch.cc (get_predicates_for_bb): Likewise. (set_predicates_for_bb): Likewise. (init_loop_unswitch_info): Likewise. (hoist_guard): Likewise. * tree-ssa-phiopt.cc (match_simplify_replacement): Likewise. (minmax_replacement): Likewise. * tree-ssa-reassoc.cc (update_range_test): Likewise. (optimize_range_tests_to_bit_test): Likewise. (optimize_range_tests_var_bound): Likewise. (optimize_range_tests): Likewise. (no_side_effect_bb): Likewise. (suitable_cond_bb): Likewise. (maybe_optimize_range_tests): Likewise. (reassociate_bb): Likewise. * tree-vrp.cc (rvrp_folder::pre_fold_bb): Likewise.
2023-04-26Rename ssa_global_cache to ssa_cache and add has_rangeAndrew MacLeod1-7/+7
This renames the ssa_global_cache to be ssa_cache. The original use was to function as a global cache, but its uses have expanded. Remove all mention of "global" from the class and methods. Also add a has_range method. * gimple-range-cache.cc (ssa_cache::ssa_cache): Rename. (ssa_cache::~ssa_cache): Rename. (ssa_cache::has_range): New. (ssa_cache::get_range): Rename. (ssa_cache::set_range): Rename. (ssa_cache::clear_range): Rename. (ssa_cache::clear): Rename. (ssa_cache::dump): Rename and use get_range. (ranger_cache::get_global_range): Use get_range and set_range. (ranger_cache::range_of_def): Use get_range. * gimple-range-cache.h (class ssa_cache): Rename class and methods. (class ranger_cache): Use ssa_cache. * gimple-range-path.cc (path_range_query::path_range_query): Use ssa_cache. (path_range_query::get_cache): Use get_range. (path_range_query::set_cache): Use set_range. * gimple-range-path.h (class path_range_query): Use ssa_cache. * gimple-range.cc (assume_query::assume_range_p): Use get_range. (assume_query::range_of_expr): Use get_range. (assume_query::assume_query): Use set_range. (assume_query::calculate_op): Use get_range and set_range. * gimple-range.h (class assume_query): Use ssa_cache.
2023-03-23ranger: Ranger meets aspellJakub Jelinek1-5/+5
I've noticed a comment typo in tree-vrp.cc and decided to quickly skim aspell -c on the ranger sources (with quick I on everything that looked ok or roughly ok). But not being a native English speaker, I could get stuff wrong. 2023-03-23 Jakub Jelinek <jakub@redhat.com> * value-range.cc (irange::irange_union, irange::intersect): Fix comment spelling bugs. * gimple-range-trace.cc (range_tracer::do_header): Likewise. * gimple-range-trace.h: Likewise. * gimple-range-edge.cc: Likewise. (gimple_outgoing_range_stmt_p, gimple_outgoing_range::switch_edge_range, gimple_outgoing_range::edge_range_p): Likewise. * gimple-range.cc (gimple_ranger::prefill_stmt_dependencies, gimple_ranger::fold_stmt, gimple_ranger::register_transitive_infer, assume_query::assume_query, assume_query::calculate_phi): Likewise. * gimple-range-edge.h: Likewise. * value-range.h (Value_Range::set, Value_Range::lower_bound, Value_Range::upper_bound, frange::set_undefined): Likewise. * gimple-range-gori.h (range_def_chain::depend, gori_map::m_outgoing, gori_compute): Likewise. * gimple-range-fold.h (fold_using_range): Likewise. * gimple-range-path.cc (path_range_query::compute_ranges_in_phis): Likewise. * gimple-range-gori.cc (range_def_chain::in_chain_p, range_def_chain::dump, gori_map::calculate_gori, gori_compute::compute_operand_range_switch, gori_compute::logical_combine, gori_compute::refine_using_relation, gori_compute::compute_operand1_range, gori_compute::may_recompute_p): Likewise. * gimple-range.h: Likewise. (enable_ranger): Likewise. * range-op.h (empty_range_varying): Likewise. * value-query.h (value_query): Likewise. * gimple-range-cache.cc (block_range_cache::set_bb_range, block_range_cache::dump, ssa_global_cache::clear_global_range, temporal_cache::temporal_value, temporal_cache::current_p, ranger_cache::range_of_def, ranger_cache::propagate_updated_value, ranger_cache::range_from_dom, ranger_cache::register_inferred_value): Likewise. * gimple-range-fold.cc (fur_edge::get_phi_operand, fur_stmt::get_operand, gimple_range_adjustment, fold_using_range::range_of_phi, fold_using_range::relation_fold_and_or): Likewise. * value-range-storage.h (irange_storage_slot::MAX_INTS): Likewise. * value-query.cc (range_query::value_of_expr, range_query::value_on_edge, range_query::query_relation): Likewise. * tree-vrp.cc (remove_unreachable::remove_and_update_globals, intersect_range_with_nonzero_bits): Likewise. * gimple-range-infer.cc (gimple_infer_range::check_assume_func, exit_range): Likewise. * value-relation.h: Likewise. (equiv_oracle, relation_trio::relation_trio, value_relation, value_relation::value_relation, pe_min): Likewise. * range-op-float.cc (range_operator_float::rv_fold, frange_arithmetic, foperator_unordered_equal::op1_range, foperator_div::rv_fold): Likewise. * gimple-range-op.cc (cfn_clz::fold_range): Likewise. * value-relation.cc (equiv_oracle::query_relation, equiv_oracle::register_equiv, equiv_oracle::add_equiv_to_block, value_relation::apply_transitive, relation_chain_head::find_relation, dom_oracle::query_relation, dom_oracle::find_relation_block, dom_oracle::find_relation_dom, path_oracle::register_equiv): Likewise. * range-op.cc (range_operator::wi_fold_in_parts_equiv, create_possibly_reversed_range, adjust_op1_for_overflow, operator_mult::wi_fold, operator_exact_divide::op1_range, operator_cast::lhs_op1_relation, operator_cast::fold_pair, operator_cast::fold_range, operator_abs::wi_fold, range_op_cast_tests, range_op_lshift_tests): Likewise.
2023-01-02Update copyright years.Jakub Jelinek1-1/+1
2022-12-08Ensure arguments to range-op handler are supported.Andrew MacLeod1-11/+13
PR tree-optimization/107985 gcc/ * gimple-range-op.cc (gimple_range_op_handler::gimple_range_op_handler): Check if type of the operands is supported. * gimple-range.cc (gimple_ranger::prefill_stmt_dependencies): Do not assert if here is no range-op handler. gcc/testsuite/ * g++.dg/pr107985.C: New.
2022-11-11Don't add dependencies in update_stmt.Andrew MacLeod1-1/+1
gimple_ranger::update_stmt has no idea what the context of an update is, and should not be adding relations when it re-evaluates a stmt. PR tree-optimization/107523 gcc/ * gimple-range.cc (gimple_ranger::update_stmt): Use fur_stmt rather than fur_depend. gcc/testsuite/ * gcc.dg/pr107523.c: New.
2022-11-07Add transitive inferred range processing.Andrew MacLeod1-0/+48
Rewalk statements at the end of a block to see if any inferred ranges affect earlier calculations and register those as inferred ranges. gcc/ PR tree-optimization/104530 * gimple-range-cache.cc (ranger_cache::register_inferred_value): New. Split from: (ranger_cache::apply_inferred_ranges): Move setting cache to separate function. * gimple-range-cache.h (register_inferred_value): New prototype. * gimple-range-infer.cc (infer_range_manager::has_range_p): New. * gimple-range-infer.h (has_range_p): New prototype. * gimple-range.cc (register_transitive_inferred_ranges): New. * gimple-range.h (register_transitive_inferred_ranges): New proto. * tree-vrp.cc (rvrp_folder::fold_stmt): Check for transitive inferred ranges at the end of the block before folding final stmt. gcc/testsuite/ * gcc.dg/pr104530.c: New.
2022-11-03Update range query cache when a statement is updated.Andrew MacLeod1-0/+34
Add an update_stmt interface to range query, and hook into it with the ssa statement update call. gcc/ * gimple-range.cc (gimple_ranger::update_stmt): New. * gimple-range.h (gimple_ranger::update_stmt): New prototype. * tree-ssa-operands.cc (update_stmt_operands): Notify range query that stmt has changed. * value-query.h (range_query::update_stmt): New. gcc/testsuite/ * gcc.dg/tree-ssa/vrp-update.c: New.
2022-11-01Allow queries on exit block.Andrew MacLeod1-1/+0
Ranger was not allowing the exit block to be queried for range_on_entry or exit. This removes that restriction. * gimple-range-cache.cc (ranger_cache::fill_block_cache): Allow exit block to be specified. (ranger_cache::range_from_dom): If exit block is specified, use the immediate predecessor instead of the dominator to start. * gimple-range.cc (gimple_ranger::range_on_exit): Allow query for exit block.
2022-10-19Add assume support to VRP.Andrew MacLeod1-0/+190
This provides an assume_query class using rangers GORI module to determine what ranges would be applied to any SSA NAMES in the function if the return value were [1, 1]. Any parameter ranges are stored in the SSA_NAME_RANGE_INFO field, and ranger's inferred range machinery is then used to look these up and match them to assume call parameteres in the bodies of other functions.. PR c++/106654 gcc/ * gimple-range-gori.h (compute_operand_range): Make public. * gimple-range-infer.cc (gimple_infer_range::check_assume_func): New. (gimple_infer_range::gimple_infer_range): Check for assume calls. * gimple-range-infer.h (check_assume_func): Add prototype. * gimple-range.cc (assume_query::assume_range_p): New. (assume_query::range_of_expr): New. (assume_query::assume_query): New. (assume_query::calculate_op): New. (assume_query::calculate_phi): New. (assume_query::check_taken_edge): New. (assume_query::calculate_stmt): New. (assume_query::dump): New. * gimple-range.h (class assume_query): New. * tree-vrp.cc (pass_assumptions::execute): Add processing. gcc/testsuite/ * g++.dg/cpp23/attr-assume-opt.C: New.
2022-09-22Create gimple_range_op_handler in a new source file.Andrew MacLeod1-5/+6
Range-ops is meant to be IL independent. Some gimple processing has be placed in range-ops, and some is located in gori. Split it all into a file and isolate it in a new class gimple_range_op_handler. * Makefile.in (OBJS): Add gimple-range-op.o. * gimple-range-edge.cc (gimple_outgoing_range_stmt_p): Use gimple_range_op_handler. * gimple-range-fold.cc (gimple_range_base_of_assignment): Move to a method in gimple_range_op_handler. (gimple_range_operand1): Ditto. (gimple_range_operand2): Ditto. (fold_using_range::fold_stmt): Use gimple_range_op_handler. (fold_using_range::range_of_range_op): Ditto. (fold_using_range::relation_fold_and_or): Ditto. (fur_source::register_outgoing_edges): Ditto. (gimple_range_ssa_names): Relocate to gimple-range-op.cc. * gimple-range-fold.h: Adjust prototypes. * gimple-range-gori.cc (gimple_range_calc_op1): Move to a method in gimple_range_op_handler. (gimple_range_calc_op2): Ditto. (gori_compute::compute_operand_range): Use gimple_range_op_handler. (gori_compute::compute_logical_operands): Ditto. (compute_operand1_range): Ditto. (gori_compute::compute_operand2_range): Ditto. (gori_compute::compute_operand1_and_operand2_range): Ditto. * gimple-range-gori.h: Adjust protoypes. * gimple-range-op.cc: New. Supply gimple_range_op_handler methods. * gimple-range-op.h: New. Supply gimple_range_op_handler class. * gimple-range.cc (gimple_ranger::prefill_name): Use gimple_range_op_handler. (gimple_ranger::prefill_stmt_dependencies): Ditto. * gimple-range.h: Include gimple-range-op.h. * range-op.cc (range_op_handler::range_op_handler): Adjust and remove gimple * parameter option. * range-op.h: Adjust prototypes.
2022-07-25[PR middle-end/106432] Gracefully handle unsupported type in range_on_edgeAldy Hernandez1-1/+3
A cleaner approach to fix this PR has been suggested by Andrew, which is to just return false on range_on_edge for unsupported range types. Tested on x86-64 Linux. PR middle-end/106432 gcc/ChangeLog: * gimple-range.cc (gimple_ranger::range_on_edge): Return false when the result range type is unsupported.
2022-07-11Implement global ranges for all vrange types (SSA_NAME_RANGE_INFO).Aldy Hernandez1-26/+4
Currently SSA_NAME_RANGE_INFO only handles integer ranges, and loses half the precision in the process because its use of legacy value_range's. This patch rewrites all the SSA_NAME_RANGE_INFO (nonzero bits included) to use the recently contributed vrange_storage. With it, we'll be able to efficiently save any ranges supported by ranger in GC memory. Presently this will only be irange's, but shortly we'll add floating ranges and others to the mix. As per the discussion with the trailing_wide_ints adjustments and vrange_storage, we'll be able to save integer ranges with a maximum of 5 sub-ranges. This could be adjusted later if more sub-ranges are needed (unlikely). Since this is a behavior changing patch, I would like to take a few days for discussion, and commit early next week if all goes well. A few notes. First, we get rid of the SSA_NAME_ANTI_RANGE_P bit in the SSA_NAME since we store full resolution ranges. Perhaps it could be re-used for something else. The range_info_def struct is gone in favor of an opaque type handled by vrange_storage. It currently supports irange, but will support frange, prange, etc, in due time. From the looks of it, set_range_info was an update operation despite its name, as we improved the nonzero bits with each call, even though we clobbered the ranges. Presumably this was because doing a proper intersect of ranges lost information with the anti-range hack. We no longer have this limitation so now we formalize both set_range_info and set_nonzero_bits to an update operation. After all, we should never be losing information, but enhancing it whenever possible. This means, that if folks' finger-memory is not offended, as a follow-up, I'd like to rename set_nonzero_bits and set_range_info to update_*. I have kept the same global API we had in tree-ssanames.h, with the caveat that all set operations are now update as discussed above. There is a 2% performance penalty for evrp and a 3% penalty for VRP that is coincidentally in line with a previous improvement of the same amount in the vrange abstraction patchset. Interestingly, this penalty is mostly due to the wide int to tree dance we keep doing with irange and legacy. In a first draft of this patch where I was streaming trees directly, there was actually a small improvement instead. I hope to get some of the gain back when we move irange's to wide-ints, though I'm not in a hurry ;-). Tested and benchmarked on x86-64 Linux. Tested on ppc64le Linux. Comments welcome. gcc/ChangeLog: * gimple-range.cc (gimple_ranger::export_global_ranges): Remove verification against legacy value_range. (gimple_ranger::register_inferred_ranges): Same. (gimple_ranger::export_global_ranges): Rename update_global_range to set_range_info. * tree-core.h (struct range_info_def): Remove. (struct irange_storage_slot): New. (struct tree_base): Remove SSA_NAME_ANTI_RANGE_P documentation. (struct tree_ssa_name): Add vrange_storage support. * tree-ssanames.cc (range_info_p): New. (range_info_fits_p): New. (range_info_alloc): New. (range_info_free): New. (range_info_get_range): New. (range_info_set_range): New. (set_range_info_raw): Remove. (set_range_info): Adjust to use vrange_storage. (set_nonzero_bits): Same. (get_nonzero_bits): Same. (duplicate_ssa_name_range_info): Remove overload taking value_range_kind. Rewrite tree overload to use vrange_storage. (duplicate_ssa_name_fn): Adjust to use vrange_storage. * tree-ssanames.h (struct range_info_def): Remove. (set_range_info): Adjust prototype to take vrange. * tree-vrp.cc (vrp_asserts::remove_range_assertions): Call duplicate_ssa_name_range_info. * tree.h (SSA_NAME_ANTI_RANGE_P): Remove. (SSA_NAME_RANGE_TYPE): Remove. * value-query.cc (get_ssa_name_range_info): Adjust to use vrange_storage. (update_global_range): Remove. (get_range_global): Remove as_a<irange>. * value-query.h (update_global_range): Remove. * tree-ssa-dom.cc (set_global_ranges_from_unreachable_edges): Rename update_global_range to set_range_info. * value-range-storage.cc (vrange_storage::alloc_slot): Remove gcc_unreachable.
2022-07-04Misc conversions to vrange.Aldy Hernandez1-3/+8
The following converts a handful of places that were irange centric. Tested on x86-64 Linux. gcc/ChangeLog: * gimple-range-fold.cc (fold_using_range::range_of_ssa_name_with_loop_info): Restrict the call to SCEV for irange supported types. (fold_using_range::range_of_builtin_int_call): Convert to vrange. * gimple-range.cc (gimple_ranger::prefill_stmt_dependencies): Same. * tree-ssa-dom.cc (cprop_operand): Same.
2022-06-03Misc range temporary fixes.Aldy Hernandez1-3/+6
This fixes a couples places that were using int_range_max, but needed a generic temporary. Found while merging the frange work. Also, copying between range temporaries is actually useful :). Tested on x86-64 Linux. gcc/ChangeLog: * gimple-range-cache.cc (ranger_cache::range_from_dom): Use Value_Range. * gimple-range.cc (gimple_ranger::register_inferred_ranges): Same. * value-range.h (Value_Range::Value_Range): Implement copy constructor for Value_Range.
2022-06-03Implement vrange::supports_type_p.Aldy Hernandez1-2/+2
[I have conservatively assumed that both the loop-ch and loop-unswitch passes, which also use the ranger, only support integers and pointers. If the goal is to handle other types as well, irange::supports_p() should be Value_Range::supports_type_p(), and any uses of int_range_max should be converted to Value_Range. I can help in the conversion if you'd like.] As discussed, this patch disambiguates the use of supports_type_p throughout, as what ranger supports is a totally different question than what a given range variant (irange, frange, etc) supports. Unfortunately we need both a static method and a virtual method, and they can't be named the same. The uses are documented in the vrange class: +// To query what types ranger and the entire ecosystem can support, +// use Value_Range::supports_type_p(tree type). This is a static +// method available independently of any vrange object. +// +// To query what a given vrange variant can support, use: +// irange::supports_p () +// frange::supports_p () +// etc +// +// To query what a range object can support, use: +// void foo (vrange &v, irange &i, frange &f) +// { +// if (v.supports_type_p (type)) ... +// if (i.supports_type_p (type)) ... +// if (f.supports_type_p (type)) ... +// } The value_range_equiv::supports_p() method can be use to determine what legacy VRP supports, as irange::supports_p() will no longer be applicable in the evrp analyzer code base once irange and prange are split. Tested on x86-64 Linux. gcc/ChangeLog: * gimple-range-edge.cc (gimple_outgoing_range_stmt_p): Adjust for an object level supports_type_p for irange and a static Value_Range::supports_type_p. * gimple-range-fold.cc (fold_using_range::range_of_range_op): Same. (fold_using_range::range_of_address): Same. (fold_using_range::range_of_builtin_call): Same. * gimple-range-fold.h (gimple_range_type): Same. (gimple_range_ssa_p): Same. * gimple-range-path.cc (path_range_query::internal_range_of_expr): Same. (path_range_query::range_of_stmt): Same. (path_range_query::add_to_imports): Same. * gimple-range.cc (gimple_ranger::range_on_edge): Same. (gimple_ranger::export_global_ranges): Same. * gimple-ssa-evrp-analyze.cc (evrp_range_analyzer::record_ranges_from_phis): Same. * range-op.cc (range_operator::wi_fold): Same. (range_operator::fold_range): Same. * tree-ssa-loop-ch.cc (entry_loop_condition_is_static): Same. * tree-ssa-loop-unswitch.cc (struct unswitch_predicate): Same. (evaluate_control_stmt_using_entry_checks): Same. * tree-ssa-threadedge.cc (hybrid_jt_simplifier::compute_ranges_from_state): Same. * tree-vrp.cc (supported_types_p): Same. * value-query.cc (range_query::value_of_expr): Same. (range_query::value_on_edge): Same. (range_query::value_of_stmt): Same. (range_query::get_tree_range): Same. (get_range_global): Same. (global_range_query::range_of_expr): Same. * value-range-equiv.h (class value_range_equiv): Same. * value-range.cc (irange::supports_type_p): Same. (unsupported_range::supports_type_p): Same. * value-range.h (enum value_range_discriminator): Same. (Value_Range::init): Same. (Value_Range::supports_type_p): Same. (irange::supports_type_p): Same. (irange::supports_p): Same. (vrange::supports_type_p): Same. (vrange_allocator::alloc_vrange): Same.
2022-06-01Convert ranger and clients to vrange.Aldy Hernandez1-24/+40
Finally, the meat of the work. Convert ranger and associated clients to vrange. Everything's relatively mechanical given the previous patches. I did include a minor cleanup in the edge code. There's no need to check that the type of the switch is an integer as non-integer switches are invalid. I verified this with an appropriately coded assert. Tested on x86-64 & ppc64le Linux. gcc/ChangeLog: * gimple-range-cache.cc (ssa_block_ranges::dump): Convert to vrange. (sbr_vector::sbr_vector): Same. (sbr_vector::grow): Same. (sbr_vector::set_bb_range): Same. (sbr_vector::get_bb_range): Same. (sbr_sparse_bitmap::sbr_sparse_bitmap): Same. (sbr_sparse_bitmap::set_bb_range): Same. (sbr_sparse_bitmap::get_bb_range): Same. (block_range_cache::set_bb_range): Same. (block_range_cache::get_bb_range): Same. (block_range_cache::dump): Same. (ssa_global_cache::get_global_range): Same. (ssa_global_cache::set_global_range): Same. (ssa_global_cache::clear): Same. (ssa_global_cache::dump): Same. (ranger_cache::get_global_range): Same. (ranger_cache::set_global_range): Same. (ranger_cache::range_of_def): Same. (ranger_cache::entry_range): Same. (ranger_cache::exit_range): Same. (ranger_cache::edge_range): Same. (ranger_cache::range_of_expr): Same. (ranger_cache::range_on_edge): Same. (ranger_cache::block_range): Same. (ranger_cache::propagate_cache): Same. (ranger_cache::fill_block_cache): Same. (ranger_cache::range_from_dom): Same. * gimple-range-cache.h: Same. * gimple-range-edge.cc (gimple_outgoing_range::get_edge_range): Same. (gimple_outgoing_range::switch_edge_range): Same. (gimple_outgoing_range::edge_range_p): Same. * gimple-range-edge.h: Same. * gimple-range-fold.cc (fur_source::get_operand): Same. (fur_source::get_phi_operand): Same. (fur_edge::get_operand): Same. (fur_edge::get_phi_operand): Same. (fur_stmt::get_operand): Same. (fur_stmt::get_phi_operand): Same. (fur_list::fur_list): Same. (fur_list::get_operand): Same. (fur_list::get_phi_operand): Same. (fold_range): Same. (adjust_imagpart_expr): Same. (adjust_realpart_expr): Same. (gimple_range_adjustment): Same. (fold_using_range::fold_stmt): Same. (fold_using_range::range_of_range_op): Same. (fold_using_range::range_of_address): Same. (fold_using_range::range_of_phi): Same. (fold_using_range::range_of_call): Same. (fold_using_range::range_of_builtin_call): Same. (fold_using_range::range_of_builtin_int_call): Same. (fold_using_range::range_of_cond_expr): Same. (fur_source::register_outgoing_edges): Same. * gimple-range-fold.h (fold_range): Same. (gimple_range_type): Same. (gimple_range_ssa_p): Same. * gimple-range-gori.cc (gimple_range_calc_op1): Same. (gimple_range_calc_op2): Same. (gori_compute::compute_operand_range_switch): Same. (gori_compute::compute_operand_range): Same. (gori_compute::logical_combine): Same. (gori_compute::compute_logical_operands): Same. (gori_compute::compute_operand1_range): Same. (gori_compute::compute_operand2_range): Same. (gori_compute::compute_operand1_and_operand2_range): Same. (gori_compute::outgoing_edge_range_p): Same. (gori_compute::condexpr_adjust): Same. * gimple-range-gori.h (gimple_range_calc_op1): Same. (gimple_range_calc_op2): Same. * gimple-range-path.cc (path_range_query::get_cache): Same. (path_range_query::set_cache): Same. (path_range_query::range_on_path_entry): Same. (path_range_query::internal_range_of_expr): Same. (path_range_query::range_of_expr): Same. (path_range_query::ssa_range_in_phi): Same. (path_range_query::range_defined_in_block): Same. (path_range_query::compute_ranges_in_phis): Same. (path_range_query::compute_ranges_in_block): Same. (path_range_query::add_to_imports): Same. (path_range_query::range_of_stmt): Same. * gimple-range-path.h: Same. * gimple-range-infer.cc (gimple_infer_range::add_range): Same. (gimple_infer_range::~side_effect_manager): Same. (gimple_infer_range::get_nonzero): Same. (gimple_infer_range::maybe_adjust_range): Same. (gimple_infer_range::add_range): Same. * gimple-range-infer.h: Same. * gimple-range-tests.cc: Same. * gimple-range-trace.cc (range_tracer::trailer): Same. (debug_seed_ranger): Same. * gimple-range-trace.h: Same. * gimple-range.cc (gimple_ranger::range_of_expr): Same. (gimple_ranger::range_on_entry): Same. (gimple_ranger::range_on_exit): Same. (gimple_ranger::range_on_edge): Same. (gimple_ranger::fold_range_internal): Same. (gimple_ranger::range_of_stmt): Same. (gimple_ranger::prefill_name): Same. (gimple_ranger::prefill_stmt_dependencies): Same. (gimple_ranger::export_global_ranges): Same. (gimple_ranger::dump_bb): Same. * gimple-range.h: Same. * gimple-ssa-warn-access.cc (check_nul_terminated_array): Same. (memmodel_to_uhwi): Same. * tree-ssa-loop-niter.cc (refine_value_range_using_guard): Same. (determine_value_range): Same. (record_nonwrapping_iv): Same. (infer_loop_bounds_from_signedness): Same. (scev_var_range_cant_overflow): Same. * tree-ssa-threadedge.cc (hybrid_jt_simplifier::simplify): Same. * value-query.cc (range_query::range_on_edge): Same. (range_query::range_of_stmt): Same. (range_query::value_of_expr): Same. (range_query::value_on_edge): Same. (range_query::value_of_stmt): Same. (range_query::get_tree_range): Same. (update_global_range): Same. (get_range_global): Same. (gimple_range_global): Same. (global_range_query::range_of_expr): Same. (range_query::query_relation): Same. * value-query.h (gimple_range_global): Same. (update_global_range): Same. * vr-values.cc (vr_values::range_of_expr): Same. (bounds_of_var_in_loop): Same. (simplify_using_ranges::vrp_visit_cond_stmt): Same. * vr-values.h (class vr_values): Same. * tree-ssa-loop-unswitch.cc (unswitch_predicate): Same.
2022-06-01Convert range-op.* to vrange.Aldy Hernandez1-3/+3
This patch provides the infrastructure to make range-ops type agnostic. First, the range_op_handler function has been replaced with an object of the same name. It's coded in such a way to minimize changes to the code base, and to encapsulate the dispatch code. Instead of: range_operator *op = range_op_handler (code, type); if (op) op->fold_range (...); We now do: range_op_handler op (code, type); if (op) op->fold_range (...); I've folded gimple_range_handler into the range_op_handler class, since it's also a query into the range operators. Instead of: range_operator *handler = gimple_range_handler (stmt); We now do: range_op_handler handler (stmt); This all has the added benefit of moving all the dispatch code into an independent class and avoid polluting range_operator (which we'll further split later when frange and prange come live). There's this annoying "using" keyword that's been added to each operator due to hiding rules in C++. The issue is that we will have different virtual versions of fold_range() for each combination of operands. For example: // Traditional binary op on irange's. fold_range (irange &lhs, const irange &op1, const irange &op2); // For POINTER_DIFF_EXPR: fold_range (irange &lhs, const prange &op1, const prange &op2); // Cast from irange to prange. fold_range (prange &lhs, const irange &op1, const irange &op2); Overloading virtuals when there are multiple same named methods causes hidden virtuals warnings from -Woverloaded-virtual, thus the using keyword. An alternative would be to have different names: fold_range_III, fold_range_IPP, fold_range_PII, but that's uglier still. Tested on x86-64 & ppc64le Linux. gcc/ChangeLog: * gimple-range-edge.cc (gimple_outgoing_range_stmt_p): Adjust for vrange and convert range_op_handler function calls to use the identically named object. * gimple-range-fold.cc (gimple_range_operand1): Same. (gimple_range_operand2): Same. (fold_using_range::fold_stmt): Same. (fold_using_range::range_of_range_op): Same. (fold_using_range::range_of_builtin_ubsan_call): Same. (fold_using_range::relation_fold_and_or): Same. (fur_source::register_outgoing_edges): Same. * gimple-range-fold.h (gimple_range_handler): Remove. * gimple-range-gori.cc (gimple_range_calc_op1): Adjust for vrange. (gimple_range_calc_op2): Same. (range_def_chain::get_def_chain): Same. (gori_compute::compute_operand_range): Same. (gori_compute::condexpr_adjust): Same. * gimple-range.cc (gimple_ranger::prefill_name): Same. (gimple_ranger::prefill_stmt_dependencies): Same. * range-op.cc (get_bool_state): Same. (class operator_equal): Add using clause. (class operator_not_equal): Same. (class operator_lt): Same. (class operator_le): Same. (class operator_gt): Same. (class operator_ge): Same. (class operator_plus): Same. (class operator_minus): Same. (class operator_mult): Same. (class operator_exact_divide): Same. (class operator_lshift): Same. (class operator_rshift): Same. (class operator_cast): Same. (class operator_logical_and): Same. (class operator_bitwise_and): Same. (class operator_logical_or): Same. (class operator_bitwise_or): Same. (class operator_bitwise_xor): Same. (class operator_trunc_mod): Same. (class operator_logical_not): Same. (class operator_bitwise_not): Same. (class operator_cst): Same. (class operator_identity): Same. (class operator_unknown): Same. (class operator_abs): Same. (class operator_negate): Same. (class operator_addr_expr): Same. (class pointer_or_operator): Same. (operator_plus::op1_range): Adjust for vrange. (operator_minus::op1_range): Same. (operator_mult::op1_range): Same. (operator_cast::op1_range): Same. (operator_bitwise_not::fold_range): Same. (operator_negate::fold_range): Same. (range_op_handler): Rename to... (get_handler): ...this. (range_op_handler::range_op_handler): New. (range_op_handler::fold_range): New. (range_op_handler::op1_range): New. (range_op_handler::op2_range): New. (range_op_handler::lhs_op1_relation): New. (range_op_handler::lhs_op2_relation): New. (range_op_handler::op1_op2_relation): New. (range_cast): Adjust for vrange. * range-op.h (range_op_handler): Remove function. (range_cast): Adjust for vrange. (class range_op_handler): New. (get_bool_state): Adjust for vrange. (empty_range_varying): Same. (relop_early_resolve): Same. * tree-data-ref.cc (compute_distributive_range): Same. * tree-vrp.cc (get_range_op_handler): Remove. (range_fold_binary_symbolics_p): Use range_op_handler class instead of get_range_op_handler. (range_fold_unary_symbolics_p): Same. (range_fold_binary_expr): Same. (range_fold_unary_expr): Same. * value-query.cc (range_query::get_tree_range): Adjust for vrange.
2022-05-25Tweak comments.Andrew MacLeod1-1/+1
Adjust some mispellings in comments. * gimple-range-cache.cc: Adjust comments. * gimple-range-infer.cc: Adjust comments. * gimple-range-infer.h: Adjust comments. * gimple-range.cc: Adjust comments.
2022-05-25Use infer instead of side-effect for ranges.Andrew MacLeod1-5/+4
Rename the files and classes to reflect the term infer rather than side-effect. * Makefile.in (OBJS): Use gimple-range-infer.o. * gimple-range-cache.cc (ranger_cache::fill_block_cache): Change msg. (ranger_cache::range_from_dom): Rename var side_effect to infer. (ranger_cache::apply_inferred_ranges): Rename from apply_side_effects. * gimple-range-cache.h: Include gimple-range-infer.h. (class ranger_cache): Adjust prototypes, use infer_range_manager. * gimple-range-infer.cc: Rename from gimple-range-side-effects.cc. (gimple_infer_range::*): Rename from stmt_side_effects. (infer_range_manager::*): Rename from side_effect_manager. * gimple-range-side-effect.cc: Rename. * gimple-range-side-effect.h: Rename. * gimple-range-infer.h: Rename from gimple-range-side-effects.h. (class gimple_infer_range): Rename from stmt_side_effects. (class infer_range_manager): Rename from side_effect_manager. * gimple-range.cc (gimple_ranger::register_inferred_ranges): Rename from register_side_effects. * gimple-range.h (register_inferred_ranges): Adjust prototype. * range-op.h: Adjust comment. * tree-vrp.cc (rvrp_folder::pre_fold_bb): Use register_inferred_ranges. (rvrp_folder::post_fold_bb): Use register_inferred_ranges.
2022-05-17Add side effect infrastructure.Andrew MacLeod1-16/+11
Replace the non-null procesing with a generic side effect implementation that can handle arbitrary side effects. * Makefile.in (OBJS): Add gimple-range-side-effect.o. * gimple-range-cache.cc (non_null_ref::non_null_ref): Delete. (non_null_ref::~non_null_ref): Delete. (non_null_ref::set_nonnull): Delete. (non_null_ref::non_null_deref_p): Delete. (non_null_ref::process_name): Delete. (ranger_cache::ranger_cache): Initialize m_exit object. (ranger_cache::fill_block_cache): Use m_exit object intead of nonnull. (ranger_cache::range_from_dom): Use side_effect class and m_exit object. (ranger_cache::update_to_nonnull): Delete. (non_null_loadstore): Delete. (ranger_cache::block_apply_nonnull): Delete. (ranger_cache::apply_side_effects): New. * gimple-range-cache.h (class non_null_ref): Delete. (non_null_ref::adjust_range): Delete. (class ranger_cache): Adjust prototypes, add side effect manager. * gimple-range-path.cc (path_range_query::range_defined_in_block): Use side effect manager for queries. (path_range_query::adjust_for_non_null_uses): Ditto. * gimple-range-path.h (class path_range_query): Delete non_null_ref. * gimple-range-side-effect.cc: New. * gimple-range-side-effect.h: New. * gimple-range.cc (gimple_ranger::gimple_ranger): Update contructor. (gimple_ranger::range_of_expr): Check def block for override value. (gimple_ranger::range_on_entry): Don't scan dominators for non-null. (gimple_ranger::range_on_edge): Check for outgoing side-effects. (gimple_ranger::register_side_effects): Call apply_side_effects. (enable_ranger): Update contructor. * gimple-range.h (class gimple_ranger): Update prototype. (enable_ranger): Update prototype. * tree-vrp.cc (execute_ranger_vrp): Invoke without immediate-use flag.
2022-05-13Export global ranges during the VRP block walk.Andrew MacLeod1-0/+22
VRP currently searches the ssa_name list for globals to exported after it finishes running. Recent changes have VRP calling a side-effect routine for each stmt during the walk. This change simply exports globals as they are calculated the final time during the walk. * gimple-range.cc (gimple_ranger::register_side_effects): First check if the DEF should be exported as a global. * tree-vrp.cc (rvrp_folder::pre_fold_bb): Process PHI side effects, which will export globals. (execute_ranger_vrp): Remove call to export_global_ranges.
2022-04-25Retain existing range knowledge when prefilling statements.Andrew MacLeod1-0/+4
When range_of_stmt was adjusted to avoid large recursion depth, we need to intersect the calculated range whth the any known range to avoid losing info. Range_of_stmt does this, but the new prefill code missed it. PR tree-optimization/105276 gcc/ * gimple-range.cc (gimple_ranger::prefill_stmt_dependencies): Include existing global range with calculated value. gcc/testsuite/ * g++.dg/pr105276.C: New.
2022-02-09Register non-null side effects properly.Andrew MacLeod1-3/+24
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.
2022-01-03Update copyright years.Jakub Jelinek1-1/+1
2021-12-01Also pre-process PHIs in range-of-stmt.Andrew MacLeod1-10/+19
PR tree-optimization/103464 * gimple-range.cc (gimple_ranger::prefill_name): Process phis also. (gimple_ranger::prefill_stmt_dependencies): Ditto.
2021-11-24Directly resolve range_of_stmt dependencies.Andrew MacLeod1-2/+105
All ranger API entries eventually call range_of_stmt to ensure there is an initial global value to work with. This can cause very deep call chains when satisfied via the normal API. Instead, push any dependencies onto a stack and evaluate them in a depth first manner, mirroring what would have happened via the normal API calls. PR tree-optimization/103231 gcc/ * gimple-range.cc (gimple_ranger::gimple_ranger): Create stmt stack. (gimple_ranger::gimple_ranger): Delete stmt stack. (gimple_ranger::range_of_stmt): Process depenedencies if they have no global cache entry. (gimple_ranger::prefill_name): New. (gimple_ranger::prefill_stmt_dependencies): New. * gimple-range.h (class gimple_ranger): Add prototypes.
2021-11-24Split return functionality of get_non_stale_global_range.Andrew MacLeod1-9/+12
Get_non_stale_global_range returns true only when there is a cache entry that is not out of date. Change it so that it returns true if there was a cache value, but return the temporal comparison result in an auxiallary flag. * gimple-range-cache.cc (ranger_cache::get_global_range): Always return a range, return if it came from the cache or not. (get_non_stale_global_range): Rename to get_global_range, and return the temporal state in a flag. * gimple-range-cache.h (get_non_stale_global_range): Rename and adjust. * gimple-range.cc (gimple_ranger::range_of_expr): No need to query get_global_range. (gimple_ranger::range_of_stmt): Adjust for global cache temporal state returned in a flag.
2021-11-24Range-on-edge trace tweak.Andrew MacLeod1-2/+2
Trace formatting gets out of sync when range on edge is called with a constant. * gimple-range.cc (gimple_ranger::range_on_edge): Call trailer when a constant is encountered to terminate the trace.
2021-11-09Keep x_range_query NULL for global ranges.Andrew MacLeod1-2/+3
Instead of x_range_query always pointing to an object, have it default to NULL and return a pointer to the global query in that case. * function.c (allocate_struct_function): Don't set x_range_query. * function.h (get_range_query): Move to value-query.h. * gimple-range.cc (enable_ranger): Check that query is currently NULL. (disable_ranger): Clear function current query field. * value-query.cc (get_global_range_query): Relocate to: * value-query.h (get_global_range_query): Here and inline. (get_range_query): Relocate here from function.h.
2021-11-08Don't calculate new values when using the private context callback.Andrew MacLeod1-2/+2
When using rangers private callback mechanism to provide context to fold_stmt calls, we are only suppose to be using the cache in read only mode, never calculate new values. gcc/ PR tree-optimization/103122 * gimple-range.cc (gimple_ranger::range_of_expr): Request the cache entry with "calulate new values" set to false. gcc/testsuite/ * g++.dg/pr103122.C: New.
2021-11-03Provide some context to folding via ranger.Andrew MacLeod1-1/+27
Provide an internal mechanism to supply context to range_of_expr for calls to ::fold_stmt. * gimple-range.cc (gimple_ranger::gimple_ranger): Initialize current_bb. (gimple_ranger::range_of_expr): Pick up range_on_entry when there is no explcit context and current_bb is set. (gimple_ranger::fold_stmt): New. * gimple-range.h (current_bb, fold_stmt): New. * tree-vrp.c (rvrp_folder::fold_stmt): Call ranger's fold_stmt.
2021-10-29Perform on-entry propagation after range_of_stmt on a gcond.Andrew MacLeod1-1/+11
Propagation is automatically done by the temporal cache when defs are out of date from the names on the RHS, but a gcond has no LHS, and any updates on the RHS are never propagated. Always propagate them. gcc/ PR tree-optimization/102983 * gimple-range-cache.h (propagate_updated_value): Make public. * gimple-range.cc (gimple_ranger::range_of_stmt): Propagate exports when processing gcond stmts. gcc/testsuite/ * gcc.dg/pr102983.c: New.
2021-10-25Always output exported ranges to a dump_file.Andrew MacLeod1-1/+1
* gimple-range.cc (gimple_ranger::export_global_ranges): Remove check for TDF_DETAILS.
2021-10-21Split --param=evrp-mode into evrp-mode and ranger-debug.Andrew MacLeod1-1/+1
With Ranger being used in more than EVRP, the debug output should no longer be tied up with the EVRP mode flag. * doc/invoke.texi (ranger-debug): Document. * flag-types.h (enum ranger_debug): New. (enum evrp_mode): Remove debug values. * gimple-range-cache.cc (DEBUG_RANGE_CACHE): Use new debug flag. * gimple-range-gori.cc (gori_compute::gori_compute): Ditto. * gimple-range.cc (gimple_ranger::gimple_ranger): Ditto. * gimple-ssa-evrp.c (hybrid_folder::choose_value): Ditto. (execute_early_vrp): Use evrp-mode directly. * params.opt (enum evrp_mode): Remove debug values. (ranger-debug): New. (ranger-logical-depth): Relocate to be in alphabetical order.
2021-10-18Process EH edges again and call get_tree_range on non gimple_range_ssa_p names.Andrew MacLeod1-5/+5
PR tree-optimization/102796 gcc/ * gimple-range.cc (gimple_ranger::range_on_edge): Process EH edges normally. Return get_tree_range for non gimple_range_ssa_p names. (gimple_ranger::range_of_stmt): Use get_tree_range for non gimple_range_ssa_p names. gcc/testsuite/ * g++.dg/pr102796.C: New.
2021-10-15Ranger : Do not process abnormal ssa-names.Andrew MacLeod1-0/+4
* gimple-range-fold.h (gimple_range_ssa_p): Don't process names that occur in abnormal phis. * gimple-range.cc (gimple_ranger::range_on_edge): Return false for abnormal and EH edges. * gimple-ssa-evrp.c (rvrp_folder::value_of_expr): Ditto. (rvrp_folder::value_on_edge): Ditto. (rvrp_folder::value_of_stmt): Ditto. (hybrid_folder::value_of_expr): Ditto for ranger queries. (hybrid_folder::value_on_edge): Ditto. (hybrid_folder::value_of_stmt): Ditto. * value-query.cc (gimple_range_global): Always return a range if the type is supported.
2021-09-30Add gimple_ranger::debug.Aldy Hernandez1-0/+6
I'm trying to add one debug() for each dump() to the dumping aids. Tested on x86-64 Linux. gcc/ChangeLog: * gimple-range.cc (gimple_ranger::debug): New. * gimple-range.h (class gimple_ranger): Add debug.
2021-09-23Create a ranger-local flag for non-executable edges.Andrew MacLeod1-4/+18
Instead of repurposing EDGE_EXECUTABLE, ranger creates a local flag and ultizes it throughout. * gimple-range-cache.cc (ranger_cache::ranger_cache): Take non-executable_edge flag as parameter. * gimple-range-cache.h (ranger_cache): Adjust prototype. * gimple-range-gori.cc (gori_compute::gori_compute): Take non-executable_edge flag as parameter. (gori_compute::outgoing_edge_range_p): Check new flag. * gimple-range-gori.h (gori_compute): Adjust prototype. * gimple-range.cc (gimple_ranger::gimple_ranger): Create new flag. (gimple_ranger::range_on_edge): Check new flag. * gimple-range.h (gimple_ranger::non_executable_edge_flag): New. * gimple-ssa-evrp.c (rvrp_folder): Pass ranger flag to simplifer. (hybrid_folder::hybrid_folder): Set ranger non-executable flag value. (hybrid_folder::fold_stmt): Set flag value in the simplifer. * vr-values.c (simplify_using_ranges::set_and_propagate_unexecutable): Use not_executable flag if provided inmstead of EDGE_EXECUTABLE. (simplify_using_ranges::simplify_switch_using_ranges): Clear EDGE_EXECUTABLE like it originally did. (simplify_using_ranges::cleanup_edges_and_switches): Clear any NON_EXECUTABLE flags. (simplify_using_ranges::simplify_using_ranges): Adjust. * vr-values.h (class simplify_using_ranges): Adjust. (simplify_using_ranges::set_range_query): Add non-executable flag param.
2021-09-20Use EDGE_EXECUTABLE in ranger and return UNDEFINED for those edges.Andrew MacLeod1-11/+25
If an incoming edge is UNDEFINED, don't process it. Track if other edges equate to a single value, and add an equivalence if appropriate. gcc/ * gimple-range-fold.cc (fold_using_range::range_of_phi): Ignore undefined edges, apply an equivalence if appropriate. * gimple-range-gori.cc (gori_compute::outgoing_edge_range_p): Return UNDEFINED if EDGE_EXECUTABLE is not set. * gimple-range.cc (gimple_ranger::gimple_ranger): Set all edges as EXECUTABLE upon startup. (gimple_ranger::range_on_edge): Return UNDEFINED for edges without EDGE_EXECUTABLE set. * vr-values.c (set_and_propagate_unexecutable): New. (simplify_using_ranges::fold_cond): Call set_and_propagate. (simplify_using_ranges::simplify_switch_using_ranges): Ditto. * vr-values.h: Add prototype. gcc/testsuite/ * gcc.dg/tree-ssa/evrp-ignore.c: New.
2021-08-25Avoid printing range table header alone.Martin Sebor1-21/+24
gcc/ChangeLog: * gimple-range-cache.cc (ssa_global_cache::dump): Avoid printing range table header alone. * gimple-range.cc (gimple_ranger::export_global_ranges): Same.
2021-08-19Document enable_ranger and disable_ranger.Martin Sebor1-0/+7
gcc: * gimple-range.cc: Add comments. * gimple-range.h: Same.
2021-08-17Abstract tracing routines into a class.Andrew MacLeod1-292/+101
Generalize range tracing into a class and integrae it with gimple_ranger. Remove the old derived trace_ranger class. * Makefile.in (OBJS): Add gimple-range-trace.o. * gimple-range-cache.h (enable_new_values): Remove unused prototype. * gimple-range-fold.cc: Adjust headers. * gimple-range-trace.cc: New. * gimple-range-trace.h: New. * gimple-range.cc (gimple_ranger::gimple_ranger): Enable tracer. (gimple_ranger::range_of_expr): Add tracing. (gimple_ranger::range_on_entry): Ditto. (gimple_ranger::range_on_exit): Ditto. (gimple_ranger::range_on_edge): Ditto. (gimple_ranger::fold_range_internal): Ditto. (gimple_ranger::dump_bb): Do not calculate edge range twice. (trace_ranger::*): Remove. (enable_ranger): Never create a trace_ranger. (debug_seed_ranger): Move to gimple-range-trace.cc. (dump_ranger): Ditto. (debug_ranger): Ditto. * gimple-range.h: Include gimple-range-trace.h. (range_on_entry, range_on_exit): No longer virtual. (class trace_ranger): Remove. (DEBUG_RANGE_CACHE): Move to gimple-range-trace.h.
2021-07-15Abstract out non_null adjustments in ranger.Aldy Hernandez1-6/+2
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.
2021-06-23Split gimple-range into gimple-range-fold and gimple-range.Andrew MacLeod1-1379/+0
Split the fold_using_range functions from gimple-range into gimple-range-fold. Also move the gimple_range_calc* routines into gimple-range-gori. * Makefile.in (OBJS): Add gimple-range-fold.o * gimple-range-fold.cc: New. * gimple-range-fold.h: New. * gimple-range-gori.cc (gimple_range_calc_op1): Move to here. (gimple_range_calc_op2): Ditto. * gimple-range-gori.h: Move prototypes to here. * gimple-range.cc: Adjust include files. (fur_source:fur_source): Relocate to gimple-range-fold.cc. (fur_source::get_operand): Ditto. (fur_source::get_phi_operand): Ditto. (fur_source::query_relation): Ditto. (fur_source::register_relation): Ditto. (class fur_edge): Ditto. (fur_edge::fur_edge): Ditto. (fur_edge::get_operand): Ditto. (fur_edge::get_phi_operand): Ditto. (fur_stmt::fur_stmt): Ditto. (fur_stmt::get_operand): Ditto. (fur_stmt::get_phi_operand): Ditto. (fur_stmt::query_relation): Ditto. (class fur_depend): Relocate to gimple-range-fold.h. (fur_depend::fur_depend): Relocate to gimple-range-fold.cc. (fur_depend::register_relation): Ditto. (fur_depend::register_relation): Ditto. (class fur_list): Ditto. (fur_list::fur_list): Ditto. (fur_list::get_operand): Ditto. (fur_list::get_phi_operand): Ditto. (fold_range): Ditto. (adjust_pointer_diff_expr): Ditto. (gimple_range_adjustment): Ditto. (gimple_range_base_of_assignment): Ditto. (gimple_range_operand1): Ditto. (gimple_range_operand2): Ditto. (gimple_range_calc_op1): Relocate to gimple-range-gori.cc. (gimple_range_calc_op2): Ditto. (fold_using_range::fold_stmt): Relocate to gimple-range-fold.cc. (fold_using_range::range_of_range_op): Ditto. (fold_using_range::range_of_address): Ditto. (fold_using_range::range_of_phi): Ditto. (fold_using_range::range_of_call): Ditto. (fold_using_range::range_of_builtin_ubsan_call): Ditto. (fold_using_range::range_of_builtin_call): Ditto. (fold_using_range::range_of_cond_expr): Ditto. (fold_using_range::range_of_ssa_name_with_loop_info): Ditto. (fold_using_range::relation_fold_and_or): Ditto. (fold_using_range::postfold_gcond_edges): Ditto. * gimple-range.h: Add gimple-range-fold.h to include files. Change GIMPLE_RANGE_STMT_H to GIMPLE_RANGE_H. (gimple_range_handler): Relocate to gimple-range-fold.h. (gimple_range_ssa_p): Ditto. (range_compatible_p): Ditto. (class fur_source): Ditto. (class fur_stmt): Ditto. (class fold_using_range): Ditto. (gimple_range_calc_op1): Relocate to gimple-range-gori.h (gimple_range_calc_op2): Ditto.