From 8934830333933349d41e62f9fd6a3d21ab71150c Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Sat, 10 Jun 2023 16:41:20 -0400 Subject: [PATCH 13/17] Remove type from range_op_handler table selection With the unified table complete, we no loonger need to specify a type to choose a table when setting a range_op_handler. * gimple-range-gori.cc (gori_compute::condexpr_adjust): Do not pass type. * gimple-range-op.cc (get_code): Rename from get_code_and_type and simplify. (gimple_range_op_handler::supported_p): No need for type. (gimple_range_op_handler::gimple_range_op_handler): Ditto. (cfn_copysign::fold_range): Ditto. (cfn_ubsan::fold_range): Ditto. * ipa-cp.cc (ipa_vr_operation_and_type_effects): Ditto. * ipa-fnsummary.cc (evaluate_conditions_for_known_args): Ditto. * range-op-float.cc (operator_plus::op1_range): Ditto. (operator_mult::op1_range): Ditto. (range_op_float_tests): Ditto. * range-op.cc (get_op_handler): Remove. (range_op_handler::set_op_handler): Remove. (operator_plus::op1_range): No need for type. (operator_minus::op1_range): Ditto. (operator_mult::op1_range): Ditto. (operator_exact_divide::op1_range): Ditto. (operator_cast::op1_range): Ditto. (perator_bitwise_not::fold_range): Ditto. (operator_negate::fold_range): Ditto. * range-op.h (range_op_handler::range_op_handler): Remove type param. (range_cast): No need for type. (range_op_table::operator[]): Check for enum_code >= 0. * tree-data-ref.cc (compute_distributive_range): No need for type. * tree-ssa-loop-unswitch.cc (unswitch_predicate): Ditto. * value-query.cc (range_query::get_tree_range): Ditto. * value-relation.cc (relation_oracle::validate_relation): Ditto. * vr-values.cc (range_of_var_in_loop): Ditto. (simplify_using_ranges::fold_cond_with_ops): Ditto. --- gcc/gimple-range-gori.cc | 2 +- gcc/gimple-range-op.cc | 42 ++++++++++------------------------- gcc/ipa-cp.cc | 6 ++--- gcc/ipa-fnsummary.cc | 6 ++--- gcc/range-op-float.cc | 6 ++--- gcc/range-op.cc | 39 ++++++++------------------------ gcc/range-op.h | 10 +++------ gcc/tree-data-ref.cc | 4 ++-- gcc/tree-ssa-loop-unswitch.cc | 2 +- gcc/value-query.cc | 5 ++--- gcc/value-relation.cc | 2 +- gcc/vr-values.cc | 6 ++--- 12 files changed, 43 insertions(+), 87 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index a1c8d51e484..abc70cd54ee 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -1478,7 +1478,7 @@ gori_compute::condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond, tree type = TREE_TYPE (gimple_assign_rhs1 (cond_def)); if (!range_compatible_p (type, TREE_TYPE (gimple_assign_rhs2 (cond_def)))) return false; - range_op_handler hand (gimple_assign_rhs_code (cond_def), type); + range_op_handler hand (gimple_assign_rhs_code (cond_def)); if (!hand) return false; diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index b6b10e47b78..4cbc981ee04 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -94,28 +94,14 @@ gimple_range_base_of_assignment (const gimple *stmt) // If statement is supported by range-ops, set the CODE and return the TYPE. -static tree -get_code_and_type (gimple *s, enum tree_code &code) +static inline enum tree_code +get_code (gimple *s) { - tree type = NULL_TREE; - code = NOP_EXPR; - if (const gassign *ass = dyn_cast (s)) - { - code = gimple_assign_rhs_code (ass); - // The LHS of a comparison is always an int, so we must look at - // the operands. - if (TREE_CODE_CLASS (code) == tcc_comparison) - type = TREE_TYPE (gimple_assign_rhs1 (ass)); - else - type = TREE_TYPE (gimple_assign_lhs (ass)); - } - else if (const gcond *cond = dyn_cast (s)) - { - code = gimple_cond_code (cond); - type = TREE_TYPE (gimple_cond_lhs (cond)); - } - return type; + return gimple_assign_rhs_code (ass); + if (const gcond *cond = dyn_cast (s)) + return gimple_cond_code (cond); + return ERROR_MARK; } // If statement S has a supported range_op handler return TRUE. @@ -123,9 +109,8 @@ get_code_and_type (gimple *s, enum tree_code &code) bool gimple_range_op_handler::supported_p (gimple *s) { - enum tree_code code; - tree type = get_code_and_type (s, code); - if (type && range_op_handler (code, type)) + enum tree_code code = get_code (s); + if (range_op_handler (code)) return true; if (is_a (s) && gimple_range_op_handler (s)) return true; @@ -135,14 +120,11 @@ gimple_range_op_handler::supported_p (gimple *s) // Construct a handler object for statement S. gimple_range_op_handler::gimple_range_op_handler (gimple *s) + : range_op_handler (get_code (s)) { - enum tree_code code; - tree type = get_code_and_type (s, code); m_stmt = s; m_op1 = NULL_TREE; m_op2 = NULL_TREE; - if (type) - set_op_handler (code, type); if (m_operator) switch (gimple_code (m_stmt)) @@ -382,8 +364,8 @@ public: const frange &rh, relation_trio) const override { frange neg; - range_op_handler abs_op (ABS_EXPR, type); - range_op_handler neg_op (NEGATE_EXPR, type); + range_op_handler abs_op (ABS_EXPR); + range_op_handler neg_op (NEGATE_EXPR); if (!abs_op || !abs_op.fold_range (r, type, lh, frange (type))) return false; if (!neg_op || !neg_op.fold_range (neg, type, r, frange (type))) @@ -1091,7 +1073,7 @@ public: virtual bool fold_range (irange &r, tree type, const irange &lh, const irange &rh, relation_trio rel) const { - range_op_handler handler (m_code, type); + range_op_handler handler (m_code); gcc_checking_assert (handler); bool saved_flag_wrapv = flag_wrapv; diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 0f37bb5e336..0bbd289078d 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -1911,7 +1911,7 @@ ipa_vr_operation_and_type_effects (value_range *dst_vr, if (!irange::supports_p (dst_type) || !irange::supports_p (src_type)) return false; - range_op_handler handler (operation, dst_type); + range_op_handler handler (operation); return (handler && handler.fold_range (*dst_vr, dst_type, *src_vr, value_range (dst_type)) @@ -1970,7 +1970,7 @@ ipa_value_range_from_jfunc (ipa_node_params *info, cgraph_edge *cs, value_range op_res, res; tree op = ipa_get_jf_pass_through_operand (jfunc); value_range op_vr; - range_op_handler handler (operation, vr_type); + range_op_handler handler (operation); ipa_range_set_and_normalize (op_vr, op); @@ -2767,7 +2767,7 @@ propagate_vr_across_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc, tree op = ipa_get_jf_pass_through_operand (jfunc); value_range op_vr; value_range op_res,res; - range_op_handler handler (operation, operand_type); + range_op_handler handler (operation); ipa_range_set_and_normalize (op_vr, op); diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc index b328bb8ce14..eae2f949f48 100644 --- a/gcc/ipa-fnsummary.cc +++ b/gcc/ipa-fnsummary.cc @@ -491,7 +491,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node, value_range res; if (!op->val[0]) { - range_op_handler handler (op->code, op->type); + range_op_handler handler (op->code); if (!handler || !res.supports_type_p (op->type) || !handler.fold_range (res, op->type, vr, @@ -501,7 +501,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node, else if (!op->val[1]) { value_range op0; - range_op_handler handler (op->code, op->type); + range_op_handler handler (op->code); ipa_range_set_and_normalize (op0, op->val[0]); @@ -520,7 +520,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node, { value_range res; value_range val_vr; - range_op_handler handler (c->code, boolean_type_node); + range_op_handler handler (c->code); ipa_range_set_and_normalize (val_vr, c->val); diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 757484a9de9..24f2235884f 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -2244,7 +2244,7 @@ operator_plus::op1_range (frange &r, tree type, const frange &lhs, { if (lhs.undefined_p ()) return false; - range_op_handler minus (MINUS_EXPR, type); + range_op_handler minus (MINUS_EXPR); if (!minus) return false; frange wlhs = float_widen_lhs_range (type, lhs); @@ -2361,7 +2361,7 @@ operator_mult::op1_range (frange &r, tree type, { if (lhs.undefined_p ()) return false; - range_op_handler rdiv (RDIV_EXPR, type); + range_op_handler rdiv (RDIV_EXPR); if (!rdiv) return false; frange wlhs = float_widen_lhs_range (type, lhs); @@ -2716,7 +2716,7 @@ range_op_float_tests () ASSERT_EQ (r, r1); // [-INF,+INF] + [-INF,+INF] could be a NAN. - range_op_handler plus (PLUS_EXPR, float_type_node); + range_op_handler plus (PLUS_EXPR); r0.set_varying (float_type_node); r1.set_varying (float_type_node); r0.clear_nan (); diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 046b7691bb6..3e8b1222b1c 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -125,30 +125,11 @@ unified_table::unified_table () // set (MAX_EXPR, op_max); } -// The tables are hidden and accessed via a simple extern function. - -range_operator * -get_op_handler (enum tree_code code, tree) -{ - return unified_tree_table[code]; -} - range_op_handler::range_op_handler () { m_operator = NULL; } -void -range_op_handler::set_op_handler (tree_code code, tree type) -{ - m_operator = get_op_handler (code, type); -} - -range_op_handler::range_op_handler (tree_code code, tree type) -{ - set_op_handler (code, type); -} - // Constructing without a type must come from the unified table. range_op_handler::range_op_handler (tree_code code) @@ -1692,7 +1673,7 @@ operator_plus::op1_range (irange &r, tree type, if (lhs.undefined_p ()) return false; // Start with the default operation. - range_op_handler minus (MINUS_EXPR, type); + range_op_handler minus (MINUS_EXPR); if (!minus) return false; bool res = minus.fold_range (r, type, lhs, op2); @@ -1908,7 +1889,7 @@ operator_minus::op1_range (irange &r, tree type, if (lhs.undefined_p ()) return false; // Start with the default operation. - range_op_handler minus (PLUS_EXPR, type); + range_op_handler minus (PLUS_EXPR); if (!minus) return false; bool res = minus.fold_range (r, type, lhs, op2); @@ -2046,8 +2027,7 @@ operator_mult::op1_range (irange &r, tree type, wide_int offset; if (op2.singleton_p (offset) && offset != 0) - return range_op_handler (TRUNC_DIV_EXPR, type).fold_range (r, type, - lhs, op2); + return range_op_handler (TRUNC_DIV_EXPR).fold_range (r, type, lhs, op2); return false; } @@ -2375,7 +2355,7 @@ operator_exact_divide::op1_range (irange &r, tree type, // the time however. // If op2 is a multiple of 2, we would be able to set some non-zero bits. if (op2.singleton_p (offset) && offset != 0) - return range_op_handler (MULT_EXPR, type).fold_range (r, type, lhs, op2); + return range_op_handler (MULT_EXPR).fold_range (r, type, lhs, op2); return false; } @@ -2946,9 +2926,8 @@ operator_cast::op1_range (irange &r, tree type, // Add this to the unsigned LHS range(s). int_range_max lim_range (type, lim, lim); int_range_max lhs_neg; - range_op_handler (PLUS_EXPR, type).fold_range (lhs_neg, type, - converted_lhs, - lim_range); + range_op_handler (PLUS_EXPR).fold_range (lhs_neg, type, + converted_lhs, lim_range); // lhs_neg now has all the negative versions of the LHS. // Now union in all the values from SIGNED MIN (0x80000) to // lim-1 in order to fill in all the ranges with the upper @@ -3987,7 +3966,7 @@ operator_bitwise_not::fold_range (irange &r, tree type, // ~X is simply -1 - X. int_range<1> minusone (type, wi::minus_one (TYPE_PRECISION (type)), wi::minus_one (TYPE_PRECISION (type))); - return range_op_handler (MINUS_EXPR, type).fold_range (r, type, minusone, lh); + return range_op_handler (MINUS_EXPR).fold_range (r, type, minusone, lh); } bool @@ -4233,8 +4212,8 @@ operator_negate::fold_range (irange &r, tree type, if (empty_range_varying (r, type, lh, rh)) return true; // -X is simply 0 - X. - return range_op_handler (MINUS_EXPR, type).fold_range (r, type, - range_zero (type), lh); + return range_op_handler (MINUS_EXPR).fold_range (r, type, + range_zero (type), lh); } bool diff --git a/gcc/range-op.h b/gcc/range-op.h index 15c45137af2..295e5116dd1 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -185,7 +185,6 @@ class range_op_handler { public: range_op_handler (); - range_op_handler (enum tree_code code, tree type); range_op_handler (enum tree_code code); inline operator bool () const { return m_operator != NULL; } @@ -213,7 +212,6 @@ public: protected: unsigned dispatch_kind (const vrange &lhs, const vrange &op1, const vrange& op2) const; - void set_op_handler (enum tree_code code, tree type); range_operator *m_operator; }; @@ -226,9 +224,8 @@ range_cast (vrange &r, tree type) Value_Range tmp (r); Value_Range varying (type); varying.set_varying (type); - range_op_handler op (CONVERT_EXPR, type); // Call op_convert, if it fails, the result is varying. - if (!op || !op.fold_range (r, type, tmp, varying)) + if (!range_op_handler (CONVERT_EXPR).fold_range (r, type, tmp, varying)) { r.set_varying (type); return false; @@ -249,9 +246,8 @@ range_cast (Value_Range &r, tree type) // Ensure we are in the correct mode for the call to fold. r.set_type (type); - range_op_handler op (CONVERT_EXPR, type); // Call op_convert, if it fails, the result is varying. - if (!op || !op.fold_range (r, type, tmp, varying)) + if (!range_op_handler (CONVERT_EXPR).fold_range (r, type, tmp, varying)) { r.set_varying (type); return false; @@ -286,7 +282,7 @@ protected: inline range_operator * range_op_table::operator[] (enum tree_code code) { - gcc_checking_assert (code > 0 && code < MAX_TREE_CODES); + gcc_checking_assert (code >= 0 && code < MAX_TREE_CODES); return m_range_tree[code]; } diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc index b576cce6db6..6d3b7c2290e 100644 --- a/gcc/tree-data-ref.cc +++ b/gcc/tree-data-ref.cc @@ -593,7 +593,7 @@ compute_distributive_range (tree type, value_range &op0_range, gcc_assert (INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_TRAPS (type)); if (result_range) { - range_op_handler op (code, type); + range_op_handler op (code); if (!op.fold_range (*result_range, type, op0_range, op1_range)) result_range->set_varying (type); } @@ -640,7 +640,7 @@ compute_distributive_range (tree type, value_range &op0_range, range_cast (op0_range, ssizetype); range_cast (op1_range, ssizetype); value_range wide_range; - range_op_handler op (code, ssizetype); + range_op_handler op (code); bool saved_flag_wrapv = flag_wrapv; flag_wrapv = 1; if (!op.fold_range (wide_range, ssizetype, op0_range, op1_range)) diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc index 47255a4125d..619b50fb4bb 100644 --- a/gcc/tree-ssa-loop-unswitch.cc +++ b/gcc/tree-ssa-loop-unswitch.cc @@ -139,7 +139,7 @@ struct unswitch_predicate count = EDGE_SUCC (bb, 0)->count ().max (EDGE_SUCC (bb, 1)->count ()); if (irange::supports_p (TREE_TYPE (lhs))) { - auto range_op = range_op_handler (code, TREE_TYPE (lhs)); + auto range_op = range_op_handler (code); int_range<2> rhs_range (TREE_TYPE (rhs)); if (CONSTANT_CLASS_P (rhs)) { diff --git a/gcc/value-query.cc b/gcc/value-query.cc index a84f164d77b..adef93415b7 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -228,8 +228,7 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) if (COMPARISON_CLASS_P (expr) && !Value_Range::supports_type_p (TREE_TYPE (op0))) return false; - range_op_handler op (TREE_CODE (expr), - BINARY_CLASS_P (expr) ? type : TREE_TYPE (op0)); + range_op_handler op (TREE_CODE (expr)); if (op) { Value_Range r0 (TREE_TYPE (op0)); @@ -245,7 +244,7 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) } if (UNARY_CLASS_P (expr)) { - range_op_handler op (TREE_CODE (expr), type); + range_op_handler op (TREE_CODE (expr)); tree op0_type = TREE_TYPE (TREE_OPERAND (expr, 0)); if (op && Value_Range::supports_type_p (op0_type)) { diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index 65cf7694d40..7df2cd6e961 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -218,7 +218,7 @@ relation_oracle::validate_relation (relation_kind rel, vrange &op1, vrange &op2) return VREL_VARYING; // If there is no handler, leave the relation as is. - range_op_handler handler (code, t1); + range_op_handler handler (code); if (!handler) return rel; diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc index 86c1bf8ebc6..ac4a83c6097 100644 --- a/gcc/vr-values.cc +++ b/gcc/vr-values.cc @@ -292,8 +292,8 @@ range_of_var_in_loop (vrange &v, tree name, class loop *l, gimple *stmt, wide_int w = wide_int::from (nit, TYPE_PRECISION (type), TYPE_SIGN (type)); int_range<1> niter (type, w, w); int_range_max max_step; - range_op_handler mult_handler (MULT_EXPR, type); - range_op_handler plus_handler (PLUS_EXPR, type); + range_op_handler mult_handler (MULT_EXPR); + range_op_handler plus_handler (PLUS_EXPR); if (!mult_handler.fold_range (max_step, type, niter, rstep) || !plus_handler.fold_range (max_init, type, rinit, max_step)) return false; @@ -317,7 +317,7 @@ simplify_using_ranges::fold_cond_with_ops (enum tree_code code, tree type = TREE_TYPE (op0); int_range<1> res; - range_op_handler handler (code, type); + range_op_handler handler (code); if (handler && handler.fold_range (res, type, r0, r1)) { if (res == range_true (type)) -- 2.40.1