Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-vrp.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* Support routines for Value Range Propagation (VRP). | 1 /* Support routines for Value Range Propagation (VRP). |
2 Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. | 2 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 |
3 Free Software Foundation, Inc. | |
3 Contributed by Diego Novillo <dnovillo@redhat.com>. | 4 Contributed by Diego Novillo <dnovillo@redhat.com>. |
4 | 5 |
5 This file is part of GCC. | 6 This file is part of GCC. |
6 | 7 |
7 GCC is free software; you can redistribute it and/or modify | 8 GCC is free software; you can redistribute it and/or modify |
29 #include "tree-flow.h" | 30 #include "tree-flow.h" |
30 #include "tree-pass.h" | 31 #include "tree-pass.h" |
31 #include "tree-dump.h" | 32 #include "tree-dump.h" |
32 #include "timevar.h" | 33 #include "timevar.h" |
33 #include "diagnostic.h" | 34 #include "diagnostic.h" |
35 #include "tree-pretty-print.h" | |
36 #include "gimple-pretty-print.h" | |
34 #include "toplev.h" | 37 #include "toplev.h" |
35 #include "intl.h" | 38 #include "intl.h" |
36 #include "cfgloop.h" | 39 #include "cfgloop.h" |
37 #include "tree-scalar-evolution.h" | 40 #include "tree-scalar-evolution.h" |
38 #include "tree-ssa-propagate.h" | 41 #include "tree-ssa-propagate.h" |
761 return vr->type == VR_RANGE | 764 return vr->type == VR_RANGE |
762 && integer_zerop (vr->min) | 765 && integer_zerop (vr->min) |
763 && integer_zerop (vr->max); | 766 && integer_zerop (vr->max); |
764 } | 767 } |
765 | 768 |
769 /* Return true if max and min of VR are INTEGER_CST. It's not necessary | |
770 a singleton. */ | |
771 | |
772 static inline bool | |
773 range_int_cst_p (value_range_t *vr) | |
774 { | |
775 return (vr->type == VR_RANGE | |
776 && TREE_CODE (vr->max) == INTEGER_CST | |
777 && TREE_CODE (vr->min) == INTEGER_CST | |
778 && !TREE_OVERFLOW (vr->max) | |
779 && !TREE_OVERFLOW (vr->min)); | |
780 } | |
781 | |
782 /* Return true if VR is a INTEGER_CST singleton. */ | |
783 | |
784 static inline bool | |
785 range_int_cst_singleton_p (value_range_t *vr) | |
786 { | |
787 return (range_int_cst_p (vr) | |
788 && tree_int_cst_equal (vr->min, vr->max)); | |
789 } | |
766 | 790 |
767 /* Return true if value range VR involves at least one symbol. */ | 791 /* Return true if value range VR involves at least one symbol. */ |
768 | 792 |
769 static inline bool | 793 static inline bool |
770 symbolic_range_p (value_range_t *vr) | 794 symbolic_range_p (value_range_t *vr) |
1339 | 1363 |
1340 bool | 1364 bool |
1341 ssa_name_nonnegative_p (const_tree t) | 1365 ssa_name_nonnegative_p (const_tree t) |
1342 { | 1366 { |
1343 value_range_t *vr = get_value_range (t); | 1367 value_range_t *vr = get_value_range (t); |
1368 | |
1369 if (INTEGRAL_TYPE_P (t) | |
1370 && TYPE_UNSIGNED (t)) | |
1371 return true; | |
1344 | 1372 |
1345 if (!vr) | 1373 if (!vr) |
1346 return false; | 1374 return false; |
1347 | 1375 |
1348 /* Testing for VR_ANTI_RANGE is not useful here as any anti-range | 1376 /* Testing for VR_ANTI_RANGE is not useful here as any anti-range |
1896 { | 1924 { |
1897 tree res; | 1925 tree res; |
1898 | 1926 |
1899 res = int_const_binop (code, val1, val2, 0); | 1927 res = int_const_binop (code, val1, val2, 0); |
1900 | 1928 |
1901 /* If we are not using wrapping arithmetic, operate symbolically | 1929 /* If we are using unsigned arithmetic, operate symbolically |
1902 on -INF and +INF. */ | 1930 on -INF and +INF as int_const_binop only handles signed overflow. */ |
1903 if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (val1))) | 1931 if (TYPE_UNSIGNED (TREE_TYPE (val1))) |
1904 { | 1932 { |
1905 int checkz = compare_values (res, val1); | 1933 int checkz = compare_values (res, val1); |
1906 bool overflow = false; | 1934 bool overflow = false; |
1907 | 1935 |
1908 /* Ensure that res = val1 [+*] val2 >= val1 | 1936 /* Ensure that res = val1 [+*] val2 >= val1 |
1935 res = copy_node (res); | 1963 res = copy_node (res); |
1936 TREE_OVERFLOW (res) = 1; | 1964 TREE_OVERFLOW (res) = 1; |
1937 } | 1965 } |
1938 | 1966 |
1939 } | 1967 } |
1968 else if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (val1))) | |
1969 /* If the singed operation wraps then int_const_binop has done | |
1970 everything we want. */ | |
1971 ; | |
1940 else if ((TREE_OVERFLOW (res) | 1972 else if ((TREE_OVERFLOW (res) |
1941 && !TREE_OVERFLOW (val1) | 1973 && !TREE_OVERFLOW (val1) |
1942 && !TREE_OVERFLOW (val2)) | 1974 && !TREE_OVERFLOW (val2)) |
1943 || is_overflow_infinity (val1) | 1975 || is_overflow_infinity (val1) |
1944 || is_overflow_infinity (val2)) | 1976 || is_overflow_infinity (val2)) |
2051 && code != TRUNC_DIV_EXPR | 2083 && code != TRUNC_DIV_EXPR |
2052 && code != FLOOR_DIV_EXPR | 2084 && code != FLOOR_DIV_EXPR |
2053 && code != CEIL_DIV_EXPR | 2085 && code != CEIL_DIV_EXPR |
2054 && code != EXACT_DIV_EXPR | 2086 && code != EXACT_DIV_EXPR |
2055 && code != ROUND_DIV_EXPR | 2087 && code != ROUND_DIV_EXPR |
2088 && code != TRUNC_MOD_EXPR | |
2056 && code != RSHIFT_EXPR | 2089 && code != RSHIFT_EXPR |
2057 && code != MIN_EXPR | 2090 && code != MIN_EXPR |
2058 && code != MAX_EXPR | 2091 && code != MAX_EXPR |
2059 && code != BIT_AND_EXPR | 2092 && code != BIT_AND_EXPR |
2060 && code != BIT_IOR_EXPR | 2093 && code != BIT_IOR_EXPR |
2119 && code != TRUNC_DIV_EXPR | 2152 && code != TRUNC_DIV_EXPR |
2120 && code != FLOOR_DIV_EXPR | 2153 && code != FLOOR_DIV_EXPR |
2121 && code != CEIL_DIV_EXPR | 2154 && code != CEIL_DIV_EXPR |
2122 && code != EXACT_DIV_EXPR | 2155 && code != EXACT_DIV_EXPR |
2123 && code != ROUND_DIV_EXPR | 2156 && code != ROUND_DIV_EXPR |
2157 && code != TRUNC_MOD_EXPR | |
2124 && (vr0.type == VR_VARYING | 2158 && (vr0.type == VR_VARYING |
2125 || vr1.type == VR_VARYING | 2159 || vr1.type == VR_VARYING |
2126 || vr0.type != vr1.type | 2160 || vr0.type != vr1.type |
2127 || symbolic_range_p (&vr0) | 2161 || symbolic_range_p (&vr0) |
2128 || symbolic_range_p (&vr1))) | 2162 || symbolic_range_p (&vr1))) |
2469 max = val[i]; | 2503 max = val[i]; |
2470 } | 2504 } |
2471 } | 2505 } |
2472 } | 2506 } |
2473 } | 2507 } |
2508 else if (code == TRUNC_MOD_EXPR) | |
2509 { | |
2510 bool sop = false; | |
2511 if (vr1.type != VR_RANGE | |
2512 || symbolic_range_p (&vr1) | |
2513 || range_includes_zero_p (&vr1) | |
2514 || vrp_val_is_min (vr1.min)) | |
2515 { | |
2516 set_value_range_to_varying (vr); | |
2517 return; | |
2518 } | |
2519 type = VR_RANGE; | |
2520 /* Compute MAX <|vr1.min|, |vr1.max|> - 1. */ | |
2521 max = fold_unary_to_constant (ABS_EXPR, TREE_TYPE (vr1.min), vr1.min); | |
2522 if (tree_int_cst_lt (max, vr1.max)) | |
2523 max = vr1.max; | |
2524 max = int_const_binop (MINUS_EXPR, max, integer_one_node, 0); | |
2525 /* If the dividend is non-negative the modulus will be | |
2526 non-negative as well. */ | |
2527 if (TYPE_UNSIGNED (TREE_TYPE (max)) | |
2528 || (vrp_expr_computes_nonnegative (op0, &sop) && !sop)) | |
2529 min = build_int_cst (TREE_TYPE (max), 0); | |
2530 else | |
2531 min = fold_unary_to_constant (NEGATE_EXPR, TREE_TYPE (max), max); | |
2532 } | |
2474 else if (code == MINUS_EXPR) | 2533 else if (code == MINUS_EXPR) |
2475 { | 2534 { |
2476 /* If we have a MINUS_EXPR with two VR_ANTI_RANGEs, drop to | 2535 /* If we have a MINUS_EXPR with two VR_ANTI_RANGEs, drop to |
2477 VR_VARYING. It would take more effort to compute a precise | 2536 VR_VARYING. It would take more effort to compute a precise |
2478 range for such a case. For example, if we have op0 == 1 and | 2537 range for such a case. For example, if we have op0 == 1 and |
2491 min = vrp_int_const_binop (code, vr0.min, vr1.max); | 2550 min = vrp_int_const_binop (code, vr0.min, vr1.max); |
2492 max = vrp_int_const_binop (code, vr0.max, vr1.min); | 2551 max = vrp_int_const_binop (code, vr0.max, vr1.min); |
2493 } | 2552 } |
2494 else if (code == BIT_AND_EXPR) | 2553 else if (code == BIT_AND_EXPR) |
2495 { | 2554 { |
2496 if (vr0.type == VR_RANGE | 2555 bool vr0_int_cst_singleton_p, vr1_int_cst_singleton_p; |
2497 && vr0.min == vr0.max | 2556 |
2498 && TREE_CODE (vr0.max) == INTEGER_CST | 2557 vr0_int_cst_singleton_p = range_int_cst_singleton_p (&vr0); |
2499 && !TREE_OVERFLOW (vr0.max) | 2558 vr1_int_cst_singleton_p = range_int_cst_singleton_p (&vr1); |
2500 && tree_int_cst_sgn (vr0.max) >= 0) | 2559 |
2560 if (vr0_int_cst_singleton_p && vr1_int_cst_singleton_p) | |
2561 min = max = int_const_binop (code, vr0.max, vr1.max, 0); | |
2562 else if (vr0_int_cst_singleton_p | |
2563 && tree_int_cst_sgn (vr0.max) >= 0) | |
2501 { | 2564 { |
2502 min = build_int_cst (expr_type, 0); | 2565 min = build_int_cst (expr_type, 0); |
2503 max = vr0.max; | 2566 max = vr0.max; |
2504 } | 2567 } |
2505 else if (vr1.type == VR_RANGE | 2568 else if (vr1_int_cst_singleton_p |
2506 && vr1.min == vr1.max | |
2507 && TREE_CODE (vr1.max) == INTEGER_CST | |
2508 && !TREE_OVERFLOW (vr1.max) | |
2509 && tree_int_cst_sgn (vr1.max) >= 0) | 2569 && tree_int_cst_sgn (vr1.max) >= 0) |
2510 { | 2570 { |
2511 type = VR_RANGE; | 2571 type = VR_RANGE; |
2512 min = build_int_cst (expr_type, 0); | 2572 min = build_int_cst (expr_type, 0); |
2513 max = vr1.max; | 2573 max = vr1.max; |
2518 return; | 2578 return; |
2519 } | 2579 } |
2520 } | 2580 } |
2521 else if (code == BIT_IOR_EXPR) | 2581 else if (code == BIT_IOR_EXPR) |
2522 { | 2582 { |
2523 if (vr0.type == VR_RANGE | 2583 if (range_int_cst_p (&vr0) |
2524 && vr1.type == VR_RANGE | 2584 && range_int_cst_p (&vr1) |
2525 && TREE_CODE (vr0.min) == INTEGER_CST | |
2526 && TREE_CODE (vr1.min) == INTEGER_CST | |
2527 && TREE_CODE (vr0.max) == INTEGER_CST | |
2528 && TREE_CODE (vr1.max) == INTEGER_CST | |
2529 && tree_int_cst_sgn (vr0.min) >= 0 | 2585 && tree_int_cst_sgn (vr0.min) >= 0 |
2530 && tree_int_cst_sgn (vr1.min) >= 0) | 2586 && tree_int_cst_sgn (vr1.min) >= 0) |
2531 { | 2587 { |
2532 double_int vr0_max = tree_to_double_int (vr0.max); | 2588 double_int vr0_max = tree_to_double_int (vr0.max); |
2533 double_int vr1_max = tree_to_double_int (vr1.max); | 2589 double_int vr1_max = tree_to_double_int (vr1.max); |
2708 not an anti-range. */ | 2764 not an anti-range. */ |
2709 if ((vr0.type == VR_RANGE | 2765 if ((vr0.type == VR_RANGE |
2710 || vr0.type == VR_ANTI_RANGE) | 2766 || vr0.type == VR_ANTI_RANGE) |
2711 && TREE_CODE (vr0.min) == INTEGER_CST | 2767 && TREE_CODE (vr0.min) == INTEGER_CST |
2712 && TREE_CODE (vr0.max) == INTEGER_CST | 2768 && TREE_CODE (vr0.max) == INTEGER_CST |
2713 && !is_overflow_infinity (vr0.min) | 2769 && (!is_overflow_infinity (vr0.min) |
2714 && !is_overflow_infinity (vr0.max) | 2770 || (vr0.type == VR_RANGE |
2771 && TYPE_PRECISION (outer_type) > TYPE_PRECISION (inner_type) | |
2772 && needs_overflow_infinity (outer_type) | |
2773 && supports_overflow_infinity (outer_type))) | |
2774 && (!is_overflow_infinity (vr0.max) | |
2775 || (vr0.type == VR_RANGE | |
2776 && TYPE_PRECISION (outer_type) > TYPE_PRECISION (inner_type) | |
2777 && needs_overflow_infinity (outer_type) | |
2778 && supports_overflow_infinity (outer_type))) | |
2715 && (TYPE_PRECISION (outer_type) >= TYPE_PRECISION (inner_type) | 2779 && (TYPE_PRECISION (outer_type) >= TYPE_PRECISION (inner_type) |
2716 || (vr0.type == VR_RANGE | 2780 || (vr0.type == VR_RANGE |
2717 && integer_zerop (int_const_binop (RSHIFT_EXPR, | 2781 && integer_zerop (int_const_binop (RSHIFT_EXPR, |
2718 int_const_binop (MINUS_EXPR, vr0.max, vr0.min, 0), | 2782 int_const_binop (MINUS_EXPR, vr0.max, vr0.min, 0), |
2719 size_int (TYPE_PRECISION (outer_type)), 0))))) | 2783 size_int (TYPE_PRECISION (outer_type)), 0))))) |
2723 TREE_INT_CST_LOW (vr0.min), | 2787 TREE_INT_CST_LOW (vr0.min), |
2724 TREE_INT_CST_HIGH (vr0.min), 0, 0); | 2788 TREE_INT_CST_HIGH (vr0.min), 0, 0); |
2725 new_max = force_fit_type_double (outer_type, | 2789 new_max = force_fit_type_double (outer_type, |
2726 TREE_INT_CST_LOW (vr0.max), | 2790 TREE_INT_CST_LOW (vr0.max), |
2727 TREE_INT_CST_HIGH (vr0.max), 0, 0); | 2791 TREE_INT_CST_HIGH (vr0.max), 0, 0); |
2792 if (is_overflow_infinity (vr0.min)) | |
2793 new_min = negative_overflow_infinity (outer_type); | |
2794 if (is_overflow_infinity (vr0.max)) | |
2795 new_max = positive_overflow_infinity (outer_type); | |
2728 set_and_canonicalize_value_range (vr, vr0.type, | 2796 set_and_canonicalize_value_range (vr, vr0.type, |
2729 new_min, new_max, NULL); | 2797 new_min, new_max, NULL); |
2730 return; | 2798 return; |
2731 } | 2799 } |
2732 | 2800 |
3134 | 3202 |
3135 static void | 3203 static void |
3136 adjust_range_with_scev (value_range_t *vr, struct loop *loop, | 3204 adjust_range_with_scev (value_range_t *vr, struct loop *loop, |
3137 gimple stmt, tree var) | 3205 gimple stmt, tree var) |
3138 { | 3206 { |
3139 tree init, step, chrec, tmin, tmax, min, max, type; | 3207 tree init, step, chrec, tmin, tmax, min, max, type, tem; |
3140 enum ev_direction dir; | 3208 enum ev_direction dir; |
3141 | 3209 |
3142 /* TODO. Don't adjust anti-ranges. An anti-range may provide | 3210 /* TODO. Don't adjust anti-ranges. An anti-range may provide |
3143 better opportunities than a regular range, but I'm not sure. */ | 3211 better opportunities than a regular range, but I'm not sure. */ |
3144 if (vr->type == VR_ANTI_RANGE) | 3212 if (vr->type == VR_ANTI_RANGE) |
3155 | 3223 |
3156 if (TREE_CODE (chrec) != POLYNOMIAL_CHREC) | 3224 if (TREE_CODE (chrec) != POLYNOMIAL_CHREC) |
3157 return; | 3225 return; |
3158 | 3226 |
3159 init = initial_condition_in_loop_num (chrec, loop->num); | 3227 init = initial_condition_in_loop_num (chrec, loop->num); |
3228 tem = op_with_constant_singleton_value_range (init); | |
3229 if (tem) | |
3230 init = tem; | |
3160 step = evolution_part_in_loop_num (chrec, loop->num); | 3231 step = evolution_part_in_loop_num (chrec, loop->num); |
3232 tem = op_with_constant_singleton_value_range (step); | |
3233 if (tem) | |
3234 step = tem; | |
3161 | 3235 |
3162 /* If STEP is symbolic, we can't know whether INIT will be the | 3236 /* If STEP is symbolic, we can't know whether INIT will be the |
3163 minimum or maximum value in the range. Also, unless INIT is | 3237 minimum or maximum value in the range. Also, unless INIT is |
3164 a simple expression, compare_values and possibly other functions | 3238 a simple expression, compare_values and possibly other functions |
3165 in tree-vrp won't be able to handle it. */ | 3239 in tree-vrp won't be able to handle it. */ |
3274 | 3348 |
3275 if (current_loops == NULL) | 3349 if (current_loops == NULL) |
3276 return true; | 3350 return true; |
3277 | 3351 |
3278 l = loop_containing_stmt (stmt); | 3352 l = loop_containing_stmt (stmt); |
3279 if (l == NULL) | 3353 if (l == NULL |
3354 || !loop_outer (l)) | |
3280 return true; | 3355 return true; |
3281 | 3356 |
3282 chrec = instantiate_parameters (l, analyze_scalar_evolution (l, var)); | 3357 chrec = instantiate_parameters (l, analyze_scalar_evolution (l, var)); |
3283 if (TREE_CODE (chrec) != POLYNOMIAL_CHREC) | 3358 if (TREE_CODE (chrec) != POLYNOMIAL_CHREC) |
3284 return true; | 3359 return true; |
4829 tree cond; | 4904 tree cond; |
4830 gimple assert_stmt; | 4905 gimple assert_stmt; |
4831 edge_iterator ei; | 4906 edge_iterator ei; |
4832 edge e; | 4907 edge e; |
4833 | 4908 |
4909 /* If we have X <=> X do not insert an assert expr for that. */ | |
4910 if (loc->expr == loc->val) | |
4911 return false; | |
4912 | |
4834 cond = build2 (loc->comp_code, boolean_type_node, loc->expr, loc->val); | 4913 cond = build2 (loc->comp_code, boolean_type_node, loc->expr, loc->val); |
4835 assert_stmt = build_assert_expr_for (cond, name); | 4914 assert_stmt = build_assert_expr_for (cond, name); |
4836 if (loc->e) | 4915 if (loc->e) |
4837 { | 4916 { |
4838 /* We have been asked to insert the assertion on an edge. This | 4917 /* We have been asked to insert the assertion on an edge. This |
4974 static void | 5053 static void |
4975 check_array_ref (location_t location, tree ref, bool ignore_off_by_one) | 5054 check_array_ref (location_t location, tree ref, bool ignore_off_by_one) |
4976 { | 5055 { |
4977 value_range_t* vr = NULL; | 5056 value_range_t* vr = NULL; |
4978 tree low_sub, up_sub; | 5057 tree low_sub, up_sub; |
4979 tree low_bound, up_bound = array_ref_up_bound (ref); | 5058 tree low_bound, up_bound, up_bound_p1; |
5059 tree base; | |
5060 | |
5061 if (TREE_NO_WARNING (ref)) | |
5062 return; | |
4980 | 5063 |
4981 low_sub = up_sub = TREE_OPERAND (ref, 1); | 5064 low_sub = up_sub = TREE_OPERAND (ref, 1); |
4982 | 5065 up_bound = array_ref_up_bound (ref); |
4983 if (!up_bound || TREE_NO_WARNING (ref) | 5066 |
4984 || TREE_CODE (up_bound) != INTEGER_CST | 5067 /* Can not check flexible arrays. */ |
4985 /* Can not check flexible arrays. */ | 5068 if (!up_bound |
4986 || (TYPE_SIZE (TREE_TYPE (ref)) == NULL_TREE | 5069 || TREE_CODE (up_bound) != INTEGER_CST) |
4987 && TYPE_DOMAIN (TREE_TYPE (ref)) != NULL_TREE | |
4988 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (ref))) == NULL_TREE) | |
4989 /* Accesses after the end of arrays of size 0 (gcc | |
4990 extension) and 1 are likely intentional ("struct | |
4991 hack"). */ | |
4992 || compare_tree_int (up_bound, 1) <= 0) | |
4993 return; | 5070 return; |
4994 | 5071 |
5072 /* Accesses to trailing arrays via pointers may access storage | |
5073 beyond the types array bounds. */ | |
5074 base = get_base_address (ref); | |
5075 if (base | |
5076 && INDIRECT_REF_P (base)) | |
5077 { | |
5078 tree cref, next = NULL_TREE; | |
5079 | |
5080 if (TREE_CODE (TREE_OPERAND (ref, 0)) != COMPONENT_REF) | |
5081 return; | |
5082 | |
5083 cref = TREE_OPERAND (ref, 0); | |
5084 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (cref, 0))) == RECORD_TYPE) | |
5085 for (next = TREE_CHAIN (TREE_OPERAND (cref, 1)); | |
5086 next && TREE_CODE (next) != FIELD_DECL; | |
5087 next = TREE_CHAIN (next)) | |
5088 ; | |
5089 | |
5090 /* If this is the last field in a struct type or a field in a | |
5091 union type do not warn. */ | |
5092 if (!next) | |
5093 return; | |
5094 } | |
5095 | |
4995 low_bound = array_ref_low_bound (ref); | 5096 low_bound = array_ref_low_bound (ref); |
5097 up_bound_p1 = int_const_binop (PLUS_EXPR, up_bound, integer_one_node, 0); | |
4996 | 5098 |
4997 if (TREE_CODE (low_sub) == SSA_NAME) | 5099 if (TREE_CODE (low_sub) == SSA_NAME) |
4998 { | 5100 { |
4999 vr = get_value_range (low_sub); | 5101 vr = get_value_range (low_sub); |
5000 if (vr->type == VR_RANGE || vr->type == VR_ANTI_RANGE) | 5102 if (vr->type == VR_RANGE || vr->type == VR_ANTI_RANGE) |
5015 "array subscript is outside array bounds"); | 5117 "array subscript is outside array bounds"); |
5016 TREE_NO_WARNING (ref) = 1; | 5118 TREE_NO_WARNING (ref) = 1; |
5017 } | 5119 } |
5018 } | 5120 } |
5019 else if (TREE_CODE (up_sub) == INTEGER_CST | 5121 else if (TREE_CODE (up_sub) == INTEGER_CST |
5020 && tree_int_cst_lt (up_bound, up_sub) | 5122 && (ignore_off_by_one |
5021 && !tree_int_cst_equal (up_bound, up_sub) | 5123 ? (tree_int_cst_lt (up_bound, up_sub) |
5022 && (!ignore_off_by_one | 5124 && !tree_int_cst_equal (up_bound_p1, up_sub)) |
5023 || !tree_int_cst_equal (int_const_binop (PLUS_EXPR, | 5125 : (tree_int_cst_lt (up_bound, up_sub) |
5024 up_bound, | 5126 || tree_int_cst_equal (up_bound_p1, up_sub)))) |
5025 integer_one_node, | |
5026 0), | |
5027 up_sub))) | |
5028 { | 5127 { |
5029 warning_at (location, OPT_Warray_bounds, | 5128 warning_at (location, OPT_Warray_bounds, |
5030 "array subscript is above array bounds"); | 5129 "array subscript is above array bounds"); |
5031 TREE_NO_WARNING (ref) = 1; | 5130 TREE_NO_WARNING (ref) = 1; |
5032 } | 5131 } |
5120 basic_block bb; | 5219 basic_block bb; |
5121 gimple_stmt_iterator si; | 5220 gimple_stmt_iterator si; |
5122 | 5221 |
5123 FOR_EACH_BB (bb) | 5222 FOR_EACH_BB (bb) |
5124 { | 5223 { |
5125 /* Skip bb's that are clearly unreachable. */ | 5224 edge_iterator ei; |
5126 if (single_pred_p (bb)) | 5225 edge e; |
5127 { | 5226 bool executable = false; |
5128 int i; | 5227 |
5129 bool reachable = true; | 5228 /* Skip blocks that were found to be unreachable. */ |
5130 edge e2; | 5229 FOR_EACH_EDGE (e, ei, bb->preds) |
5131 edge e = EDGE_PRED (bb, 0); | 5230 executable |= !!(e->flags & EDGE_EXECUTABLE); |
5132 basic_block pred_bb = e->src; | 5231 if (!executable) |
5133 gimple ls = NULL; | 5232 continue; |
5134 | 5233 |
5135 for (i = 0; VEC_iterate (edge, to_remove_edges, i, e2); ++i) | |
5136 if (e == e2) | |
5137 { | |
5138 reachable = false; | |
5139 break; | |
5140 } | |
5141 | |
5142 if (!reachable) | |
5143 continue; | |
5144 | |
5145 if (!gsi_end_p (gsi_last_bb (pred_bb))) | |
5146 ls = gsi_stmt (gsi_last_bb (pred_bb)); | |
5147 | |
5148 if (ls && gimple_code (ls) == GIMPLE_COND | |
5149 && ((gimple_cond_false_p (ls) | |
5150 && (EDGE_PRED (bb, 0)->flags & EDGE_TRUE_VALUE)) | |
5151 || (gimple_cond_true_p (ls) | |
5152 && (EDGE_PRED (bb, 0)->flags & EDGE_FALSE_VALUE)))) | |
5153 continue; | |
5154 } | |
5155 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) | 5234 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) |
5156 { | 5235 { |
5157 gimple stmt = gsi_stmt (si); | 5236 gimple stmt = gsi_stmt (si); |
5158 struct walk_stmt_info wi; | 5237 struct walk_stmt_info wi; |
5159 if (!gimple_has_location (stmt)) | 5238 if (!gimple_has_location (stmt)) |
5356 build_range_type. */ | 5435 build_range_type. */ |
5357 && TYPE_MIN_VALUE (TREE_TYPE (lhs)) | 5436 && TYPE_MIN_VALUE (TREE_TYPE (lhs)) |
5358 && TYPE_MAX_VALUE (TREE_TYPE (lhs))) | 5437 && TYPE_MAX_VALUE (TREE_TYPE (lhs))) |
5359 || POINTER_TYPE_P (TREE_TYPE (lhs)))) | 5438 || POINTER_TYPE_P (TREE_TYPE (lhs)))) |
5360 { | 5439 { |
5361 struct loop *l; | |
5362 value_range_t new_vr = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }; | 5440 value_range_t new_vr = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }; |
5363 | 5441 |
5364 if (code == GIMPLE_CALL) | 5442 if (code == GIMPLE_CALL) |
5365 extract_range_basic (&new_vr, stmt); | 5443 extract_range_basic (&new_vr, stmt); |
5366 else | 5444 else |
5367 extract_range_from_assignment (&new_vr, stmt); | 5445 extract_range_from_assignment (&new_vr, stmt); |
5368 | |
5369 /* If STMT is inside a loop, we may be able to know something | |
5370 else about the range of LHS by examining scalar evolution | |
5371 information. */ | |
5372 if (current_loops && (l = loop_containing_stmt (stmt))) | |
5373 adjust_range_with_scev (&new_vr, l, stmt, lhs); | |
5374 | 5446 |
5375 if (update_value_range (lhs, &new_vr)) | 5447 if (update_value_range (lhs, &new_vr)) |
5376 { | 5448 { |
5377 *output_p = lhs; | 5449 *output_p = lhs; |
5378 | 5450 |
6273 size_t i; | 6345 size_t i; |
6274 tree lhs = PHI_RESULT (phi); | 6346 tree lhs = PHI_RESULT (phi); |
6275 value_range_t *lhs_vr = get_value_range (lhs); | 6347 value_range_t *lhs_vr = get_value_range (lhs); |
6276 value_range_t vr_result = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }; | 6348 value_range_t vr_result = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }; |
6277 int edges, old_edges; | 6349 int edges, old_edges; |
6350 struct loop *l; | |
6278 | 6351 |
6279 copy_value_range (&vr_result, lhs_vr); | 6352 copy_value_range (&vr_result, lhs_vr); |
6280 | 6353 |
6281 if (dump_file && (dump_flags & TDF_DETAILS)) | 6354 if (dump_file && (dump_flags & TDF_DETAILS)) |
6282 { | 6355 { |
6335 | 6408 |
6336 if (vr_result.type == VR_VARYING) | 6409 if (vr_result.type == VR_VARYING) |
6337 break; | 6410 break; |
6338 } | 6411 } |
6339 } | 6412 } |
6413 | |
6414 /* If this is a loop PHI node SCEV may known more about its | |
6415 value-range. */ | |
6416 if (current_loops | |
6417 && (l = loop_containing_stmt (phi)) | |
6418 && l->header == gimple_bb (phi)) | |
6419 adjust_range_with_scev (&vr_result, l, phi, lhs); | |
6340 | 6420 |
6341 if (vr_result.type == VR_VARYING) | 6421 if (vr_result.type == VR_VARYING) |
6342 goto varying; | 6422 goto varying; |
6343 | 6423 |
6344 old_edges = vr_phi_edge_counts[SSA_NAME_VERSION (lhs)]; | 6424 old_edges = vr_phi_edge_counts[SSA_NAME_VERSION (lhs)]; |
6407 } | 6487 } |
6408 | 6488 |
6409 /* If the new range is different than the previous value, keep | 6489 /* If the new range is different than the previous value, keep |
6410 iterating. */ | 6490 iterating. */ |
6411 if (update_value_range (lhs, &vr_result)) | 6491 if (update_value_range (lhs, &vr_result)) |
6412 return SSA_PROP_INTERESTING; | 6492 { |
6493 if (dump_file && (dump_flags & TDF_DETAILS)) | |
6494 { | |
6495 fprintf (dump_file, "Found new range for "); | |
6496 print_generic_expr (dump_file, lhs, 0); | |
6497 fprintf (dump_file, ": "); | |
6498 dump_value_range (dump_file, &vr_result); | |
6499 fprintf (dump_file, "\n\n"); | |
6500 } | |
6501 | |
6502 return SSA_PROP_INTERESTING; | |
6503 } | |
6413 | 6504 |
6414 /* Nothing changed, don't add outgoing edges. */ | 6505 /* Nothing changed, don't add outgoing edges. */ |
6415 return SSA_PROP_NOT_INTERESTING; | 6506 return SSA_PROP_NOT_INTERESTING; |
6416 | 6507 |
6417 /* No match found. Set the LHS to VARYING. */ | 6508 /* No match found. Set the LHS to VARYING. */ |
6924 if (dump_file && (dump_flags & TDF_DETAILS)) | 7015 if (dump_file && (dump_flags & TDF_DETAILS)) |
6925 { | 7016 { |
6926 fprintf (dump_file, "removing unreachable case label\n"); | 7017 fprintf (dump_file, "removing unreachable case label\n"); |
6927 } | 7018 } |
6928 VEC_safe_push (edge, heap, to_remove_edges, e); | 7019 VEC_safe_push (edge, heap, to_remove_edges, e); |
7020 e->flags &= ~EDGE_EXECUTABLE; | |
6929 } | 7021 } |
6930 | 7022 |
6931 /* And queue an update for the stmt. */ | 7023 /* And queue an update for the stmt. */ |
6932 su.stmt = stmt; | 7024 su.stmt = stmt; |
6933 su.vec = vec2; | 7025 su.vec = vec2; |
7253 } | 7345 } |
7254 | 7346 |
7255 substitute_and_fold (single_val_range, vrp_fold_stmt); | 7347 substitute_and_fold (single_val_range, vrp_fold_stmt); |
7256 | 7348 |
7257 if (warn_array_bounds) | 7349 if (warn_array_bounds) |
7258 check_all_array_refs (); | 7350 check_all_array_refs (); |
7259 | 7351 |
7260 /* We must identify jump threading opportunities before we release | 7352 /* We must identify jump threading opportunities before we release |
7261 the datastructures built by VRP. */ | 7353 the datastructures built by VRP. */ |
7262 identify_jump_threads (); | 7354 identify_jump_threads (); |
7263 | 7355 |