diff options
author | Richard Sandiford <richard.sandiford@linaro.org> | 2017-10-10 16:55:34 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2017-10-10 16:55:34 +0000 |
commit | 8e6cdc90d41633e09a3a34bb8c6f71cf246101b2 (patch) | |
tree | c8d6aac483b647ae892778e9398965071da02686 /gcc/tree.c | |
parent | 3934b625ee2f522edf455191d1eaaa42e265a1d9 (diff) | |
download | gcc-8e6cdc90d41633e09a3a34bb8c6f71cf246101b2.zip gcc-8e6cdc90d41633e09a3a34bb8c6f71cf246101b2.tar.gz gcc-8e6cdc90d41633e09a3a34bb8c6f71cf246101b2.tar.bz2 |
Require wi::to_wide for trees
The wide_int routines allow things like:
wi::add (t, 1)
to add 1 to an INTEGER_CST T in its native precision. But we also have:
wi::to_offset (t) // Treat T as an offset_int
wi::to_widest (t) // Treat T as a widest_int
Recently we also gained:
wi::to_wide (t, prec) // Treat T as a wide_int in preccision PREC
This patch therefore requires:
wi::to_wide (t)
when operating on INTEGER_CSTs in their native precision. This is
just as efficient, and makes it clearer that a deliberate choice is
being made to treat the tree as a wide_int in its native precision.
This also removes the inconsistency that
a) INTEGER_CSTs in their native precision can be used without an accessor
but must use wi:: functions instead of C++ operators
b) the other forms need an explicit accessor but the result can be used
with C++ operators.
It also helps with SVE, where there's the additional possibility
that the tree could be a runtime value.
2017-10-10 Richard Sandiford <richard.sandiford@linaro.org>
gcc/
* wide-int.h (wide_int_ref_storage): Make host_dependent_precision
a template parameter.
(WIDE_INT_REF_FOR): Update accordingly.
* tree.h (wi::int_traits <const_tree>): Delete.
(wi::tree_to_widest_ref, wi::tree_to_offset_ref): New typedefs.
(wi::to_widest, wi::to_offset): Use them. Expand commentary.
(wi::tree_to_wide_ref): New typedef.
(wi::to_wide): New function.
* calls.c (get_size_range): Use wi::to_wide when operating on
trees as wide_ints.
* cgraph.c (cgraph_node::create_thunk): Likewise.
* config/i386/i386.c (ix86_data_alignment): Likewise.
(ix86_local_alignment): Likewise.
* dbxout.c (stabstr_O): Likewise.
* dwarf2out.c (add_scalar_info, gen_enumeration_type_die): Likewise.
* expr.c (const_vector_from_tree): Likewise.
* fold-const-call.c (host_size_t_cst_p, fold_const_call_1): Likewise.
* fold-const.c (may_negate_without_overflow_p, negate_expr_p)
(fold_negate_expr_1, int_const_binop_1, const_binop)
(fold_convert_const_int_from_real, optimize_bit_field_compare)
(all_ones_mask_p, sign_bit_p, unextend, extract_muldiv_1)
(fold_div_compare, fold_single_bit_test, fold_plusminus_mult_expr)
(pointer_may_wrap_p, expr_not_equal_to, fold_binary_loc)
(fold_ternary_loc, multiple_of_p, fold_negate_const, fold_abs_const)
(fold_not_const, round_up_loc): Likewise.
* gimple-fold.c (gimple_fold_indirect_ref): Likewise.
* gimple-ssa-warn-alloca.c (alloca_call_type_by_arg): Likewise.
(alloca_call_type): Likewise.
* gimple.c (preprocess_case_label_vec_for_gimple): Likewise.
* godump.c (go_output_typedef): Likewise.
* graphite-sese-to-poly.c (tree_int_to_gmp): Likewise.
* internal-fn.c (get_min_precision): Likewise.
* ipa-cp.c (ipcp_store_vr_results): Likewise.
* ipa-polymorphic-call.c
(ipa_polymorphic_call_context::ipa_polymorphic_call_context): Likewise.
* ipa-prop.c (ipa_print_node_jump_functions_for_edge): Likewise.
(ipa_modify_call_arguments): Likewise.
* match.pd: Likewise.
* omp-low.c (scan_omp_1_op, lower_omp_ordered_clauses): Likewise.
* print-tree.c (print_node_brief, print_node): Likewise.
* stmt.c (expand_case): Likewise.
* stor-layout.c (layout_type): Likewise.
* tree-affine.c (tree_to_aff_combination): Likewise.
* tree-cfg.c (group_case_labels_stmt): Likewise.
* tree-data-ref.c (dr_analyze_indices): Likewise.
(prune_runtime_alias_test_list): Likewise.
* tree-dump.c (dequeue_and_dump): Likewise.
* tree-inline.c (remap_gimple_op_r, copy_tree_body_r): Likewise.
* tree-predcom.c (is_inv_store_elimination_chain): Likewise.
* tree-pretty-print.c (dump_generic_node): Likewise.
* tree-scalar-evolution.c (iv_can_overflow_p): Likewise.
(simple_iv_with_niters): Likewise.
* tree-ssa-address.c (addr_for_mem_ref): Likewise.
* tree-ssa-ccp.c (ccp_finalize, evaluate_stmt): Likewise.
* tree-ssa-loop-ivopts.c (constant_multiple_of): Likewise.
* tree-ssa-loop-niter.c (split_to_var_and_offset)
(refine_value_range_using_guard, number_of_iterations_ne_max)
(number_of_iterations_lt_to_ne, number_of_iterations_lt)
(get_cst_init_from_scev, record_nonwrapping_iv)
(scev_var_range_cant_overflow): Likewise.
* tree-ssa-phiopt.c (minmax_replacement): Likewise.
* tree-ssa-pre.c (compute_avail): Likewise.
* tree-ssa-sccvn.c (vn_reference_fold_indirect): Likewise.
(vn_reference_maybe_forwprop_address, valueized_wider_op): Likewise.
* tree-ssa-structalias.c (get_constraint_for_ptr_offset): Likewise.
* tree-ssa-uninit.c (is_pred_expr_subset_of): Likewise.
* tree-ssanames.c (set_nonzero_bits, get_nonzero_bits): Likewise.
* tree-switch-conversion.c (collect_switch_conv_info, array_value_type)
(dump_case_nodes, try_switch_expansion): Likewise.
* tree-vect-loop-manip.c (vect_gen_vector_loop_niters): Likewise.
(vect_do_peeling): Likewise.
* tree-vect-patterns.c (vect_recog_bool_pattern): Likewise.
* tree-vect-stmts.c (vectorizable_load): Likewise.
* tree-vrp.c (compare_values_warnv, vrp_int_const_binop): Likewise.
(zero_nonzero_bits_from_vr, ranges_from_anti_range): Likewise.
(extract_range_from_binary_expr_1, adjust_range_with_scev): Likewise.
(overflow_comparison_p_1, register_edge_assert_for_2): Likewise.
(is_masked_range_test, find_switch_asserts, maybe_set_nonzero_bits)
(vrp_evaluate_conditional_warnv_with_ops, intersect_ranges): Likewise.
(range_fits_type_p, two_valued_val_range_p, vrp_finalize): Likewise.
(evrp_dom_walker::before_dom_children): Likewise.
* tree.c (cache_integer_cst, real_value_from_int_cst, integer_zerop)
(integer_all_onesp, integer_pow2p, integer_nonzerop, tree_log2)
(tree_floor_log2, tree_ctz, mem_ref_offset, tree_int_cst_sign_bit)
(tree_int_cst_sgn, get_unwidened, int_fits_type_p): Likewise.
(get_type_static_bounds, num_ending_zeros, drop_tree_overflow)
(get_range_pos_neg): Likewise.
* ubsan.c (ubsan_expand_ptr_ifn): Likewise.
* config/darwin.c (darwin_mergeable_constant_section): Likewise.
* config/aarch64/aarch64.c (aapcs_vfp_sub_candidate): Likewise.
* config/arm/arm.c (aapcs_vfp_sub_candidate): Likewise.
* config/avr/avr.c (avr_fold_builtin): Likewise.
* config/bfin/bfin.c (bfin_local_alignment): Likewise.
* config/msp430/msp430.c (msp430_attr): Likewise.
* config/nds32/nds32.c (nds32_insert_attributes): Likewise.
* config/powerpcspe/powerpcspe-c.c
(altivec_resolve_overloaded_builtin): Likewise.
* config/powerpcspe/powerpcspe.c (rs6000_aggregate_candidate)
(rs6000_expand_ternop_builtin): Likewise.
* config/rs6000/rs6000-c.c
(altivec_resolve_overloaded_builtin): Likewise.
* config/rs6000/rs6000.c (rs6000_aggregate_candidate): Likewise.
(rs6000_expand_ternop_builtin): Likewise.
* config/s390/s390.c (s390_handle_hotpatch_attribute): Likewise.
gcc/ada/
* gcc-interface/decl.c (annotate_value): Use wi::to_wide when
operating on trees as wide_ints.
gcc/c/
* c-parser.c (c_parser_cilk_clause_vectorlength): Use wi::to_wide when
operating on trees as wide_ints.
* c-typeck.c (build_c_cast, c_finish_omp_clauses): Likewise.
(c_tree_equal): Likewise.
gcc/c-family/
* c-ada-spec.c (dump_generic_ada_node): Use wi::to_wide when
operating on trees as wide_ints.
* c-common.c (pointer_int_sum): Likewise.
* c-pretty-print.c (pp_c_integer_constant): Likewise.
* c-warn.c (match_case_to_enum_1): Likewise.
(c_do_switch_warnings): Likewise.
(maybe_warn_shift_overflow): Likewise.
gcc/cp/
* cvt.c (ignore_overflows): Use wi::to_wide when
operating on trees as wide_ints.
* decl.c (check_array_designated_initializer): Likewise.
* mangle.c (write_integer_cst): Likewise.
* semantics.c (cp_finish_omp_clause_depend_sink): Likewise.
gcc/fortran/
* target-memory.c (gfc_interpret_logical): Use wi::to_wide when
operating on trees as wide_ints.
* trans-const.c (gfc_conv_tree_to_mpz): Likewise.
* trans-expr.c (gfc_conv_cst_int_power): Likewise.
* trans-intrinsic.c (trans_this_image): Likewise.
(gfc_conv_intrinsic_bound): Likewise.
(conv_intrinsic_cobound): Likewise.
gcc/lto/
* lto.c (compare_tree_sccs_1): Use wi::to_wide when
operating on trees as wide_ints.
gcc/objc/
* objc-act.c (objc_decl_method_attributes): Use wi::to_wide when
operating on trees as wide_ints.
From-SVN: r253595
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 57 |
1 files changed, 29 insertions, 28 deletions
@@ -1584,7 +1584,7 @@ cache_integer_cst (tree t) case BOOLEAN_TYPE: /* Cache false or true. */ limit = 2; - if (wi::ltu_p (t, 2)) + if (wi::ltu_p (wi::to_wide (t), 2)) ix = TREE_INT_CST_ELT (t, 0); break; @@ -1603,7 +1603,7 @@ cache_integer_cst (tree t) if (tree_to_uhwi (t) < (unsigned HOST_WIDE_INT) INTEGER_SHARE_LIMIT) ix = tree_to_uhwi (t); } - else if (wi::ltu_p (t, INTEGER_SHARE_LIMIT)) + else if (wi::ltu_p (wi::to_wide (t), INTEGER_SHARE_LIMIT)) ix = tree_to_uhwi (t); } else @@ -1613,14 +1613,14 @@ cache_integer_cst (tree t) if (integer_minus_onep (t)) ix = 0; - else if (!wi::neg_p (t)) + else if (!wi::neg_p (wi::to_wide (t))) { if (prec < HOST_BITS_PER_WIDE_INT) { if (tree_to_shwi (t) < INTEGER_SHARE_LIMIT) ix = tree_to_shwi (t) + 1; } - else if (wi::ltu_p (t, INTEGER_SHARE_LIMIT)) + else if (wi::ltu_p (wi::to_wide (t), INTEGER_SHARE_LIMIT)) ix = tree_to_shwi (t) + 1; } } @@ -1652,7 +1652,7 @@ cache_integer_cst (tree t) /* If there is already an entry for the number verify it's the same. */ if (*slot) - gcc_assert (wi::eq_p (tree (*slot), t)); + gcc_assert (wi::to_wide (tree (*slot)) == wi::to_wide (t)); else /* Otherwise insert this one into the hash table. */ *slot = t; @@ -1969,7 +1969,7 @@ real_value_from_int_cst (const_tree type, const_tree i) bitwise comparisons to see if two values are the same. */ memset (&d, 0, sizeof d); - real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, i, + real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode, wi::to_wide (i), TYPE_SIGN (TREE_TYPE (i))); return d; } @@ -2331,7 +2331,7 @@ integer_zerop (const_tree expr) switch (TREE_CODE (expr)) { case INTEGER_CST: - return wi::eq_p (expr, 0); + return wi::to_wide (expr) == 0; case COMPLEX_CST: return (integer_zerop (TREE_REALPART (expr)) && integer_zerop (TREE_IMAGPART (expr))); @@ -2410,7 +2410,8 @@ integer_all_onesp (const_tree expr) else if (TREE_CODE (expr) != INTEGER_CST) return 0; - return wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED) == expr; + return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED) + == wi::to_wide (expr)); } /* Return 1 if EXPR is the integer constant minus one. */ @@ -2439,7 +2440,7 @@ integer_pow2p (const_tree expr) if (TREE_CODE (expr) != INTEGER_CST) return 0; - return wi::popcount (expr) == 1; + return wi::popcount (wi::to_wide (expr)) == 1; } /* Return 1 if EXPR is an integer constant other than zero or a @@ -2449,7 +2450,7 @@ int integer_nonzerop (const_tree expr) { return ((TREE_CODE (expr) == INTEGER_CST - && !wi::eq_p (expr, 0)) + && wi::to_wide (expr) != 0) || (TREE_CODE (expr) == COMPLEX_CST && (integer_nonzerop (TREE_REALPART (expr)) || integer_nonzerop (TREE_IMAGPART (expr))))); @@ -2485,7 +2486,7 @@ tree_log2 (const_tree expr) if (TREE_CODE (expr) == COMPLEX_CST) return tree_log2 (TREE_REALPART (expr)); - return wi::exact_log2 (expr); + return wi::exact_log2 (wi::to_wide (expr)); } /* Similar, but return the largest integer Y such that 2 ** Y is less @@ -2497,7 +2498,7 @@ tree_floor_log2 (const_tree expr) if (TREE_CODE (expr) == COMPLEX_CST) return tree_log2 (TREE_REALPART (expr)); - return wi::floor_log2 (expr); + return wi::floor_log2 (wi::to_wide (expr)); } /* Return number of known trailing zero bits in EXPR, or, if the value of @@ -2514,7 +2515,7 @@ tree_ctz (const_tree expr) switch (TREE_CODE (expr)) { case INTEGER_CST: - ret1 = wi::ctz (expr); + ret1 = wi::ctz (wi::to_wide (expr)); return MIN (ret1, prec); case SSA_NAME: ret1 = wi::ctz (get_nonzero_bits (expr)); @@ -4679,7 +4680,7 @@ build_simple_mem_ref_loc (location_t loc, tree ptr) offset_int mem_ref_offset (const_tree t) { - return offset_int::from (TREE_OPERAND (t, 1), SIGNED); + return offset_int::from (wi::to_wide (TREE_OPERAND (t, 1)), SIGNED); } /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE @@ -6614,7 +6615,7 @@ tree_int_cst_sign_bit (const_tree t) { unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1; - return wi::extract_uhwi (t, bitno, 1); + return wi::extract_uhwi (wi::to_wide (t), bitno, 1); } /* Return an indication of the sign of the integer constant T. @@ -6624,11 +6625,11 @@ tree_int_cst_sign_bit (const_tree t) int tree_int_cst_sgn (const_tree t) { - if (wi::eq_p (t, 0)) + if (wi::to_wide (t) == 0) return 0; else if (TYPE_UNSIGNED (TREE_TYPE (t))) return 1; - else if (wi::neg_p (t)) + else if (wi::neg_p (wi::to_wide (t))) return -1; else return 1; @@ -8291,7 +8292,7 @@ get_unwidened (tree op, tree for_type) if (TREE_CODE (win) == INTEGER_CST) { tree wtype = TREE_TYPE (win); - unsigned prec = wi::min_precision (win, TYPE_SIGN (wtype)); + unsigned prec = wi::min_precision (wi::to_wide (win), TYPE_SIGN (wtype)); if (for_type) prec = MAX (prec, final_prec); if (prec < TYPE_PRECISION (wtype)) @@ -8412,7 +8413,7 @@ int_fits_type_p (const_tree c, const_tree type) /* Non-standard boolean types can have arbitrary precision but various transformations assume that they can only take values 0 and +/-1. */ if (TREE_CODE (type) == BOOLEAN_TYPE) - return wi::fits_to_boolean_p (c, type); + return wi::fits_to_boolean_p (wi::to_wide (c), type); retry: type_low_bound = TYPE_MIN_VALUE (type); @@ -8455,7 +8456,7 @@ retry: /* Perform some generic filtering which may allow making a decision even if the bounds are not constant. First, negative integers never fit in unsigned types, */ - if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (c)) + if (TYPE_UNSIGNED (type) && sgn_c == SIGNED && wi::neg_p (wi::to_wide (c))) return false; /* Second, narrower types always fit in wider ones. */ @@ -8474,10 +8475,10 @@ retry: possible that the value will not fit. The test below fails if any bit is set between the sign bit of the underlying mode and the top bit of the type. */ - if (wi::ne_p (wi::zext (c, prec - 1), c)) + if (wi::zext (wi::to_wide (c), prec - 1) != wi::to_wide (c)) return false; } - else if (wi::neg_p (c)) + else if (wi::neg_p (wi::to_wide (c))) return false; } @@ -8493,7 +8494,7 @@ retry: } /* Or to fits_to_tree_p, if nothing else. */ - return wi::fits_to_tree_p (c, type); + return wi::fits_to_tree_p (wi::to_wide (c), type); } /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant @@ -8506,7 +8507,7 @@ get_type_static_bounds (const_tree type, mpz_t min, mpz_t max) { if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type) && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST) - wi::to_mpz (TYPE_MIN_VALUE (type), min, TYPE_SIGN (type)); + wi::to_mpz (wi::to_wide (TYPE_MIN_VALUE (type)), min, TYPE_SIGN (type)); else { if (TYPE_UNSIGNED (type)) @@ -8520,7 +8521,7 @@ get_type_static_bounds (const_tree type, mpz_t min, mpz_t max) if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type) && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST) - wi::to_mpz (TYPE_MAX_VALUE (type), max, TYPE_SIGN (type)); + wi::to_mpz (wi::to_wide (TYPE_MAX_VALUE (type)), max, TYPE_SIGN (type)); else { wide_int mn = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); @@ -10931,7 +10932,7 @@ operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1) tree num_ending_zeros (const_tree x) { - return build_int_cst (TREE_TYPE (x), wi::ctz (x)); + return build_int_cst (TREE_TYPE (x), wi::ctz (wi::to_wide (x))); } @@ -12355,7 +12356,7 @@ drop_tree_overflow (tree t) /* For tree codes with a sharing machinery re-build the result. */ if (TREE_CODE (t) == INTEGER_CST) - return wide_int_to_tree (TREE_TYPE (t), t); + return wide_int_to_tree (TREE_TYPE (t), wi::to_wide (t)); /* Otherwise, as all tcc_constants are possibly shared, copy the node and drop the flag. */ @@ -13528,7 +13529,7 @@ get_range_pos_neg (tree arg) int cnt = 0; if (TREE_CODE (arg) == INTEGER_CST) { - wide_int w = wi::sext (arg, prec); + wide_int w = wi::sext (wi::to_wide (arg), prec); if (wi::neg_p (w)) return 2; else |