aboutsummaryrefslogtreecommitdiff
path: root/gcc/value-relation.h
AgeCommit message (Collapse)AuthorFilesLines
2025-01-02Update copyright years.Jakub Jelinek1-1/+1
2024-06-24Make transitive relations an oracle optionAndrew MacLeod1-1/+2
This patch makes processing of transitive relations configurable at dom_oracle creation. * tree-vrp.cc (execute_fast_vrp): Do not use transitive relations. * value-query.cc (range_query::create_relation_oracle): Add parameter to enable transitive relations. * value-query.h (range_query::create_relation_oracle): Likewise. * value-relation.h (dom_oracle::dom_oracle): Likewise. * value-relation.cc (dom_oracle::dom_oracle): Likewise. (dom_oracle::register_transitives): Check transitive flag.
2024-05-23Rename relation oracle and API.Andrew MacLeod1-22/+17
With more oracles incoming, rename the range_query oracle () method to relation (), and remove the redundant 'relation' text from register and query methods, resulting in calls that look like: relation ()->record (...) and relation ()->query (...) * gimple-range-cache.cc (ranger_cache::dump_bb): Use m_relation. (ranger_cache::fill_block_cache): Likewise * gimple-range-fold.cc (fur_stmt::get_phi_operand): Use new names. (fur_depend::register_relation): Likewise. (fold_using_range::range_of_phi): Likewise. * gimple-range-path.cc (path_range_query::path_range_query): Likewise. (path_range_query::~path_range_query): Likewise. (ath_range_query::compute_ranges): Likewise. (jt_fur_source::register_relation): Likewise. (jt_fur_source::query_relation): Likewise. (path_range_query::maybe_register_phi_relation): Likewise. * gimple-range-path.h (get_path_oracle): Likewise. * gimple-range.cc (gimple_ranger::gimple_ranger): Likewise. (gimple_ranger::~gimple_ranger): Likewise. * value-query.cc (range_query::create_relation_oracle): Likewise. (range_query::destroy_relation_oracle): Likewise. (range_query::share_oracles): Likewise. (range_query::range_query): Likewise. * value-query.h (value_query::relation): Rename from oracle. (m_relation): Rename from m_oracle. * value-relation.cc (relation_oracle::query): Rename from query_relation. (equiv_oracle::query): Likewise. (equiv_oracle::record): Rename from register_relation. (relation_oracle::record): Likewise. (dom_oracle::record): Likewise. (dom_oracle::query): Rename from query_relation. (path_oracle::record): Rename from register_relation. (path_oracle::query): Rename from query_relation. * value-relation.h (*::record): Rename from register_relation. (*::query): Rename from query_relation.
2024-05-23Move to an always available relation oracle.Andrew MacLeod1-16/+16
This eliminates the need to check if the relation oracle pointer is NULL before every call by providing a default oracle which does nothing. REmove unused routines, and Unify register_relation method names. * gimple-range-cache.cc (ranger_cache::dump_bb): Remove check for NULL oracle pointer. (ranger_cache::fill_block_cache): Likewise. * gimple-range-fold.cc (fur_stmt::get_phi_operand): Likewise. (fur_depend::fur_depend): Likewise. (fur_depend::register_relation): Likewise, use qury_relation. (fold_using_range::range_of_phi): Likewise. (fold_using_range::relation_fold_and_or): Likewise. * gimple-range-fold.h (fur_source::m_oracle): Delete. Oracle can be accessed dirctly via m_query now. * gimple-range-path.cc (path_range_query::path_range_query): Adjust for oracle reference pointer. (path_range_query::compute_ranges): Likewise. (jt_fur_source::jt_fur_source): Adjust for no m_oracle member. (jt_fur_source::register_relation): Do not check for NULL pointer. (jt_fur_source::query_relation): Likewise. * gimple-range.cc (gimple_ranger::gimple_ranger): Adjust for reference pointer. * value-query.cc (default_relation_oracle): New. (range_query::create_relation_oracle): Relocate from header. Ensure not being added to global query. (range_query::destroy_relation_oracle): Relocate from header. (range_query::range_query): Initailize to default oracle. (ange_query::~range_query): Call destroy_relation_oracle. * value-query.h (class range_query): Adjust prototypes. (range_query::create_relation_oracle): Move to source file. (range_query::destroy_relation_oracle): Move to source file. * value-relation.cc (relation_oracle::validate_relation): Delete. (relation_oracle::register_stmt): Rename to register_relation. (relation_oracle::register_edge): Likewise. * value-relation.h (register_stmt): Rename to register_relation and provide default function in base class. (register_edge): Likewise. (relation_oracle::validate_relation): Delete. (relation_oracle::query_relation): Provide default in base class. (relation_oracle::dump): Likewise. (relation_oracle::equiv_set): Likewise. (default_relation_oracle): New extenal reference. (partial_equiv_set, add_partial_equiv): Move to protected.
2024-05-23Move all relation queries into relation_oracle.Andrew MacLeod1-1/+3
Move relation queries from range_query object into the relation oracle. * gimple-range-cache.cc (ranger_cache::ranger_cache): Call create_relation_oracle. (ranger_cache::~ranger_cache): Call destroy_relation_oracle. * gimple-range-fold.cc (fur_stmt::get_phi_operand): Check for relation oracle bnefore calling query_relation. (fold_using_range::range_of_phi): Likewise. * gimple-range-path.cc (path_range_query::~path_range_query): Set relation oracle pointer to NULL when done. * gimple-range.cc (gimple_ranger::~gimple_ranger): Likewise. * value-query.cc (range_query::~range_query): Ensure any relation oracle is destroyed. (range_query::query_relation): relocate to relation_oracle object. * value-query.h (class range_query): Adjust method proototypes. (range_query::create_relation_oracle): New. (range_query::destroy_relation_oracle): New. * value-relation.cc (relation_oracle::query_relation): Relocate from range query class. * value-relation.h (Call relation_oracle): New prototypes.
2024-01-03Update copyright years.Jakub Jelinek1-1/+1
2023-10-09Ensure float equivalences include + and - zero.Andrew MacLeod1-0/+3
A floating point equivalence may not properly reflect both signs of zero, so be pessimsitic and ensure both signs are included. PR tree-optimization/111694 gcc/ * gimple-range-cache.cc (ranger_cache::fill_block_cache): Adjust equivalence range. * value-relation.cc (adjust_equivalence_range): New. * value-relation.h (adjust_equivalence_range): New prototype. gcc/testsuite/ * gcc.dg/pr111694.c: New.
2023-10-09Remove unused get_identity_relation.Andrew MacLeod1-3/+0
Turns out we didnt need this as there is no unordered relations managed by the oracle. * gimple-range-gori.cc (gori_compute::compute_operand1_range): Do not call get_identity_relation. (gori_compute::compute_operand2_range): Ditto. * value-relation.cc (get_identity_relation): Remove. * value-relation.h (get_identity_relation): Remove protyotype.
2023-08-03Provide a routine for NAME == NAME relation.Andrew MacLeod1-0/+3
We've been assuming x == x s VREL_EQ in GORI, but this is not always going to be true with floating point. Provide an API to return the relation. * gimple-range-gori.cc (gori_compute::compute_operand1_range): Use identity relation. (gori_compute::compute_operand2_range): Ditto. * value-relation.cc (get_identity_relation): New. * value-relation.h (get_identity_relation): New prototype.
2023-04-26Quicker relation check.Andrew MacLeod1-0/+1
If either of the SSA names in a comparison do not have any equivalences or relations, we can short-circuit the check slightly. * value-relation.cc (dom_oracle::query_relation): Check early for lack of any relation. * value-relation.h (equiv_oracle::has_equiv_p): New.
2023-03-28Fix compute_operand when op1 == op2 symbolically.Andrew MacLeod1-7/+0
First, class value_relation should not sanitize records. just create what is asked. Second., if there is not a relation record, compute_operand was creating one for op1 == op2 if op1 and op2 were the same symbol. This is not the correct way to communicate the information, as that record will continue to be passed along the GORI unwind chain. Instead, simply pass that information locally to the opX_range routine for only the current statement. PR tree-optimization/109265 PR tree-optimization/109274 gcc/ * gimple-range-gori.cc (gori_compute::compute_operand_range): Do not create a relation record is op1 and op2 are the same symbol. (gori_compute::compute_operand1_range): Pass op1 == op2 to the handler for this stmt, but create a new record only if this statement generates a relation based on the ranges. (gori_compute::compute_operand2_range): Ditto. * value-relation.h (value_relation::set_relation): Always create the record that is requested. gcc/testsuite/ * gcc.dg/pr109274.c: New. * gfortran.dg/pr109265.f90: New.
2023-03-23ranger: Ranger meets aspellJakub Jelinek1-9/+9
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-03-21Terminate GORI calculations if a relation is not relevant.Andrew MacLeod1-1/+1
We currently allow VARYING lhs GORI calculations to continue if there is a relation present in the hope it will eventually better refine a result. This adds a check that the relation is relevant to the outgoing range calculation first. If it is not relevant, stop calculating. PR tree-optimization/109192 * gimple-range-gori.cc (gori_compute::compute_operand_range): Terminate gori calculations if a relation is not relevant. * value-relation.h (value_relation::set_relation): Allow equality between op1 and op2 if they are the same.
2023-01-31Properly set GORI relation trios.Andrew MacLeod1-0/+1
When relation trios were added to GORI, there was only one use. As they are utilized more by range-ops, it is apparent that the implelemtation was not complete. This patch fleshes it out completely so that every GORI operation has a complete relation trio. * gimple-range-gori.cc (gori_compute::compute_operand_range): Do not abort calculations if there is a valid relation available. (gori_compute::refine_using_relation): Pass correct relation trio. (gori_compute::compute_operand1_range): Create trio and use it. (gori_compute::compute_operand2_range): Ditto. * range-op.cc (operator_plus::op1_range): Use correct trio member. (operator_minus::op1_range): Use correct trio member. * value-relation.cc (value_relation::create_trio): New. * value-relation.h (value_relation::create_trio): New prototype.
2023-01-02Update copyright years.Jakub Jelinek1-1/+1
2022-10-17Add relation_trio class for range-ops.Andrew MacLeod1-12/+107
There are 3 possible relations range-ops might care about, but only the one most likely to be needed is supplied. This patch provides a new class relation_trio which allows 3 relations to be passed in a single word. fold_range (), op1_range (), and op2_range () are adjusted to take a relation_trio class instead of a relation_kind, then the routine can extract which relation it wants to work with. * gimple-range-fold.cc (fold_using_range::range_of_range_op): Provide relation_trio class. * gimple-range-gori.cc (gori_compute::refine_using_relation): Provide relation_trio class. (gori_compute::refine_using_relation): Ditto. (gori_compute::compute_operand1_range): Provide lhs_op2 and op1_op2 relations via relation_trio class. (gori_compute::compute_operand2_range): Ditto. * gimple-range-op.cc (gimple_range_op_handler::calc_op1): Use relation_trio instead of relation_kind. (gimple_range_op_handler::calc_op2): Ditto. (*::fold_range): Ditto. * gimple-range-op.h (gimple_range_op::calc_op1): Adjust prototypes. (gimple_range_op::calc_op2): Adjust prototypes. * range-op-float.cc (*::fold_range): Use relation_trio instead of relation_kind. (*::op1_range): Ditto. (*::op2_range): Ditto. * range-op.cc (*::fold_range): Use relation_trio instead of relation_kind. (*::op1_range): Ditto. (*::op2_range): Ditto. * range-op.h (class range_operator): Adjust prototypes. (class range_operator_float): Ditto. (class range_op_handler): Adjust prototypes. (relop_early_resolve): Pickup op1_op2 relation from relation_trio. * value-relation.cc (VREL_LAST): Adjust use to be one past the end of the enum. (relation_oracle::validate_relation): Use relation_trio in call to fold_range. * value-relation.h (enum relation_kind_t): Add VREL_LAST as final element. (class relation_trio): New. (TRIO_VARYING, TRIO_SHIFT, TRIO_MASK): New.
2022-10-17Don't set useless relations.Andrew MacLeod1-0/+7
The oracle will not register nonssense/useless relations, class value_relation shouldn't either. * value-relation.cc (value_relation::dump): Change message. * value-relation.h (value_relation::set_relation): If op1 is the same as op2 do not create a relation.
2022-10-13Add equivalence iterator to relation oracle.Andrew MacLeod1-3/+38
Instead of looping over an exposed equivalence bitmap, provide iterators to loop over equivalences, partial equivalences, or both. * gimple-range-cache.cc (ranger_cache::fill_block_cache): Use iterator. * value-relation.cc (equiv_relation_iterator::equiv_relation_iterator): New. (equiv_relation_iterator::next): New. (equiv_relation_iterator::get_name): New. * value-relation.h (class relation_oracle): Privatize some methods. (class equiv_relation_iterator): New. (FOR_EACH_EQUIVALENCE): New. (FOR_EACH_PARTIAL_EQUIV): New. (FOR_EACH_PARTIAL_AND_FULL_EQUIV): New.
2022-10-13Add partial equivalence support to the relation oracle.Andrew MacLeod1-2/+76
This provides enhancements to the equivalence oracle to also track partial equivalences. They are tracked similar to equivalences, except it tracks a 'slice' of another ssa name. 8, 16, 32 and 64 bit slices are tracked. This will allow casts and mask of the same value to compare equal. * value-relation.cc (equiv_chain::dump): Don't print empty equivalences. (equiv_oracle::equiv_oracle): Allocate a partial equiv table. (equiv_oracle::~equiv_oracle): Release the partial equiv table. (equiv_oracle::add_partial_equiv): New. (equiv_oracle::partial_equiv_set): New. (equiv_oracle::partial_equiv): New. (equiv_oracle::query_relation): Check for partial equivs too. (equiv_oracle::dump): Also dump partial equivs. (dom_oracle::register_relation): Handle partial equivs. (dom_oracle::query_relation): Check for partial equivs. * value-relation.h (enum relation_kind_t): Add partial equivs. (relation_partial_equiv_p): New. (relation_equiv_p): New. (class pe_slice): New. (class equiv_oracle): Add prototypes. (pe_to_bits): New. (bits_to_pe): New. (pe_min): New.
2022-09-29Process unsigned overflow relations for plus and minus is range-ops.Andrew MacLeod1-0/+2
If a relation is available, calculate overflow and normal ranges. Then apply as appropriate. gcc/ * range-op.cc (plus_minus_ranges): New. (adjust_op1_for_overflow): New. (operator_plus::op1_range): Use new adjustment. (operator_plus::op2_range): Ditto. (operator_minus::op1_range): Ditto. * value-relation.h (relation_lt_le_gt_ge_p): New. gcc/testsuite/ * gcc.dg/tree-ssa/pr79095.c: Test evrp pass rather than vrp1.
2022-09-29Move class value_relation the header file.Andrew MacLeod1-0/+57
* value-relation.cc (class value_relation): Move to .h file. (value_relation::set_relation): Ditto. (value_relation::value_relation): ditto. * value-relation.h (class value_relation): Move from .cc file. (value_relation::set_relation): Ditto (value_relation::value_relation): Ditto.
2022-08-17Reset root oracle from path_oracle::reset_path.Aldy Hernandez1-1/+1
When we cross a backedge in the path solver, we reset the path relations and nuke the root oracle. However, we forget to reset it for the next path. This is causing us to miss threads because subsequent paths will have no root oracle to use. With this patch we get 201 more threads in the threadfull passes in my .ii files and 118 more overall (DOM gets less because threadfull runs before). Normally, I'd recommend this for the GCC 12 branch, but considering how sensitive other passes are to jump threading, and that there is no PR associated with this, perhaps we should leave this out. Up to the release maintainers of course. gcc/ChangeLog: * gimple-range-path.cc (path_range_query::compute_ranges_in_block): Remove set_root_oracle call. (path_range_query::compute_ranges): Pass ranger oracle to reset_path. * value-relation.cc (path_oracle::reset_path): Set root oracle. * value-relation.h (path_oracle::reset_path): Add root oracle argument.
2022-07-05Provide a relation verification mechanism.Andrew MacLeod1-3/+7
Provide a relation oracle API which validates a relation between 2 ranges. This allows relation queries that are symbolicly true to be overridden by range specific information. ie. x == x is true symbolically, but for floating point a NaN may invalidate this assumption. * value-relation.cc (relation_to_code): New vector. (relation_oracle::validate_relation): New. (set_relation): Allow ssa1 == ssa2 to be registered. * value-relation.h (validate_relation): New prototype. (query_relation): Make internal variant protected.
2022-06-15value-relation.h: add 'final' and 'override' to relation_oracle vfunc implsDavid Malcolm1-17/+21
gcc/ChangeLog: * value-relation.h: Add "final" and "override" to relation_oracle vfunc implementations as appropriate. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-05-13Move VREL values to their own enumerated type.Andrew MacLeod1-10/+16
Re-using some common things like EQ_EXPR and other relationals made certain things easier, but complicated debugging and added extra overhead when accessing lookup tables. With forthcoming additional relation types, it makes more sense to simple have a distinct relation kind. * gimple-range-fold.cc (fold_using_range::range_of_phi): Use new VREL_* enumerated values. * gimple-range-path.cc (maybe_register_phi_relation): Ditto. * range-op.cc (*::lhs_op1_relation): Return relation_kind, and use new VREL enumerated values. (*::lhs_op2_relation): Ditto. (*::op1_op2_relation): Ditto. (*::fold_range): Use new VREL enumerated values. (minus_op1_op2_relation_effect): Ditto. (range_relational_tests): Ditto. * range-op.h (fold_range, op1_range, op2_range): Use VREL_VARYING. (lhs_op1_relation, lhs_op2_relation, op1_op2_relation): Return relation_kind. (*_op1_op2_relation): Return relation_kind. (relop_early_resolve): Use VREL_UNDEFINED. * value-query.cc (range_query::query_relation): Use VREL_VARYING. * value-relation.cc (VREL_LAST): Change enumerated value. (vrel_range_assert): Delete. (print_relation): Remove range assert. (rr_negate_table): Adjust table to use new enumerated values.. (relation_negate): Remove range assert. (rr_swap_table): Adjust. (relation_swap): Remove range assert. (rr_intersect_table): Adjust. (relation_intersect): Remove range assert. (rr_union_table): Adjust. (relation_union): Remove range assert. (rr_transitive_table): Adjust. (relation_transitive): Remove range assert. (equiv_oracle::query_relation): Use new VREL enumerated values. (equiv_oracle::register_relation): Ditto. (relation_oracle::register_stmt): Ditto. (dom_oracle::set_one_relation): Ditto. (dom_oracle::register_transitives): Ditto. (dom_oracle::query_relation): Ditto. (path_oracle::register_relation): Ditto. (path_oracle::query_relation): Ditto. * value-relation.h (enum relation_kind_t): New relation_kind. (*_op1_op2_relation): Adjust prototypes.
2022-03-07Fix up duplicated duplicated words in commentsJakub Jelinek1-1/+1
Like in r10-7215-g700d4cb08c88aec37c13e21e63dd61fd698baabc 2 years ago, I've run grep -v 'long long\|optab optab\|template template\|double double' *.{[chS],cc} */*.{[chS],cc} *.def config/*/* 2>/dev/null | grep ' \([a-zA-Z]\+\) \1 ' and for the cases that looked clearly wrong changed them, mostly by removing one of the duplicated words but in some cases with other changes. 2022-03-07 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-ssa-propagate.cc: Fix up duplicated word issue in a comment. * config/riscv/riscv.cc: Likewise. * config/darwin.h: Likewise. * config/i386/i386.cc: Likewise. * config/aarch64/thunderx3t110.md: Likewise. * config/aarch64/fractional-cost.h: Likewise. * config/vax/vax.cc: Likewise. * config/rs6000/pcrel-opt.md: Likewise. * config/rs6000/predicates.md: Likewise. * ctfc.h: Likewise. * tree-ssa-uninit.cc: Likewise. * value-relation.h: Likewise. * gimple-range-gori.cc: Likewise. * ipa-polymorphic-call.cc: Likewise. * pointer-query.cc: Likewise. * ipa-sra.cc: Likewise. * internal-fn.cc: Likewise. * varasm.cc: Likewise. * gimple-ssa-warn-access.cc: Likewise. gcc/analyzer/ * store.cc: Fix up duplicated word issue in a comment. * analyzer.cc: Likewise. * engine.cc: Likewise. * sm-taint.cc: Likewise. gcc/c-family/ * c-attribs.cc: Fix up duplicated word issue in a comment. gcc/cp/ * cvt.cc: Fix up duplicated word issue in a comment. * pt.cc: Likewise. * module.cc: Likewise. * coroutines.cc: Likewise. gcc/fortran/ * trans-expr.cc: Fix up duplicated word issue in a comment. * gfortran.h: Likewise. * scanner.cc: Likewise. gcc/jit/ * libgccjit.h: Fix up duplicated word issue in a comment.
2022-01-21Reset relations when crossing backedges.Aldy Hernandez1-0/+1
As discussed in PR103721, the problem here is that we are crossing a backedge and causing us to use relations from a previous iteration of a loop. This handles the testcases in both PR103721 and PR104067 which are variants of the same thing. Tested on x86-64 Linux with the usual regstrap as well as verifying the thread count before and after the patch. The number of threads is reduced by a miniscule amount. gcc/ChangeLog: PR tree-optimization/103721 * gimple-range-path.cc (path_range_query::relations_may_be_invalidated): New. (path_range_query::compute_ranges_in_block): Reset relations if they may be invalidated. (path_range_query::maybe_register_phi_relation): Exit if relations may be invalidated on incoming edge. (path_range_query::compute_phi_relations): Pass incoming PHI edge to maybe_register_phi_relation. * gimple-range-path.h (relations_may_be_invalidated): New. (maybe_register_phi_relation): Pass edge instead of tree. * tree-ssa-threadbackward.cc (back_threader::back_threader): Mark DFS edges. * value-relation.cc (path_oracle::path_oracle): Call mark_dfs_back_edges. (path_oracle::register_relation): Add SSA names to m_registered bitmap. (path_oracle::reset_path): Clear m_registered bitmap. * value-relation.h (path_oracle::set_root_oracle): New. gcc/testsuite/ChangeLog: * gcc.dg/pr103721-2.c: New test. * gcc.dg/pr103721.c: New test.
2022-01-20Only add equivalencies that are still valid.Andrew MacLeod1-0/+2
When equivalencies sets are merged, each member of the set should be queried to ensure its still valid rather than a bulk union. * value-relation.cc (relation_oracle::valid_equivs): Query and add if valid members of a set. (equiv_oracle::register_equiv): Call valid_equivs rather than bitmap direct operations. (path_oracle::register_equiv): Ditto. * value-relation.h (relation_oracle::valid_equivs): New prototype.
2022-01-18Limit the number of relations registered per basic block.Andrew MacLeod1-0/+1
In pathological cases, the number of transitive relations being added is potentially quadratic. Lookups for relations in a block is linear in nature, so simply limit the number of relations to some reasonable number. PR tree-optimization/104038 * doc/invoke.texi (relation-block-limit): New. * params.opt (relation-block-limit): New. * value-relation.cc (dom_oracle::register_relation): Check for NULL record before invoking transitive registery. (dom_oracle::set_one_relation): Check limit before creating record. (dom_oracle::register_transitives): Stop when no record created. * value-relation.h (relation_chain_head::m_num_relations): New.
2022-01-03Update copyright years.Jakub Jelinek1-1/+1
2021-11-06path oracle: Do not look at root oracle for killed defs.Aldy Hernandez1-0/+1
The problem here is that we are incorrectly threading 41->20->21 here: <bb 35> [local count: 56063504182]: _134 = M.10_120 + 1; if (_71 <= _134) goto <bb 19>; [11.00%] else goto <bb 41>; [89.00%] ... ... ... <bb 41> [local count: 49896518755]: <bb 20> [local count: 56063503181]: # lb_75 = PHI <_134(41), 1(18)> _117 = mstep_49 + lb_75; _118 = _117 + -1; _119 = mstep_49 + _118; M.10_120 = MIN_EXPR <_119, _71>; if (lb_75 > M.10_120) goto <bb 21>; [11.00%] else goto <bb 22>; [89.00%] First, lb_17 == _134 because of the PHI. Second, _134 > M.10_120 because of _134 = M.10_120 + 1. We then assume that lb_75 > M.10_120, but this is incorrect because M.10_120 was killed along the path. This incorrect thread causes the miscompilation in 527.cam4_r. Tested on x86-64 and ppc64le Linux. gcc/ChangeLog: PR tree-optimization/103061 * value-relation.cc (path_oracle::path_oracle): Initialize m_killed_defs. (path_oracle::killing_def): Set m_killed_defs. (path_oracle::query_relation): Do not look at the root oracle for killed defs. * value-relation.h (class path_oracle): Add m_killed_defs.
2021-10-22Disregard incoming equivalences to a path when defining a new one.Aldy Hernandez1-0/+1
The equivalence oracle creates a new equiv set at each def point, killing any incoming equivalences, however in the path sensitive oracle we create brand new equivalences at each PHI: BB4: BB8: x_5 = PHI <y_8(4)> Here we note that x_5 == y_8 at the end of the path. The current code is intersecting this new equivalence with previously known equivalences coming into the path. This is incorrect, as this is a new definition. This patch kills any known equivalence before we register a new one. This hasn't caused problems so far, but upcoming changes to the pipeline has us threading more aggressively and triggering corner cases where this causes incorrect code. I have tested this patch with the usual regstrap cycle. I have also hacked a compiler comparing the old and new behavior to see if we were previously threading paths where the decision was made due to invalid equivalences. Luckily, there were no such paths, but there were 22 paths in a set of .ii files where disregarding incoming relations allowed us to thread the path. This is a miniscule improvement, but we moved a handful of thredable paths earlier in the pipeline, which is always good. Tested on x86-64 Linux. Co-authored-by: Andrew MacLeod <amacleod@redhat.com> gcc/ChangeLog: * gimple-range-path.cc (path_range_query::compute_phi_relations): Kill any global relations we may know before registering a new one. * value-relation.cc (path_oracle::killing_def): New. * value-relation.h (path_oracle::killing_def): New.
2021-09-20Make each def a new equivalency record.Andrew MacLeod1-1/+2
Create a new equivalency set at each def point killing any equivalencies coming into the block from back edges. Do not add equivalences for PHI arguments defined in this block. * value-relation.cc (equiv_oracle::register_initial_def): New. (equiv_oracle::register_relation): Call register_initial_def. (equiv_oracle::add_equiv_to_block): New. Split register_relation. (relation_oracle::register_stmt): Check def block of PHI arguments. * value-relation.h (equiv_oracle): Add new prototypes.
2021-09-17Provide a relation oracle for paths.Andrew MacLeod1-2/+49
This provides a path_oracle class which can optionally be used in conjunction with another oracle to track relations on a path as it is walked. * value-relation.cc (class equiv_chain): Move to header file. (path_oracle::path_oracle): New. (path_oracle::~path_oracle): New. (path_oracle::register_relation): New. (path_oracle::query_relation): New. (path_oracle::reset_path): New. (path_oracle::dump): New. * value-relation.h (class equiv_chain): Move to here. (class path_oracle): New.
2021-09-17Virtualize relation oracle and various cleanups.Andrew MacLeod1-18/+44
Standardize equiv_oracle API onto the new relation_oracle virtual base, and then have dom_oracle inherit from that. equiv_set always returns an equivalency set now, never NULL. EQ_EXPR requires symmetry now. Each SSA name must be in the other equiv set. Shuffle some routines around, simplify. * gimple-range-cache.cc (ranger_cache::ranger_cache): Create a DOM based oracle. * gimple-range-fold.cc (fur_depend::register_relation): Use register_stmt/edge routines. * value-relation.cc (equiv_chain::find): Relocate from equiv_oracle. (equiv_oracle::equiv_oracle): Create self equivalence cache. (equiv_oracle::~equiv_oracle): Release same. (equiv_oracle::equiv_set): Return entry from self equiv cache if there are no equivalences. (equiv_oracle::find_equiv_block): Move list find to equiv_chain. (equiv_oracle::register_relation): Rename from register_equiv. (relation_chain_head::find_relation): Relocate from dom_oracle. (relation_oracle::register_stmt): New. (relation_oracle::register_edge): New. (dom_oracle::*): Rename from relation_oracle. (dom_oracle::register_relation): Adjust to call equiv_oracle. (dom_oracle::set_one_relation): Split from register_relation. (dom_oracle::register_transitives): Consolidate 2 methods. (dom_oracle::find_relation_block): Move core to relation_chain. (dom_oracle::query_relation): Rename from find_relation_dom and adjust. * value-relation.h (class relation_oracle): New pure virtual base. (class equiv_oracle): Inherit from relation_oracle and adjust. (class dom_oracle): Rename from old relation_oracle and adjust.
2021-09-03Implement relation_oracle::debug.Aldy Hernandez1-0/+1
Tested on x86-64 Linux. gcc/ChangeLog: * value-relation.cc (relation_oracle::debug): New. * value-relation.h (relation_oracle::debug): New.
2021-08-24Add transitive operations to the relation oracle.Andrew MacLeod1-2/+7
When registering relations in the oracle, search for other relations which imply new transitive relations. gcc/ * value-relation.cc (rr_transitive_table): New. (relation_transitive): New. (value_relation::swap): Remove. (value_relation::apply_transitive): New. (relation_oracle::relation_oracle): Allocate a new tmp bitmap. (relation_oracle::register_relation): Call register_transitives. (relation_oracle::register_transitives): New. * value-relation.h (relation_oracle): Add new temporary bitmap and methods. gcc/testsuite/ * gcc.dg/predict-1.c: Disable evrp. * gcc.dg/tree-ssa/evrp-trans.c: New.
2021-06-22Initial value-relation code.Andrew MacLeod1-0/+159
This code provides a both an equivalence and relation oracle which can be accessed via a range_query object. This initial code drop includes the oracles and access them, but does not utilize them yet. * Makefile.in (OBJS): Add value-relation.o. * gimple-range.h: Adjust include files. * tree-data-ref.c: Adjust include file order. * value-query.cc (range_query::get_value_range): Default to no oracle. (range_query::query_relation): New. (range_query::query_relation): New. * value-query.h (class range_query): Adjust. * value-relation.cc: New. * value-relation.h: New.