Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-vrp.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | 58ad6c70ea60 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
119 DEF_VEC_O(switch_update); | 119 DEF_VEC_O(switch_update); |
120 DEF_VEC_ALLOC_O(switch_update, heap); | 120 DEF_VEC_ALLOC_O(switch_update, heap); |
121 static VEC (switch_update, heap) *to_update_switch_stmts; | 121 static VEC (switch_update, heap) *to_update_switch_stmts; |
122 | 122 |
123 | 123 |
124 /* Return the maximum value for TYPEs base type. */ | 124 /* Return the maximum value for TYPE. */ |
125 | 125 |
126 static inline tree | 126 static inline tree |
127 vrp_val_max (const_tree type) | 127 vrp_val_max (const_tree type) |
128 { | 128 { |
129 if (!INTEGRAL_TYPE_P (type)) | 129 if (!INTEGRAL_TYPE_P (type)) |
130 return NULL_TREE; | 130 return NULL_TREE; |
131 | 131 |
132 /* For integer sub-types the values for the base type are relevant. */ | |
133 if (TREE_TYPE (type)) | |
134 type = TREE_TYPE (type); | |
135 | |
136 return TYPE_MAX_VALUE (type); | 132 return TYPE_MAX_VALUE (type); |
137 } | 133 } |
138 | 134 |
139 /* Return the minimum value for TYPEs base type. */ | 135 /* Return the minimum value for TYPE. */ |
140 | 136 |
141 static inline tree | 137 static inline tree |
142 vrp_val_min (const_tree type) | 138 vrp_val_min (const_tree type) |
143 { | 139 { |
144 if (!INTEGRAL_TYPE_P (type)) | 140 if (!INTEGRAL_TYPE_P (type)) |
145 return NULL_TREE; | 141 return NULL_TREE; |
146 | |
147 /* For integer sub-types the values for the base type are relevant. */ | |
148 if (TREE_TYPE (type)) | |
149 type = TREE_TYPE (type); | |
150 | 142 |
151 return TYPE_MIN_VALUE (type); | 143 return TYPE_MIN_VALUE (type); |
152 } | 144 } |
153 | 145 |
154 /* Return whether VAL is equal to the maximum value of its type. This | 146 /* Return whether VAL is equal to the maximum value of its type. This |
186 TYPE_{MIN,MAX}_VALUE. */ | 178 TYPE_{MIN,MAX}_VALUE. */ |
187 | 179 |
188 static inline bool | 180 static inline bool |
189 needs_overflow_infinity (const_tree type) | 181 needs_overflow_infinity (const_tree type) |
190 { | 182 { |
191 return (INTEGRAL_TYPE_P (type) | 183 return INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_WRAPS (type); |
192 && !TYPE_OVERFLOW_WRAPS (type) | |
193 /* Integer sub-types never overflow as they are never | |
194 operands of arithmetic operators. */ | |
195 && !(TREE_TYPE (type) && TREE_TYPE (type) != type)); | |
196 } | 184 } |
197 | 185 |
198 /* Return whether TYPE can support our overflow infinity | 186 /* Return whether TYPE can support our overflow infinity |
199 representation: we use the TREE_OVERFLOW flag, which only exists | 187 representation: we use the TREE_OVERFLOW flag, which only exists |
200 for constants. If TYPE doesn't support this, we don't optimize | 188 for constants. If TYPE doesn't support this, we don't optimize |
633 } | 621 } |
634 set_and_canonicalize_value_range (vr, VR_RANGE, min, max, NULL); | 622 set_and_canonicalize_value_range (vr, VR_RANGE, min, max, NULL); |
635 } | 623 } |
636 | 624 |
637 | 625 |
638 /* Return value range information for VAR. | 626 /* Return value range information for VAR. |
639 | 627 |
640 If we have no values ranges recorded (ie, VRP is not running), then | 628 If we have no values ranges recorded (ie, VRP is not running), then |
641 return NULL. Otherwise create an empty range if none existed for VAR. */ | 629 return NULL. Otherwise create an empty range if none existed for VAR. */ |
642 | 630 |
643 static value_range_t * | 631 static value_range_t * |
995 | 983 |
996 if (TREE_CODE (expr) == PLUS_EXPR | 984 if (TREE_CODE (expr) == PLUS_EXPR |
997 || TREE_CODE (expr) == MINUS_EXPR) | 985 || TREE_CODE (expr) == MINUS_EXPR) |
998 return (TREE_CODE (TREE_OPERAND (expr, 0)) == SSA_NAME | 986 return (TREE_CODE (TREE_OPERAND (expr, 0)) == SSA_NAME |
999 && TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST); | 987 && TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST); |
1000 | 988 |
1001 return is_gimple_min_invariant (expr); | 989 return is_gimple_min_invariant (expr); |
1002 } | 990 } |
1003 | 991 |
1004 /* Return | 992 /* Return |
1005 1 if VAL < VAL2 | 993 1 if VAL < VAL2 |
1006 0 if !(VAL < VAL2) | 994 0 if !(VAL < VAL2) |
1007 -2 if those are incomparable. */ | 995 -2 if those are incomparable. */ |
1008 static inline int | 996 static inline int |
1009 operand_less_p (tree val, tree val2) | 997 operand_less_p (tree val, tree val2) |
1045 | 1033 |
1046 return 0; | 1034 return 0; |
1047 } | 1035 } |
1048 | 1036 |
1049 /* Compare two values VAL1 and VAL2. Return | 1037 /* Compare two values VAL1 and VAL2. Return |
1050 | 1038 |
1051 -2 if VAL1 and VAL2 cannot be compared at compile-time, | 1039 -2 if VAL1 and VAL2 cannot be compared at compile-time, |
1052 -1 if VAL1 < VAL2, | 1040 -1 if VAL1 < VAL2, |
1053 0 if VAL1 == VAL2, | 1041 0 if VAL1 == VAL2, |
1054 +1 if VAL1 > VAL2, and | 1042 +1 if VAL1 > VAL2, and |
1055 +2 if VAL1 != VAL2 | 1043 +2 if VAL1 != VAL2 |
1083 || TREE_CODE (val2) == PLUS_EXPR | 1071 || TREE_CODE (val2) == PLUS_EXPR |
1084 || TREE_CODE (val2) == MINUS_EXPR)) | 1072 || TREE_CODE (val2) == MINUS_EXPR)) |
1085 { | 1073 { |
1086 tree n1, c1, n2, c2; | 1074 tree n1, c1, n2, c2; |
1087 enum tree_code code1, code2; | 1075 enum tree_code code1, code2; |
1088 | 1076 |
1089 /* If VAL1 and VAL2 are of the form 'NAME [+-] CST' or 'NAME', | 1077 /* If VAL1 and VAL2 are of the form 'NAME [+-] CST' or 'NAME', |
1090 return -1 or +1 accordingly. If VAL1 and VAL2 don't use the | 1078 return -1 or +1 accordingly. If VAL1 and VAL2 don't use the |
1091 same name, return -2. */ | 1079 same name, return -2. */ |
1092 if (TREE_CODE (val1) == SSA_NAME) | 1080 if (TREE_CODE (val1) == SSA_NAME) |
1093 { | 1081 { |
1219 tree t; | 1207 tree t; |
1220 | 1208 |
1221 /* First see if VAL1 and VAL2 are not the same. */ | 1209 /* First see if VAL1 and VAL2 are not the same. */ |
1222 if (val1 == val2 || operand_equal_p (val1, val2, 0)) | 1210 if (val1 == val2 || operand_equal_p (val1, val2, 0)) |
1223 return 0; | 1211 return 0; |
1224 | 1212 |
1225 /* If VAL1 is a lower address than VAL2, return -1. */ | 1213 /* If VAL1 is a lower address than VAL2, return -1. */ |
1226 if (operand_less_p (val1, val2) == 1) | 1214 if (operand_less_p (val1, val2) == 1) |
1227 return -1; | 1215 return -1; |
1228 | 1216 |
1229 /* If VAL1 is a higher address than VAL2, return +1. */ | 1217 /* If VAL1 is a higher address than VAL2, return +1. */ |
1280 themselves. | 1268 themselves. |
1281 | 1269 |
1282 This also applies to value_ranges_intersect_p and | 1270 This also applies to value_ranges_intersect_p and |
1283 range_includes_zero_p. The semantics of VR_RANGE and | 1271 range_includes_zero_p. The semantics of VR_RANGE and |
1284 VR_ANTI_RANGE should be encoded here, but that also means | 1272 VR_ANTI_RANGE should be encoded here, but that also means |
1285 adapting the users of these functions to the new semantics. | 1273 adapting the users of these functions to the new semantics. |
1286 | 1274 |
1287 Benchmark compile/20001226-1.c compilation time after changing this | 1275 Benchmark compile/20001226-1.c compilation time after changing this |
1288 function. */ | 1276 function. */ |
1289 | 1277 |
1290 static inline int | 1278 static inline int |
1305 return !cmp2; | 1293 return !cmp2; |
1306 } | 1294 } |
1307 | 1295 |
1308 | 1296 |
1309 /* Return true if value ranges VR0 and VR1 have a non-empty | 1297 /* Return true if value ranges VR0 and VR1 have a non-empty |
1310 intersection. | 1298 intersection. |
1311 | 1299 |
1312 Benchmark compile/20001226-1.c compilation time after changing this | 1300 Benchmark compile/20001226-1.c compilation time after changing this |
1313 function. | 1301 function. |
1314 */ | 1302 */ |
1315 | 1303 |
1316 static inline bool | 1304 static inline bool |
1363 { | 1351 { |
1364 int result = compare_values (vr->min, integer_zero_node); | 1352 int result = compare_values (vr->min, integer_zero_node); |
1365 | 1353 |
1366 return (result == 0 || result == 1); | 1354 return (result == 0 || result == 1); |
1367 } | 1355 } |
1368 return false; | |
1369 } | |
1370 | |
1371 /* Return true if T, an SSA_NAME, is known to be nonzero. Return | |
1372 false otherwise or if no value range information is available. */ | |
1373 | |
1374 bool | |
1375 ssa_name_nonzero_p (const_tree t) | |
1376 { | |
1377 value_range_t *vr = get_value_range (t); | |
1378 | |
1379 if (!vr) | |
1380 return false; | |
1381 | |
1382 /* A VR_RANGE which does not include zero is a nonzero value. */ | |
1383 if (vr->type == VR_RANGE && !symbolic_range_p (vr)) | |
1384 return ! range_includes_zero_p (vr); | |
1385 | |
1386 /* A VR_ANTI_RANGE which does include zero is a nonzero value. */ | |
1387 if (vr->type == VR_ANTI_RANGE && !symbolic_range_p (vr)) | |
1388 return range_includes_zero_p (vr); | |
1389 | |
1390 return false; | 1356 return false; |
1391 } | 1357 } |
1392 | 1358 |
1393 /* If OP has a value range with a single constant value return that, | 1359 /* If OP has a value range with a single constant value return that, |
1394 otherwise return NULL_TREE. This returns OP itself if OP is a | 1360 otherwise return NULL_TREE. This returns OP itself if OP is a |
1574 and for value 1, VAR should be ~[1, 1]. We cannot | 1540 and for value 1, VAR should be ~[1, 1]. We cannot |
1575 represent these ranges. | 1541 represent these ranges. |
1576 | 1542 |
1577 The only situation in which we can build a valid | 1543 The only situation in which we can build a valid |
1578 anti-range is when LIMIT_VR is a single-valued range | 1544 anti-range is when LIMIT_VR is a single-valued range |
1579 (i.e., LIMIT_VR->MIN == LIMIT_VR->MAX). In that case, | 1545 (i.e., LIMIT_VR->MIN == LIMIT_VR->MAX). In that case, |
1580 build the anti-range ~[LIMIT_VR->MIN, LIMIT_VR->MAX]. */ | 1546 build the anti-range ~[LIMIT_VR->MIN, LIMIT_VR->MAX]. */ |
1581 if (limit_vr | 1547 if (limit_vr |
1582 && limit_vr->type == VR_RANGE | 1548 && limit_vr->type == VR_RANGE |
1583 && compare_values (limit_vr->min, limit_vr->max) == 0) | 1549 && compare_values (limit_vr->min, limit_vr->max) == 0) |
1584 { | 1550 { |
1768 | 1734 |
1769 /* We want to compute the logical AND of the two ranges; | 1735 /* We want to compute the logical AND of the two ranges; |
1770 there are three cases to consider. | 1736 there are three cases to consider. |
1771 | 1737 |
1772 | 1738 |
1773 1. The VR_ANTI_RANGE range is completely within the | 1739 1. The VR_ANTI_RANGE range is completely within the |
1774 VR_RANGE and the endpoints of the ranges are | 1740 VR_RANGE and the endpoints of the ranges are |
1775 different. In that case the resulting range | 1741 different. In that case the resulting range |
1776 should be whichever range is more precise. | 1742 should be whichever range is more precise. |
1777 Typically that will be the VR_RANGE. | 1743 Typically that will be the VR_RANGE. |
1778 | 1744 |
2268 /* For operations that make the resulting range directly | 2234 /* For operations that make the resulting range directly |
2269 proportional to the original ranges, apply the operation to | 2235 proportional to the original ranges, apply the operation to |
2270 the same end of each range. */ | 2236 the same end of each range. */ |
2271 min = vrp_int_const_binop (code, vr0.min, vr1.min); | 2237 min = vrp_int_const_binop (code, vr0.min, vr1.min); |
2272 max = vrp_int_const_binop (code, vr0.max, vr1.max); | 2238 max = vrp_int_const_binop (code, vr0.max, vr1.max); |
2239 | |
2240 /* If both additions overflowed the range kind is still correct. | |
2241 This happens regularly with subtracting something in unsigned | |
2242 arithmetic. | |
2243 ??? See PR30318 for all the cases we do not handle. */ | |
2244 if (code == PLUS_EXPR | |
2245 && (TREE_OVERFLOW (min) && !is_overflow_infinity (min)) | |
2246 && (TREE_OVERFLOW (max) && !is_overflow_infinity (max))) | |
2247 { | |
2248 min = build_int_cst_wide (TREE_TYPE (min), | |
2249 TREE_INT_CST_LOW (min), | |
2250 TREE_INT_CST_HIGH (min)); | |
2251 max = build_int_cst_wide (TREE_TYPE (max), | |
2252 TREE_INT_CST_LOW (max), | |
2253 TREE_INT_CST_HIGH (max)); | |
2254 } | |
2273 } | 2255 } |
2274 else if (code == MULT_EXPR | 2256 else if (code == MULT_EXPR |
2275 || code == TRUNC_DIV_EXPR | 2257 || code == TRUNC_DIV_EXPR |
2276 || code == FLOOR_DIV_EXPR | 2258 || code == FLOOR_DIV_EXPR |
2277 || code == CEIL_DIV_EXPR | 2259 || code == CEIL_DIV_EXPR |
2706 && INTEGRAL_TYPE_P (TREE_TYPE (op0))) | 2688 && INTEGRAL_TYPE_P (TREE_TYPE (op0))) |
2707 { | 2689 { |
2708 tree inner_type = TREE_TYPE (op0); | 2690 tree inner_type = TREE_TYPE (op0); |
2709 tree outer_type = type; | 2691 tree outer_type = type; |
2710 | 2692 |
2711 /* Always use base-types here. This is important for the | |
2712 correct signedness. */ | |
2713 if (TREE_TYPE (inner_type)) | |
2714 inner_type = TREE_TYPE (inner_type); | |
2715 if (TREE_TYPE (outer_type)) | |
2716 outer_type = TREE_TYPE (outer_type); | |
2717 | |
2718 /* If VR0 is varying and we increase the type precision, assume | 2693 /* If VR0 is varying and we increase the type precision, assume |
2719 a full range for the following transformation. */ | 2694 a full range for the following transformation. */ |
2720 if (vr0.type == VR_VARYING | 2695 if (vr0.type == VR_VARYING |
2721 && TYPE_PRECISION (inner_type) < TYPE_PRECISION (outer_type)) | 2696 && TYPE_PRECISION (inner_type) < TYPE_PRECISION (outer_type)) |
2722 { | 2697 { |
2846 && !range_includes_zero_p (&vr0)))) | 2821 && !range_includes_zero_p (&vr0)))) |
2847 { | 2822 { |
2848 set_value_range_to_varying (vr); | 2823 set_value_range_to_varying (vr); |
2849 return; | 2824 return; |
2850 } | 2825 } |
2851 | 2826 |
2852 /* ABS_EXPR may flip the range around, if the original range | 2827 /* ABS_EXPR may flip the range around, if the original range |
2853 included negative values. */ | 2828 included negative values. */ |
2854 if (is_overflow_infinity (vr0.min)) | 2829 if (is_overflow_infinity (vr0.min)) |
2855 min = positive_overflow_infinity (type); | 2830 min = positive_overflow_infinity (type); |
2856 else if (!vrp_val_is_min (vr0.min)) | 2831 else if (!vrp_val_is_min (vr0.min)) |
2885 cmp = compare_values (min, max); | 2860 cmp = compare_values (min, max); |
2886 | 2861 |
2887 /* If a VR_ANTI_RANGEs contains zero, then we have | 2862 /* If a VR_ANTI_RANGEs contains zero, then we have |
2888 ~[-INF, min(MIN, MAX)]. */ | 2863 ~[-INF, min(MIN, MAX)]. */ |
2889 if (vr0.type == VR_ANTI_RANGE) | 2864 if (vr0.type == VR_ANTI_RANGE) |
2890 { | 2865 { |
2891 if (range_includes_zero_p (&vr0)) | 2866 if (range_includes_zero_p (&vr0)) |
2892 { | 2867 { |
2893 /* Take the lower of the two values. */ | 2868 /* Take the lower of the two values. */ |
2894 if (cmp != 1) | 2869 if (cmp != 1) |
2895 max = min; | 2870 max = min; |
3063 extract_range_from_comparison (value_range_t *vr, enum tree_code code, | 3038 extract_range_from_comparison (value_range_t *vr, enum tree_code code, |
3064 tree type, tree op0, tree op1) | 3039 tree type, tree op0, tree op1) |
3065 { | 3040 { |
3066 bool sop = false; | 3041 bool sop = false; |
3067 tree val; | 3042 tree val; |
3068 | 3043 |
3069 val = vrp_evaluate_conditional_warnv_with_ops (code, op0, op1, false, &sop, | 3044 val = vrp_evaluate_conditional_warnv_with_ops (code, op0, op1, false, &sop, |
3070 NULL); | 3045 NULL); |
3071 | 3046 |
3072 /* A disadvantage of using a special infinity as an overflow | 3047 /* A disadvantage of using a special infinity as an overflow |
3073 representation is that we lose the ability to record overflow | 3048 representation is that we lose the ability to record overflow |
3332 return false; | 3307 return false; |
3333 } | 3308 } |
3334 | 3309 |
3335 | 3310 |
3336 /* Given two numeric value ranges VR0, VR1 and a comparison code COMP: | 3311 /* Given two numeric value ranges VR0, VR1 and a comparison code COMP: |
3337 | 3312 |
3338 - Return BOOLEAN_TRUE_NODE if VR0 COMP VR1 always returns true for | 3313 - Return BOOLEAN_TRUE_NODE if VR0 COMP VR1 always returns true for |
3339 all the values in the ranges. | 3314 all the values in the ranges. |
3340 | 3315 |
3341 - Return BOOLEAN_FALSE_NODE if the comparison always returns false. | 3316 - Return BOOLEAN_FALSE_NODE if the comparison always returns false. |
3342 | 3317 |
3489 } | 3464 } |
3490 | 3465 |
3491 /* Otherwise, we don't know. */ | 3466 /* Otherwise, we don't know. */ |
3492 return NULL_TREE; | 3467 return NULL_TREE; |
3493 } | 3468 } |
3494 | 3469 |
3495 gcc_unreachable (); | 3470 gcc_unreachable (); |
3496 } | 3471 } |
3497 | 3472 |
3498 | 3473 |
3499 /* Given a value range VR, a value VAL and a comparison code COMP, return | 3474 /* Given a value range VR, a value VAL and a comparison code COMP, return |
3749 gcc_assert (TREE_CODE (v) == SSA_NAME); | 3724 gcc_assert (TREE_CODE (v) == SSA_NAME); |
3750 n = duplicate_ssa_name (v, NULL); | 3725 n = duplicate_ssa_name (v, NULL); |
3751 | 3726 |
3752 if (COMPARISON_CLASS_P (cond)) | 3727 if (COMPARISON_CLASS_P (cond)) |
3753 { | 3728 { |
3754 tree a = build2 (ASSERT_EXPR, TREE_TYPE (v), v, cond); | 3729 tree a = build2 (ASSERT_EXPR, TREE_TYPE (v), v, cond); |
3755 assertion = gimple_build_assign (n, a); | 3730 assertion = gimple_build_assign (n, a); |
3756 } | 3731 } |
3757 else if (TREE_CODE (cond) == TRUTH_NOT_EXPR) | 3732 else if (TREE_CODE (cond) == TRUTH_NOT_EXPR) |
3758 { | 3733 { |
3759 /* Given !V, build the assignment N = false. */ | 3734 /* Given !V, build the assignment N = false. */ |
3934 basic_block bb, | 3909 basic_block bb, |
3935 edge e, | 3910 edge e, |
3936 gimple_stmt_iterator si) | 3911 gimple_stmt_iterator si) |
3937 { | 3912 { |
3938 assert_locus_t n, loc, last_loc; | 3913 assert_locus_t n, loc, last_loc; |
3939 bool found; | |
3940 basic_block dest_bb; | 3914 basic_block dest_bb; |
3941 | 3915 |
3942 #if defined ENABLE_CHECKING | 3916 #if defined ENABLE_CHECKING |
3943 gcc_assert (bb == NULL || e == NULL); | 3917 gcc_assert (bb == NULL || e == NULL); |
3944 | 3918 |
3958 /* The new assertion A will be inserted at BB or E. We need to | 3932 /* The new assertion A will be inserted at BB or E. We need to |
3959 determine if the new location is dominated by a previously | 3933 determine if the new location is dominated by a previously |
3960 registered location for A. If we are doing an edge insertion, | 3934 registered location for A. If we are doing an edge insertion, |
3961 assume that A will be inserted at E->DEST. Note that this is not | 3935 assume that A will be inserted at E->DEST. Note that this is not |
3962 necessarily true. | 3936 necessarily true. |
3963 | 3937 |
3964 If E is a critical edge, it will be split. But even if E is | 3938 If E is a critical edge, it will be split. But even if E is |
3965 split, the new block will dominate the same set of blocks that | 3939 split, the new block will dominate the same set of blocks that |
3966 E->DEST dominates. | 3940 E->DEST dominates. |
3967 | 3941 |
3968 The reverse, however, is not true, blocks dominated by E->DEST | 3942 The reverse, however, is not true, blocks dominated by E->DEST |
3969 will not be dominated by the new block created to split E. So, | 3943 will not be dominated by the new block created to split E. So, |
3970 if the insertion location is on a critical edge, we will not use | 3944 if the insertion location is on a critical edge, we will not use |
3971 the new location to move another assertion previously registered | 3945 the new location to move another assertion previously registered |
3972 at a block dominated by E->DEST. */ | 3946 at a block dominated by E->DEST. */ |
3983 should not be more than a handful of assertions registered per | 3957 should not be more than a handful of assertions registered per |
3984 name. If this becomes a performance problem, a table hashed by | 3958 name. If this becomes a performance problem, a table hashed by |
3985 COMP_CODE and VAL could be implemented. */ | 3959 COMP_CODE and VAL could be implemented. */ |
3986 loc = asserts_for[SSA_NAME_VERSION (name)]; | 3960 loc = asserts_for[SSA_NAME_VERSION (name)]; |
3987 last_loc = loc; | 3961 last_loc = loc; |
3988 found = false; | |
3989 while (loc) | 3962 while (loc) |
3990 { | 3963 { |
3991 if (loc->comp_code == comp_code | 3964 if (loc->comp_code == comp_code |
3992 && (loc->val == val | 3965 && (loc->val == val |
3993 || operand_equal_p (loc->val, val, 0)) | 3966 || operand_equal_p (loc->val, val, 0)) |
4245 return retval; | 4218 return retval; |
4246 } | 4219 } |
4247 | 4220 |
4248 /* OP is an operand of a truth value expression which is known to have | 4221 /* OP is an operand of a truth value expression which is known to have |
4249 a particular value. Register any asserts for OP and for any | 4222 a particular value. Register any asserts for OP and for any |
4250 operands in OP's defining statement. | 4223 operands in OP's defining statement. |
4251 | 4224 |
4252 If CODE is EQ_EXPR, then we want to register OP is zero (false), | 4225 If CODE is EQ_EXPR, then we want to register OP is zero (false), |
4253 if CODE is NE_EXPR, then we want to register OP is nonzero (true). */ | 4226 if CODE is NE_EXPR, then we want to register OP is nonzero (true). */ |
4254 | 4227 |
4255 static bool | 4228 static bool |
4264 /* We only care about SSA_NAMEs. */ | 4237 /* We only care about SSA_NAMEs. */ |
4265 if (TREE_CODE (op) != SSA_NAME) | 4238 if (TREE_CODE (op) != SSA_NAME) |
4266 return false; | 4239 return false; |
4267 | 4240 |
4268 /* We know that OP will have a zero or nonzero value. If OP is used | 4241 /* We know that OP will have a zero or nonzero value. If OP is used |
4269 more than once go ahead and register an assert for OP. | 4242 more than once go ahead and register an assert for OP. |
4270 | 4243 |
4271 The FOUND_IN_SUBGRAPH support is not helpful in this situation as | 4244 The FOUND_IN_SUBGRAPH support is not helpful in this situation as |
4272 it will always be set for OP (because OP is used in a COND_EXPR in | 4245 it will always be set for OP (because OP is used in a COND_EXPR in |
4273 the subgraph). */ | 4246 the subgraph). */ |
4274 if (!has_single_use (op)) | 4247 if (!has_single_use (op)) |
4325 /* Recurse through the copy. */ | 4298 /* Recurse through the copy. */ |
4326 retval |= register_edge_assert_for_1 (gimple_assign_rhs1 (op_def), | 4299 retval |= register_edge_assert_for_1 (gimple_assign_rhs1 (op_def), |
4327 code, e, bsi); | 4300 code, e, bsi); |
4328 } | 4301 } |
4329 else if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (op_def))) | 4302 else if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (op_def))) |
4330 { | 4303 { |
4331 /* Recurse through the type conversion. */ | 4304 /* Recurse through the type conversion. */ |
4332 retval |= register_edge_assert_for_1 (gimple_assign_rhs1 (op_def), | 4305 retval |= register_edge_assert_for_1 (gimple_assign_rhs1 (op_def), |
4333 code, e, bsi); | 4306 code, e, bsi); |
4334 } | 4307 } |
4335 | 4308 |
4580 /* Traverse all the statements in block BB looking for statements that | 4553 /* Traverse all the statements in block BB looking for statements that |
4581 may generate useful assertions for the SSA names in their operand. | 4554 may generate useful assertions for the SSA names in their operand. |
4582 If a statement produces a useful assertion A for name N_i, then the | 4555 If a statement produces a useful assertion A for name N_i, then the |
4583 list of assertions already generated for N_i is scanned to | 4556 list of assertions already generated for N_i is scanned to |
4584 determine if A is actually needed. | 4557 determine if A is actually needed. |
4585 | 4558 |
4586 If N_i already had the assertion A at a location dominating the | 4559 If N_i already had the assertion A at a location dominating the |
4587 current location, then nothing needs to be done. Otherwise, the | 4560 current location, then nothing needs to be done. Otherwise, the |
4588 new location for A is recorded instead. | 4561 new location for A is recorded instead. |
4589 | 4562 |
4590 1- For every statement S in BB, all the variables used by S are | 4563 1- For every statement S in BB, all the variables used by S are |
4624 determine that 'a' is always 9 on that edge. However, an assertion | 4597 determine that 'a' is always 9 on that edge. However, an assertion |
4625 on the ELSE clause would be unnecessary. | 4598 on the ELSE clause would be unnecessary. |
4626 | 4599 |
4627 4- If BB does not end in a conditional expression, then we recurse | 4600 4- If BB does not end in a conditional expression, then we recurse |
4628 into BB's dominator children. | 4601 into BB's dominator children. |
4629 | 4602 |
4630 At the end of the recursive traversal, every SSA name will have a | 4603 At the end of the recursive traversal, every SSA name will have a |
4631 list of locations where ASSERT_EXPRs should be added. When a new | 4604 list of locations where ASSERT_EXPRs should be added. When a new |
4632 location for name N is found, it is registered by calling | 4605 location for name N is found, it is registered by calling |
4633 register_new_assert_for. That function keeps track of all the | 4606 register_new_assert_for. That function keeps track of all the |
4634 registered assertions to prevent adding unnecessary assertions. | 4607 registered assertions to prevent adding unnecessary assertions. |
4674 tree op; | 4647 tree op; |
4675 ssa_op_iter i; | 4648 ssa_op_iter i; |
4676 | 4649 |
4677 stmt = gsi_stmt (si); | 4650 stmt = gsi_stmt (si); |
4678 | 4651 |
4652 if (is_gimple_debug (stmt)) | |
4653 continue; | |
4654 | |
4679 /* See if we can derive an assertion for any of STMT's operands. */ | 4655 /* See if we can derive an assertion for any of STMT's operands. */ |
4680 FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_USE) | 4656 FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_USE) |
4681 { | 4657 { |
4682 tree value; | 4658 tree value; |
4683 enum tree_code comp_code; | 4659 enum tree_code comp_code; |
4698 for the operand of the NOP_EXPR. */ | 4674 for the operand of the NOP_EXPR. */ |
4699 if (comp_code == NE_EXPR && integer_zerop (value)) | 4675 if (comp_code == NE_EXPR && integer_zerop (value)) |
4700 { | 4676 { |
4701 tree t = op; | 4677 tree t = op; |
4702 gimple def_stmt = SSA_NAME_DEF_STMT (t); | 4678 gimple def_stmt = SSA_NAME_DEF_STMT (t); |
4703 | 4679 |
4704 while (is_gimple_assign (def_stmt) | 4680 while (is_gimple_assign (def_stmt) |
4705 && gimple_assign_rhs_code (def_stmt) == NOP_EXPR | 4681 && gimple_assign_rhs_code (def_stmt) == NOP_EXPR |
4706 && TREE_CODE | 4682 && TREE_CODE |
4707 (gimple_assign_rhs1 (def_stmt)) == SSA_NAME | 4683 (gimple_assign_rhs1 (def_stmt)) == SSA_NAME |
4708 && POINTER_TYPE_P | 4684 && POINTER_TYPE_P |
4994 range. If the array subscript is a RANGE, warn if it is | 4970 range. If the array subscript is a RANGE, warn if it is |
4995 non-overlapping with valid range. | 4971 non-overlapping with valid range. |
4996 IGNORE_OFF_BY_ONE is true if the ARRAY_REF is inside a ADDR_EXPR. */ | 4972 IGNORE_OFF_BY_ONE is true if the ARRAY_REF is inside a ADDR_EXPR. */ |
4997 | 4973 |
4998 static void | 4974 static void |
4999 check_array_ref (tree ref, const location_t *location, bool ignore_off_by_one) | 4975 check_array_ref (location_t location, tree ref, bool ignore_off_by_one) |
5000 { | 4976 { |
5001 value_range_t* vr = NULL; | 4977 value_range_t* vr = NULL; |
5002 tree low_sub, up_sub; | 4978 tree low_sub, up_sub; |
5003 tree low_bound, up_bound = array_ref_up_bound (ref); | 4979 tree low_bound, up_bound = array_ref_up_bound (ref); |
5004 | 4980 |
5033 if (TREE_CODE (up_sub) == INTEGER_CST | 5009 if (TREE_CODE (up_sub) == INTEGER_CST |
5034 && tree_int_cst_lt (up_bound, up_sub) | 5010 && tree_int_cst_lt (up_bound, up_sub) |
5035 && TREE_CODE (low_sub) == INTEGER_CST | 5011 && TREE_CODE (low_sub) == INTEGER_CST |
5036 && tree_int_cst_lt (low_sub, low_bound)) | 5012 && tree_int_cst_lt (low_sub, low_bound)) |
5037 { | 5013 { |
5038 warning (OPT_Warray_bounds, | 5014 warning_at (location, OPT_Warray_bounds, |
5039 "%Harray subscript is outside array bounds", location); | 5015 "array subscript is outside array bounds"); |
5040 TREE_NO_WARNING (ref) = 1; | 5016 TREE_NO_WARNING (ref) = 1; |
5041 } | 5017 } |
5042 } | 5018 } |
5043 else if (TREE_CODE (up_sub) == INTEGER_CST | 5019 else if (TREE_CODE (up_sub) == INTEGER_CST |
5044 && tree_int_cst_lt (up_bound, up_sub) | 5020 && tree_int_cst_lt (up_bound, up_sub) |
5048 up_bound, | 5024 up_bound, |
5049 integer_one_node, | 5025 integer_one_node, |
5050 0), | 5026 0), |
5051 up_sub))) | 5027 up_sub))) |
5052 { | 5028 { |
5053 warning (OPT_Warray_bounds, "%Harray subscript is above array bounds", | 5029 warning_at (location, OPT_Warray_bounds, |
5054 location); | 5030 "array subscript is above array bounds"); |
5055 TREE_NO_WARNING (ref) = 1; | 5031 TREE_NO_WARNING (ref) = 1; |
5056 } | 5032 } |
5057 else if (TREE_CODE (low_sub) == INTEGER_CST | 5033 else if (TREE_CODE (low_sub) == INTEGER_CST |
5058 && tree_int_cst_lt (low_sub, low_bound)) | 5034 && tree_int_cst_lt (low_sub, low_bound)) |
5059 { | 5035 { |
5060 warning (OPT_Warray_bounds, "%Harray subscript is below array bounds", | 5036 warning_at (location, OPT_Warray_bounds, |
5061 location); | 5037 "array subscript is below array bounds"); |
5062 TREE_NO_WARNING (ref) = 1; | 5038 TREE_NO_WARNING (ref) = 1; |
5063 } | 5039 } |
5064 } | 5040 } |
5065 | 5041 |
5066 /* Searches if the expr T, located at LOCATION computes | 5042 /* Searches if the expr T, located at LOCATION computes |
5067 address of an ARRAY_REF, and call check_array_ref on it. */ | 5043 address of an ARRAY_REF, and call check_array_ref on it. */ |
5068 | 5044 |
5069 static void | 5045 static void |
5070 search_for_addr_array (tree t, const location_t *location) | 5046 search_for_addr_array (tree t, location_t location) |
5071 { | 5047 { |
5072 while (TREE_CODE (t) == SSA_NAME) | 5048 while (TREE_CODE (t) == SSA_NAME) |
5073 { | 5049 { |
5074 gimple g = SSA_NAME_DEF_STMT (t); | 5050 gimple g = SSA_NAME_DEF_STMT (t); |
5075 | 5051 |
5076 if (gimple_code (g) != GIMPLE_ASSIGN) | 5052 if (gimple_code (g) != GIMPLE_ASSIGN) |
5077 return; | 5053 return; |
5078 | 5054 |
5079 if (get_gimple_rhs_class (gimple_assign_rhs_code (g)) | 5055 if (get_gimple_rhs_class (gimple_assign_rhs_code (g)) |
5080 != GIMPLE_SINGLE_RHS) | 5056 != GIMPLE_SINGLE_RHS) |
5081 return; | 5057 return; |
5082 | 5058 |
5083 t = gimple_assign_rhs1 (g); | 5059 t = gimple_assign_rhs1 (g); |
5084 } | 5060 } |
5085 | 5061 |
5086 | 5062 |
5087 /* We are only interested in addresses of ARRAY_REF's. */ | 5063 /* We are only interested in addresses of ARRAY_REF's. */ |
5088 if (TREE_CODE (t) != ADDR_EXPR) | 5064 if (TREE_CODE (t) != ADDR_EXPR) |
5089 return; | 5065 return; |
5090 | 5066 |
5091 /* Check each ARRAY_REFs in the reference chain. */ | 5067 /* Check each ARRAY_REFs in the reference chain. */ |
5092 do | 5068 do |
5093 { | 5069 { |
5094 if (TREE_CODE (t) == ARRAY_REF) | 5070 if (TREE_CODE (t) == ARRAY_REF) |
5095 check_array_ref (t, location, true /*ignore_off_by_one*/); | 5071 check_array_ref (location, t, true /*ignore_off_by_one*/); |
5096 | 5072 |
5097 t = TREE_OPERAND (t, 0); | 5073 t = TREE_OPERAND (t, 0); |
5098 } | 5074 } |
5099 while (handled_component_p (t)); | 5075 while (handled_component_p (t)); |
5100 } | 5076 } |
5101 | 5077 |
5102 /* walk_tree() callback that checks if *TP is | 5078 /* walk_tree() callback that checks if *TP is |
5103 an ARRAY_REF inside an ADDR_EXPR (in which an array | 5079 an ARRAY_REF inside an ADDR_EXPR (in which an array |
5104 subscript one outside the valid range is allowed). Call | 5080 subscript one outside the valid range is allowed). Call |
5105 check_array_ref for each ARRAY_REF found. The location is | 5081 check_array_ref for each ARRAY_REF found. The location is |
5106 passed in DATA. */ | 5082 passed in DATA. */ |
5107 | 5083 |
5108 static tree | 5084 static tree |
5109 check_array_bounds (tree *tp, int *walk_subtree, void *data) | 5085 check_array_bounds (tree *tp, int *walk_subtree, void *data) |
5110 { | 5086 { |
5111 tree t = *tp; | 5087 tree t = *tp; |
5112 struct walk_stmt_info *wi = (struct walk_stmt_info *) data; | 5088 struct walk_stmt_info *wi = (struct walk_stmt_info *) data; |
5113 const location_t *location = (const location_t *) wi->info; | 5089 location_t location; |
5090 | |
5091 if (EXPR_HAS_LOCATION (t)) | |
5092 location = EXPR_LOCATION (t); | |
5093 else | |
5094 { | |
5095 location_t *locp = (location_t *) wi->info; | |
5096 location = *locp; | |
5097 } | |
5114 | 5098 |
5115 *walk_subtree = TRUE; | 5099 *walk_subtree = TRUE; |
5116 | 5100 |
5117 if (TREE_CODE (t) == ARRAY_REF) | 5101 if (TREE_CODE (t) == ARRAY_REF) |
5118 check_array_ref (t, location, false /*ignore_off_by_one*/); | 5102 check_array_ref (location, t, false /*ignore_off_by_one*/); |
5119 | 5103 |
5120 if (TREE_CODE (t) == INDIRECT_REF | 5104 if (TREE_CODE (t) == INDIRECT_REF |
5121 || (TREE_CODE (t) == RETURN_EXPR && TREE_OPERAND (t, 0))) | 5105 || (TREE_CODE (t) == RETURN_EXPR && TREE_OPERAND (t, 0))) |
5122 search_for_addr_array (TREE_OPERAND (t, 0), location); | 5106 search_for_addr_array (TREE_OPERAND (t, 0), location); |
5123 | 5107 |
5139 FOR_EACH_BB (bb) | 5123 FOR_EACH_BB (bb) |
5140 { | 5124 { |
5141 /* Skip bb's that are clearly unreachable. */ | 5125 /* Skip bb's that are clearly unreachable. */ |
5142 if (single_pred_p (bb)) | 5126 if (single_pred_p (bb)) |
5143 { | 5127 { |
5144 basic_block pred_bb = EDGE_PRED (bb, 0)->src; | 5128 int i; |
5129 bool reachable = true; | |
5130 edge e2; | |
5131 edge e = EDGE_PRED (bb, 0); | |
5132 basic_block pred_bb = e->src; | |
5145 gimple ls = NULL; | 5133 gimple ls = NULL; |
5134 | |
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; | |
5146 | 5144 |
5147 if (!gsi_end_p (gsi_last_bb (pred_bb))) | 5145 if (!gsi_end_p (gsi_last_bb (pred_bb))) |
5148 ls = gsi_stmt (gsi_last_bb (pred_bb)); | 5146 ls = gsi_stmt (gsi_last_bb (pred_bb)); |
5149 | 5147 |
5150 if (ls && gimple_code (ls) == GIMPLE_COND | 5148 if (ls && gimple_code (ls) == GIMPLE_COND |
5155 continue; | 5153 continue; |
5156 } | 5154 } |
5157 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) | 5155 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) |
5158 { | 5156 { |
5159 gimple stmt = gsi_stmt (si); | 5157 gimple stmt = gsi_stmt (si); |
5160 const location_t *location = gimple_location_ptr (stmt); | |
5161 struct walk_stmt_info wi; | 5158 struct walk_stmt_info wi; |
5162 if (!gimple_has_location (stmt)) | 5159 if (!gimple_has_location (stmt)) |
5163 continue; | 5160 continue; |
5164 | 5161 |
5165 if (is_gimple_call (stmt)) | 5162 if (is_gimple_call (stmt)) |
5167 size_t i; | 5164 size_t i; |
5168 size_t n = gimple_call_num_args (stmt); | 5165 size_t n = gimple_call_num_args (stmt); |
5169 for (i = 0; i < n; i++) | 5166 for (i = 0; i < n; i++) |
5170 { | 5167 { |
5171 tree arg = gimple_call_arg (stmt, i); | 5168 tree arg = gimple_call_arg (stmt, i); |
5172 search_for_addr_array (arg, location); | 5169 search_for_addr_array (arg, gimple_location (stmt)); |
5173 } | 5170 } |
5174 } | 5171 } |
5175 else | 5172 else |
5176 { | 5173 { |
5177 memset (&wi, 0, sizeof (wi)); | 5174 memset (&wi, 0, sizeof (wi)); |
5178 wi.info = CONST_CAST (void *, (const void *) location); | 5175 wi.info = CONST_CAST (void *, (const void *) |
5176 gimple_location_ptr (stmt)); | |
5179 | 5177 |
5180 walk_gimple_op (gsi_stmt (si), | 5178 walk_gimple_op (gsi_stmt (si), |
5181 check_array_bounds, | 5179 check_array_bounds, |
5182 &wi); | 5180 &wi); |
5183 } | 5181 } |
5186 } | 5184 } |
5187 | 5185 |
5188 /* Convert range assertion expressions into the implied copies and | 5186 /* Convert range assertion expressions into the implied copies and |
5189 copy propagate away the copies. Doing the trivial copy propagation | 5187 copy propagate away the copies. Doing the trivial copy propagation |
5190 here avoids the need to run the full copy propagation pass after | 5188 here avoids the need to run the full copy propagation pass after |
5191 VRP. | 5189 VRP. |
5192 | 5190 |
5193 FIXME, this will eventually lead to copy propagation removing the | 5191 FIXME, this will eventually lead to copy propagation removing the |
5194 names that had useful range information attached to them. For | 5192 names that had useful range information attached to them. For |
5195 instance, if we had the assertion N_i = ASSERT_EXPR <N_j, N_j > 3>, | 5193 instance, if we had the assertion N_i = ASSERT_EXPR <N_j, N_j > 3>, |
5196 then N_i will have the range [3, +INF]. | 5194 then N_i will have the range [3, +INF]. |
5197 | 5195 |
5198 However, by converting the assertion into the implied copy | 5196 However, by converting the assertion into the implied copy |
5199 operation N_i = N_j, we will then copy-propagate N_j into the uses | 5197 operation N_i = N_j, we will then copy-propagate N_j into the uses |
5200 of N_i and lose the range information. We may want to hold on to | 5198 of N_i and lose the range information. We may want to hold on to |
5201 ASSERT_EXPRs a little while longer as the ranges could be used in | 5199 ASSERT_EXPRs a little while longer as the ranges could be used in |
5202 things like jump threading. | 5200 things like jump threading. |
5203 | 5201 |
5204 The problem with keeping ASSERT_EXPRs around is that passes after | 5202 The problem with keeping ASSERT_EXPRs around is that passes after |
5205 VRP need to handle them appropriately. | 5203 VRP need to handle them appropriately. |
5206 | 5204 |
5207 Another approach would be to make the range information a first | 5205 Another approach would be to make the range information a first |
5208 class property of the SSA_NAME so that it can be queried from | 5206 class property of the SSA_NAME so that it can be queried from |
5209 any pass. This is made somewhat more complex by the need for | 5207 any pass. This is made somewhat more complex by the need for |
5210 multiple ranges to be associated with one SSA_NAME. */ | 5208 multiple ranges to be associated with one SSA_NAME. */ |
5245 gcc_assert (TREE_CODE (var) == SSA_NAME); | 5243 gcc_assert (TREE_CODE (var) == SSA_NAME); |
5246 } | 5244 } |
5247 | 5245 |
5248 /* And finally, remove the copy, it is not needed. */ | 5246 /* And finally, remove the copy, it is not needed. */ |
5249 gsi_remove (&si, true); | 5247 gsi_remove (&si, true); |
5250 release_defs (stmt); | 5248 release_defs (stmt); |
5251 } | 5249 } |
5252 else | 5250 else |
5253 gsi_next (&si); | 5251 gsi_next (&si); |
5254 } | 5252 } |
5255 } | 5253 } |
5276 && (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) | 5274 && (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) |
5277 || POINTER_TYPE_P (TREE_TYPE (lhs))) | 5275 || POINTER_TYPE_P (TREE_TYPE (lhs))) |
5278 && ((is_gimple_call (stmt) | 5276 && ((is_gimple_call (stmt) |
5279 && gimple_call_fndecl (stmt) != NULL_TREE | 5277 && gimple_call_fndecl (stmt) != NULL_TREE |
5280 && DECL_IS_BUILTIN (gimple_call_fndecl (stmt))) | 5278 && DECL_IS_BUILTIN (gimple_call_fndecl (stmt))) |
5281 || ZERO_SSA_OPERANDS (stmt, SSA_OP_ALL_VIRTUALS))) | 5279 || !gimple_vuse (stmt))) |
5282 return true; | 5280 return true; |
5283 } | 5281 } |
5284 else if (gimple_code (stmt) == GIMPLE_COND | 5282 else if (gimple_code (stmt) == GIMPLE_COND |
5285 || gimple_code (stmt) == GIMPLE_SWITCH) | 5283 || gimple_code (stmt) == GIMPLE_SWITCH) |
5286 return true; | 5284 return true; |
5318 | 5316 |
5319 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) | 5317 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) |
5320 { | 5318 { |
5321 gimple stmt = gsi_stmt (si); | 5319 gimple stmt = gsi_stmt (si); |
5322 | 5320 |
5323 if (!stmt_interesting_for_vrp (stmt)) | 5321 /* If the statement is a control insn, then we do not |
5322 want to avoid simulating the statement once. Failure | |
5323 to do so means that those edges will never get added. */ | |
5324 if (stmt_ends_bb_p (stmt)) | |
5325 prop_set_simulate_again (stmt, true); | |
5326 else if (!stmt_interesting_for_vrp (stmt)) | |
5324 { | 5327 { |
5325 ssa_op_iter i; | 5328 ssa_op_iter i; |
5326 tree def; | 5329 tree def; |
5327 FOR_EACH_SSA_TREE_OPERAND (def, stmt, i, SSA_OP_DEF) | 5330 FOR_EACH_SSA_TREE_OPERAND (def, stmt, i, SSA_OP_DEF) |
5328 set_value_range_to_varying (get_value_range (def)); | 5331 set_value_range_to_varying (get_value_range (def)); |
5329 prop_set_simulate_again (stmt, false); | 5332 prop_set_simulate_again (stmt, false); |
5330 } | 5333 } |
5331 else | 5334 else |
5332 { | 5335 prop_set_simulate_again (stmt, true); |
5333 prop_set_simulate_again (stmt, true); | |
5334 } | |
5335 } | 5336 } |
5336 } | 5337 } |
5337 } | 5338 } |
5338 | 5339 |
5339 | 5340 |
5390 return SSA_PROP_INTERESTING; | 5391 return SSA_PROP_INTERESTING; |
5391 } | 5392 } |
5392 | 5393 |
5393 return SSA_PROP_NOT_INTERESTING; | 5394 return SSA_PROP_NOT_INTERESTING; |
5394 } | 5395 } |
5395 | 5396 |
5396 /* Every other statement produces no useful ranges. */ | 5397 /* Every other statement produces no useful ranges. */ |
5397 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF) | 5398 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF) |
5398 set_value_range_to_varying (get_value_range (def)); | 5399 set_value_range_to_varying (get_value_range (def)); |
5399 | 5400 |
5400 return SSA_PROP_VARYING; | 5401 return SSA_PROP_VARYING; |
5673 The ranges of all the names equivalent with the operands in COND | 5674 The ranges of all the names equivalent with the operands in COND |
5674 will be used when trying to compute the value. If the result is | 5675 will be used when trying to compute the value. If the result is |
5675 based on undefined signed overflow, issue a warning if | 5676 based on undefined signed overflow, issue a warning if |
5676 appropriate. */ | 5677 appropriate. */ |
5677 | 5678 |
5678 tree | 5679 static tree |
5679 vrp_evaluate_conditional (enum tree_code code, tree op0, tree op1, gimple stmt) | 5680 vrp_evaluate_conditional (enum tree_code code, tree op0, tree op1, gimple stmt) |
5680 { | 5681 { |
5681 bool sop; | 5682 bool sop; |
5682 tree ret; | 5683 tree ret; |
5683 bool only_ranges; | 5684 bool only_ranges; |
5718 | 5719 |
5719 if (!gimple_has_location (stmt)) | 5720 if (!gimple_has_location (stmt)) |
5720 location = input_location; | 5721 location = input_location; |
5721 else | 5722 else |
5722 location = gimple_location (stmt); | 5723 location = gimple_location (stmt); |
5723 warning (OPT_Wstrict_overflow, "%H%s", &location, warnmsg); | 5724 warning_at (location, OPT_Wstrict_overflow, "%s", warnmsg); |
5724 } | 5725 } |
5725 } | 5726 } |
5726 | 5727 |
5727 if (warn_type_limits | 5728 if (warn_type_limits |
5728 && ret && only_ranges | 5729 && ret && only_ranges |
5732 /* If the comparison is being folded and the operand on the LHS | 5733 /* If the comparison is being folded and the operand on the LHS |
5733 is being compared against a constant value that is outside of | 5734 is being compared against a constant value that is outside of |
5734 the natural range of OP0's type, then the predicate will | 5735 the natural range of OP0's type, then the predicate will |
5735 always fold regardless of the value of OP0. If -Wtype-limits | 5736 always fold regardless of the value of OP0. If -Wtype-limits |
5736 was specified, emit a warning. */ | 5737 was specified, emit a warning. */ |
5737 const char *warnmsg = NULL; | |
5738 tree type = TREE_TYPE (op0); | 5738 tree type = TREE_TYPE (op0); |
5739 value_range_t *vr0 = get_value_range (op0); | 5739 value_range_t *vr0 = get_value_range (op0); |
5740 | 5740 |
5741 if (vr0->type != VR_VARYING | 5741 if (vr0->type != VR_VARYING |
5742 && INTEGRAL_TYPE_P (type) | 5742 && INTEGRAL_TYPE_P (type) |
5743 && vrp_val_is_min (vr0->min) | 5743 && vrp_val_is_min (vr0->min) |
5744 && vrp_val_is_max (vr0->max) | 5744 && vrp_val_is_max (vr0->max) |
5745 && is_gimple_min_invariant (op1)) | 5745 && is_gimple_min_invariant (op1)) |
5746 { | 5746 { |
5747 if (integer_zerop (ret)) | |
5748 warnmsg = G_("comparison always false due to limited range of " | |
5749 "data type"); | |
5750 else | |
5751 warnmsg = G_("comparison always true due to limited range of " | |
5752 "data type"); | |
5753 } | |
5754 | |
5755 if (warnmsg) | |
5756 { | |
5757 location_t location; | 5747 location_t location; |
5758 | 5748 |
5759 if (!gimple_has_location (stmt)) | 5749 if (!gimple_has_location (stmt)) |
5760 location = input_location; | 5750 location = input_location; |
5761 else | 5751 else |
5762 location = gimple_location (stmt); | 5752 location = gimple_location (stmt); |
5763 | 5753 |
5764 warning (OPT_Wtype_limits, "%H%s", &location, warnmsg); | 5754 warning_at (location, OPT_Wtype_limits, |
5755 integer_zerop (ret) | |
5756 ? G_("comparison always false " | |
5757 "due to limited range of data type") | |
5758 : G_("comparison always true " | |
5759 "due to limited range of data type")); | |
5765 } | 5760 } |
5766 } | 5761 } |
5767 | 5762 |
5768 return ret; | 5763 return ret; |
5769 } | 5764 } |
5788 ssa_op_iter i; | 5783 ssa_op_iter i; |
5789 | 5784 |
5790 fprintf (dump_file, "\nVisiting conditional with predicate: "); | 5785 fprintf (dump_file, "\nVisiting conditional with predicate: "); |
5791 print_gimple_stmt (dump_file, stmt, 0, 0); | 5786 print_gimple_stmt (dump_file, stmt, 0, 0); |
5792 fprintf (dump_file, "\nWith known ranges\n"); | 5787 fprintf (dump_file, "\nWith known ranges\n"); |
5793 | 5788 |
5794 FOR_EACH_SSA_TREE_OPERAND (use, stmt, i, SSA_OP_USE) | 5789 FOR_EACH_SSA_TREE_OPERAND (use, stmt, i, SSA_OP_USE) |
5795 { | 5790 { |
5796 fprintf (dump_file, "\t"); | 5791 fprintf (dump_file, "\t"); |
5797 print_generic_expr (dump_file, use, 0); | 5792 print_generic_expr (dump_file, use, 0); |
5798 fprintf (dump_file, ": "); | 5793 fprintf (dump_file, ": "); |
5802 fprintf (dump_file, "\n"); | 5797 fprintf (dump_file, "\n"); |
5803 } | 5798 } |
5804 | 5799 |
5805 /* Compute the value of the predicate COND by checking the known | 5800 /* Compute the value of the predicate COND by checking the known |
5806 ranges of each of its operands. | 5801 ranges of each of its operands. |
5807 | 5802 |
5808 Note that we cannot evaluate all the equivalent ranges here | 5803 Note that we cannot evaluate all the equivalent ranges here |
5809 because those ranges may not yet be final and with the current | 5804 because those ranges may not yet be final and with the current |
5810 propagation strategy, we cannot determine when the value ranges | 5805 propagation strategy, we cannot determine when the value ranges |
5811 of the names in the equivalence set have changed. | 5806 of the names in the equivalence set have changed. |
5812 | 5807 |
5881 [START_IDX, n - 1] where n is the size of VEC. | 5876 [START_IDX, n - 1] where n is the size of VEC. |
5882 | 5877 |
5883 If there is a CASE_LABEL for VAL, its index is placed in IDX and true is | 5878 If there is a CASE_LABEL for VAL, its index is placed in IDX and true is |
5884 returned. | 5879 returned. |
5885 | 5880 |
5886 If there is no CASE_LABEL for VAL and the is one that is larger than VAL, | 5881 If there is no CASE_LABEL for VAL and there is one that is larger than VAL, |
5887 it is placed in IDX and false is returned. | 5882 it is placed in IDX and false is returned. |
5888 | 5883 |
5889 If VAL is larger than any CASE_LABEL, n is placed on IDX and false is | 5884 If VAL is larger than any CASE_LABEL, n is placed on IDX and false is |
5890 returned. */ | 5885 returned. */ |
5891 | 5886 |
5949 | 5944 |
5950 if (i == j | 5945 if (i == j |
5951 && min_take_default | 5946 && min_take_default |
5952 && max_take_default) | 5947 && max_take_default) |
5953 { | 5948 { |
5954 /* Only the default case label reached. | 5949 /* Only the default case label reached. |
5955 Return an empty range. */ | 5950 Return an empty range. */ |
5956 *min_idx = 1; | 5951 *min_idx = 1; |
5957 *max_idx = 0; | 5952 *max_idx = 0; |
5958 return false; | 5953 return false; |
5959 } | 5954 } |
5998 static enum ssa_prop_result | 5993 static enum ssa_prop_result |
5999 vrp_visit_switch_stmt (gimple stmt, edge *taken_edge_p) | 5994 vrp_visit_switch_stmt (gimple stmt, edge *taken_edge_p) |
6000 { | 5995 { |
6001 tree op, val; | 5996 tree op, val; |
6002 value_range_t *vr; | 5997 value_range_t *vr; |
6003 size_t i = 0, j = 0, n; | 5998 size_t i = 0, j = 0; |
6004 bool take_default; | 5999 bool take_default; |
6005 | 6000 |
6006 *taken_edge_p = NULL; | 6001 *taken_edge_p = NULL; |
6007 op = gimple_switch_index (stmt); | 6002 op = gimple_switch_index (stmt); |
6008 if (TREE_CODE (op) != SSA_NAME) | 6003 if (TREE_CODE (op) != SSA_NAME) |
6021 if (vr->type != VR_RANGE | 6016 if (vr->type != VR_RANGE |
6022 || symbolic_range_p (vr)) | 6017 || symbolic_range_p (vr)) |
6023 return SSA_PROP_VARYING; | 6018 return SSA_PROP_VARYING; |
6024 | 6019 |
6025 /* Find the single edge that is taken from the switch expression. */ | 6020 /* Find the single edge that is taken from the switch expression. */ |
6026 n = gimple_switch_num_labels (stmt); | |
6027 | |
6028 take_default = !find_case_label_range (stmt, vr->min, vr->max, &i, &j); | 6021 take_default = !find_case_label_range (stmt, vr->min, vr->max, &i, &j); |
6029 | 6022 |
6030 /* Check if the range spans no CASE_LABEL. If so, we only reach the default | 6023 /* Check if the range spans no CASE_LABEL. If so, we only reach the default |
6031 label */ | 6024 label */ |
6032 if (j < i) | 6025 if (j < i) |
6094 fprintf (dump_file, "\nVisiting statement:\n"); | 6087 fprintf (dump_file, "\nVisiting statement:\n"); |
6095 print_gimple_stmt (dump_file, stmt, 0, dump_flags); | 6088 print_gimple_stmt (dump_file, stmt, 0, dump_flags); |
6096 fprintf (dump_file, "\n"); | 6089 fprintf (dump_file, "\n"); |
6097 } | 6090 } |
6098 | 6091 |
6099 if (is_gimple_assign (stmt) || is_gimple_call (stmt)) | 6092 if (!stmt_interesting_for_vrp (stmt)) |
6093 gcc_assert (stmt_ends_bb_p (stmt)); | |
6094 else if (is_gimple_assign (stmt) || is_gimple_call (stmt)) | |
6100 { | 6095 { |
6101 /* In general, assignments with virtual operands are not useful | 6096 /* In general, assignments with virtual operands are not useful |
6102 for deriving ranges, with the obvious exception of calls to | 6097 for deriving ranges, with the obvious exception of calls to |
6103 builtin functions. */ | 6098 builtin functions. */ |
6104 | 6099 |
6105 if ((is_gimple_call (stmt) | 6100 if ((is_gimple_call (stmt) |
6106 && gimple_call_fndecl (stmt) != NULL_TREE | 6101 && gimple_call_fndecl (stmt) != NULL_TREE |
6107 && DECL_IS_BUILTIN (gimple_call_fndecl (stmt))) | 6102 && DECL_IS_BUILTIN (gimple_call_fndecl (stmt))) |
6108 || ZERO_SSA_OPERANDS (stmt, SSA_OP_ALL_VIRTUALS)) | 6103 || !gimple_vuse (stmt)) |
6109 return vrp_visit_assignment_or_call (stmt, output_p); | 6104 return vrp_visit_assignment_or_call (stmt, output_p); |
6110 } | 6105 } |
6111 else if (gimple_code (stmt) == GIMPLE_COND) | 6106 else if (gimple_code (stmt) == GIMPLE_COND) |
6112 return vrp_visit_cond_stmt (stmt, taken_edge_p); | 6107 return vrp_visit_cond_stmt (stmt, taken_edge_p); |
6113 else if (gimple_code (stmt) == GIMPLE_SWITCH) | 6108 else if (gimple_code (stmt) == GIMPLE_SWITCH) |
6597 | 6592 |
6598 if (!gimple_has_location (stmt)) | 6593 if (!gimple_has_location (stmt)) |
6599 location = input_location; | 6594 location = input_location; |
6600 else | 6595 else |
6601 location = gimple_location (stmt); | 6596 location = gimple_location (stmt); |
6602 warning (OPT_Wstrict_overflow, | 6597 warning_at (location, OPT_Wstrict_overflow, |
6603 ("%Hassuming signed overflow does not occur when " | 6598 "assuming signed overflow does not occur when " |
6604 "simplifying / or %% to >> or &"), | 6599 "simplifying %</%> or %<%%%> to %<>>%> or %<&%>"); |
6605 &location); | |
6606 } | 6600 } |
6607 } | 6601 } |
6608 | 6602 |
6609 if (val && integer_onep (val)) | 6603 if (val && integer_onep (val)) |
6610 { | 6604 { |
6680 | 6674 |
6681 if (!gimple_has_location (stmt)) | 6675 if (!gimple_has_location (stmt)) |
6682 location = input_location; | 6676 location = input_location; |
6683 else | 6677 else |
6684 location = gimple_location (stmt); | 6678 location = gimple_location (stmt); |
6685 warning (OPT_Wstrict_overflow, | 6679 warning_at (location, OPT_Wstrict_overflow, |
6686 ("%Hassuming signed overflow does not occur when " | 6680 "assuming signed overflow does not occur when " |
6687 "simplifying abs (X) to X or -X"), | 6681 "simplifying %<abs (X)%> to %<X%> or %<-X%>"); |
6688 &location); | |
6689 } | 6682 } |
6690 | 6683 |
6691 gimple_assign_set_rhs1 (stmt, op); | 6684 gimple_assign_set_rhs1 (stmt, op); |
6692 if (integer_onep (val)) | 6685 if (integer_onep (val)) |
6693 gimple_assign_set_rhs_code (stmt, NEGATE_EXPR); | 6686 gimple_assign_set_rhs_code (stmt, NEGATE_EXPR); |
6749 | 6742 |
6750 /* Now refine the minimum and maximum values using any | 6743 /* Now refine the minimum and maximum values using any |
6751 value range information we have for op0. */ | 6744 value range information we have for op0. */ |
6752 if (min && max) | 6745 if (min && max) |
6753 { | 6746 { |
6754 if (compare_values (vr->min, min) == -1) | 6747 if (compare_values (vr->min, min) == 1) |
6755 min = min; | |
6756 else | |
6757 min = vr->min; | 6748 min = vr->min; |
6758 if (compare_values (vr->max, max) == 1) | 6749 if (compare_values (vr->max, max) == -1) |
6759 max = max; | |
6760 else | |
6761 max = vr->max; | 6750 max = vr->max; |
6762 | 6751 |
6763 /* If the new min/max values have converged to a single value, | 6752 /* If the new min/max values have converged to a single value, |
6764 then there is only one value which can satisfy the condition, | 6753 then there is only one value which can satisfy the condition, |
6765 return that value. */ | 6754 return that value. */ |
6785 && TREE_CODE (op0) == SSA_NAME | 6774 && TREE_CODE (op0) == SSA_NAME |
6786 && INTEGRAL_TYPE_P (TREE_TYPE (op0)) | 6775 && INTEGRAL_TYPE_P (TREE_TYPE (op0)) |
6787 && is_gimple_min_invariant (op1)) | 6776 && is_gimple_min_invariant (op1)) |
6788 { | 6777 { |
6789 value_range_t *vr = get_value_range (op0); | 6778 value_range_t *vr = get_value_range (op0); |
6790 | 6779 |
6791 /* If we have range information for OP0, then we might be | 6780 /* If we have range information for OP0, then we might be |
6792 able to simplify this conditional. */ | 6781 able to simplify this conditional. */ |
6793 if (vr->type == VR_RANGE) | 6782 if (vr->type == VR_RANGE) |
6794 { | 6783 { |
6795 tree new_tree = test_for_singularity (cond_code, op0, op1, vr); | 6784 tree new_tree = test_for_singularity (cond_code, op0, op1, vr); |
6866 edge_iterator ei; | 6855 edge_iterator ei; |
6867 size_t i = 0, j = 0, n, n2; | 6856 size_t i = 0, j = 0, n, n2; |
6868 tree vec2; | 6857 tree vec2; |
6869 switch_update su; | 6858 switch_update su; |
6870 | 6859 |
6871 if (TREE_CODE (op) != SSA_NAME) | 6860 if (TREE_CODE (op) == SSA_NAME) |
6861 { | |
6862 vr = get_value_range (op); | |
6863 | |
6864 /* We can only handle integer ranges. */ | |
6865 if (vr->type != VR_RANGE | |
6866 || symbolic_range_p (vr)) | |
6867 return false; | |
6868 | |
6869 /* Find case label for min/max of the value range. */ | |
6870 take_default = !find_case_label_range (stmt, vr->min, vr->max, &i, &j); | |
6871 } | |
6872 else if (TREE_CODE (op) == INTEGER_CST) | |
6873 { | |
6874 take_default = !find_case_label_index (stmt, 1, op, &i); | |
6875 if (take_default) | |
6876 { | |
6877 i = 1; | |
6878 j = 0; | |
6879 } | |
6880 else | |
6881 { | |
6882 j = i; | |
6883 } | |
6884 } | |
6885 else | |
6872 return false; | 6886 return false; |
6873 | 6887 |
6874 vr = get_value_range (op); | |
6875 | |
6876 /* We can only handle integer ranges. */ | |
6877 if (vr->type != VR_RANGE | |
6878 || symbolic_range_p (vr)) | |
6879 return false; | |
6880 | |
6881 /* Find case label for min/max of the value range. */ | |
6882 n = gimple_switch_num_labels (stmt); | 6888 n = gimple_switch_num_labels (stmt); |
6883 take_default = !find_case_label_range (stmt, vr->min, vr->max, &i, &j); | |
6884 | 6889 |
6885 /* Bail out if this is just all edges taken. */ | 6890 /* Bail out if this is just all edges taken. */ |
6886 if (i == 1 | 6891 if (i == 1 |
6887 && j == n - 1 | 6892 && j == n - 1 |
6888 && take_default) | 6893 && take_default) |
6930 return false; | 6935 return false; |
6931 } | 6936 } |
6932 | 6937 |
6933 /* Simplify STMT using ranges if possible. */ | 6938 /* Simplify STMT using ranges if possible. */ |
6934 | 6939 |
6935 bool | 6940 static bool |
6936 simplify_stmt_using_ranges (gimple_stmt_iterator *gsi) | 6941 simplify_stmt_using_ranges (gimple_stmt_iterator *gsi) |
6937 { | 6942 { |
6938 gimple stmt = gsi_stmt (*gsi); | 6943 gimple stmt = gsi_stmt (*gsi); |
6939 if (is_gimple_assign (stmt)) | 6944 if (is_gimple_assign (stmt)) |
6940 { | 6945 { |
6983 return simplify_switch_using_ranges (stmt); | 6988 return simplify_switch_using_ranges (stmt); |
6984 | 6989 |
6985 return false; | 6990 return false; |
6986 } | 6991 } |
6987 | 6992 |
6993 /* If the statement pointed by SI has a predicate whose value can be | |
6994 computed using the value range information computed by VRP, compute | |
6995 its value and return true. Otherwise, return false. */ | |
6996 | |
6997 static bool | |
6998 fold_predicate_in (gimple_stmt_iterator *si) | |
6999 { | |
7000 bool assignment_p = false; | |
7001 tree val; | |
7002 gimple stmt = gsi_stmt (*si); | |
7003 | |
7004 if (is_gimple_assign (stmt) | |
7005 && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_comparison) | |
7006 { | |
7007 assignment_p = true; | |
7008 val = vrp_evaluate_conditional (gimple_assign_rhs_code (stmt), | |
7009 gimple_assign_rhs1 (stmt), | |
7010 gimple_assign_rhs2 (stmt), | |
7011 stmt); | |
7012 } | |
7013 else if (gimple_code (stmt) == GIMPLE_COND) | |
7014 val = vrp_evaluate_conditional (gimple_cond_code (stmt), | |
7015 gimple_cond_lhs (stmt), | |
7016 gimple_cond_rhs (stmt), | |
7017 stmt); | |
7018 else | |
7019 return false; | |
7020 | |
7021 if (val) | |
7022 { | |
7023 if (assignment_p) | |
7024 val = fold_convert (gimple_expr_type (stmt), val); | |
7025 | |
7026 if (dump_file) | |
7027 { | |
7028 fprintf (dump_file, "Folding predicate "); | |
7029 print_gimple_expr (dump_file, stmt, 0, 0); | |
7030 fprintf (dump_file, " to "); | |
7031 print_generic_expr (dump_file, val, 0); | |
7032 fprintf (dump_file, "\n"); | |
7033 } | |
7034 | |
7035 if (is_gimple_assign (stmt)) | |
7036 gimple_assign_set_rhs_from_tree (si, val); | |
7037 else | |
7038 { | |
7039 gcc_assert (gimple_code (stmt) == GIMPLE_COND); | |
7040 if (integer_zerop (val)) | |
7041 gimple_cond_make_false (stmt); | |
7042 else if (integer_onep (val)) | |
7043 gimple_cond_make_true (stmt); | |
7044 else | |
7045 gcc_unreachable (); | |
7046 } | |
7047 | |
7048 return true; | |
7049 } | |
7050 | |
7051 return false; | |
7052 } | |
7053 | |
7054 /* Callback for substitute_and_fold folding the stmt at *SI. */ | |
7055 | |
7056 static bool | |
7057 vrp_fold_stmt (gimple_stmt_iterator *si) | |
7058 { | |
7059 if (fold_predicate_in (si)) | |
7060 return true; | |
7061 | |
7062 return simplify_stmt_using_ranges (si); | |
7063 } | |
7064 | |
6988 /* Stack of dest,src equivalency pairs that need to be restored after | 7065 /* Stack of dest,src equivalency pairs that need to be restored after |
6989 each attempt to thread a block's incoming edge to an outgoing edge. | 7066 each attempt to thread a block's incoming edge to an outgoing edge. |
6990 | 7067 |
6991 A NULL entry is used to mark the end of pairs which need to be | 7068 A NULL entry is used to mark the end of pairs which need to be |
6992 restored. */ | 7069 restored. */ |
6993 static VEC(tree,heap) *stack; | 7070 static VEC(tree,heap) *stack; |
6994 | 7071 |
7024 with edges that may be suitable for jump threading. | 7101 with edges that may be suitable for jump threading. |
7025 | 7102 |
7026 Unlike DOM, we do not iterate VRP if jump threading was successful. | 7103 Unlike DOM, we do not iterate VRP if jump threading was successful. |
7027 While iterating may expose new opportunities for VRP, it is expected | 7104 While iterating may expose new opportunities for VRP, it is expected |
7028 those opportunities would be very limited and the compile time cost | 7105 those opportunities would be very limited and the compile time cost |
7029 to expose those opportunities would be significant. | 7106 to expose those opportunities would be significant. |
7030 | 7107 |
7031 As jump threading opportunities are discovered, they are registered | 7108 As jump threading opportunities are discovered, they are registered |
7032 for later realization. */ | 7109 for later realization. */ |
7033 | 7110 |
7034 static void | 7111 static void |
7150 dump_all_value_ranges (dump_file); | 7227 dump_all_value_ranges (dump_file); |
7151 fprintf (dump_file, "\n"); | 7228 fprintf (dump_file, "\n"); |
7152 } | 7229 } |
7153 | 7230 |
7154 /* We may have ended with ranges that have exactly one value. Those | 7231 /* We may have ended with ranges that have exactly one value. Those |
7155 values can be substituted as any other copy/const propagated | 7232 values can be substituted as any other const propagated |
7156 value using substitute_and_fold. */ | 7233 value using substitute_and_fold. */ |
7157 single_val_range = XCNEWVEC (prop_value_t, num_ssa_names); | 7234 single_val_range = XCNEWVEC (prop_value_t, num_ssa_names); |
7158 | 7235 |
7159 do_value_subst_p = false; | 7236 do_value_subst_p = false; |
7160 for (i = 0; i < num_ssa_names; i++) | 7237 for (i = 0; i < num_ssa_names; i++) |
7161 if (vr_value[i] | 7238 if (vr_value[i] |
7162 && vr_value[i]->type == VR_RANGE | 7239 && vr_value[i]->type == VR_RANGE |
7163 && vr_value[i]->min == vr_value[i]->max) | 7240 && vr_value[i]->min == vr_value[i]->max |
7241 && is_gimple_min_invariant (vr_value[i]->min)) | |
7164 { | 7242 { |
7165 single_val_range[i].value = vr_value[i]->min; | 7243 single_val_range[i].value = vr_value[i]->min; |
7166 do_value_subst_p = true; | 7244 do_value_subst_p = true; |
7167 } | 7245 } |
7168 | 7246 |
7172 do single value substitution in substitute_and_fold. */ | 7250 do single value substitution in substitute_and_fold. */ |
7173 free (single_val_range); | 7251 free (single_val_range); |
7174 single_val_range = NULL; | 7252 single_val_range = NULL; |
7175 } | 7253 } |
7176 | 7254 |
7177 substitute_and_fold (single_val_range, true); | 7255 substitute_and_fold (single_val_range, vrp_fold_stmt); |
7178 | 7256 |
7179 if (warn_array_bounds) | 7257 if (warn_array_bounds) |
7180 check_all_array_refs (); | 7258 check_all_array_refs (); |
7181 | 7259 |
7182 /* We must identify jump threading opportunities before we release | 7260 /* We must identify jump threading opportunities before we release |
7218 2 p_4 = ASSERT_EXPR <p_3, p_3 != 0> | 7296 2 p_4 = ASSERT_EXPR <p_3, p_3 != 0> |
7219 3 if (p_4 == q_2) | 7297 3 if (p_4 == q_2) |
7220 4 p_5 = ASSERT_EXPR <p_4, p_4 == q_2>; | 7298 4 p_5 = ASSERT_EXPR <p_4, p_4 == q_2>; |
7221 5 endif | 7299 5 endif |
7222 6 if (q_2) | 7300 6 if (q_2) |
7223 | 7301 |
7224 In the code above, pointer p_5 has range [q_2, q_2], but from the | 7302 In the code above, pointer p_5 has range [q_2, q_2], but from the |
7225 code we can also determine that p_5 cannot be NULL and, if q_2 had | 7303 code we can also determine that p_5 cannot be NULL and, if q_2 had |
7226 a non-varying range, p_5's range should also be compatible with it. | 7304 a non-varying range, p_5's range should also be compatible with it. |
7227 | 7305 |
7228 These equivalences are created by two expressions: ASSERT_EXPR and | 7306 These equivalences are created by two expressions: ASSERT_EXPR and |
7232 | 7310 |
7233 Together with value ranges, we also propagate these equivalences | 7311 Together with value ranges, we also propagate these equivalences |
7234 between names so that we can take advantage of information from | 7312 between names so that we can take advantage of information from |
7235 multiple ranges when doing final replacement. Note that this | 7313 multiple ranges when doing final replacement. Note that this |
7236 equivalency relation is transitive but not symmetric. | 7314 equivalency relation is transitive but not symmetric. |
7237 | 7315 |
7238 In the example above, p_5 is equivalent to p_4, q_2 and p_3, but we | 7316 In the example above, p_5 is equivalent to p_4, q_2 and p_3, but we |
7239 cannot assert that q_2 is equivalent to p_5 because q_2 may be used | 7317 cannot assert that q_2 is equivalent to p_5 because q_2 may be used |
7240 in contexts where that assertion does not hold (e.g., in line 6). | 7318 in contexts where that assertion does not hold (e.g., in line 6). |
7241 | 7319 |
7242 TODO, the main difference between this pass and Patterson's is that | 7320 TODO, the main difference between this pass and Patterson's is that |
7259 | 7337 |
7260 insert_range_assertions (); | 7338 insert_range_assertions (); |
7261 | 7339 |
7262 to_remove_edges = VEC_alloc (edge, heap, 10); | 7340 to_remove_edges = VEC_alloc (edge, heap, 10); |
7263 to_update_switch_stmts = VEC_alloc (switch_update, heap, 5); | 7341 to_update_switch_stmts = VEC_alloc (switch_update, heap, 5); |
7342 threadedge_initialize_values (); | |
7264 | 7343 |
7265 vrp_initialize (); | 7344 vrp_initialize (); |
7266 ssa_propagate (vrp_visit_stmt, vrp_visit_phi_node); | 7345 ssa_propagate (vrp_visit_stmt, vrp_visit_phi_node); |
7267 vrp_finalize (); | 7346 vrp_finalize (); |
7268 | 7347 |
7304 if (VEC_length (edge, to_remove_edges) > 0) | 7383 if (VEC_length (edge, to_remove_edges) > 0) |
7305 free_dominance_info (CDI_DOMINATORS); | 7384 free_dominance_info (CDI_DOMINATORS); |
7306 | 7385 |
7307 VEC_free (edge, heap, to_remove_edges); | 7386 VEC_free (edge, heap, to_remove_edges); |
7308 VEC_free (switch_update, heap, to_update_switch_stmts); | 7387 VEC_free (switch_update, heap, to_update_switch_stmts); |
7388 threadedge_finalize_values (); | |
7309 | 7389 |
7310 scev_finalize (); | 7390 scev_finalize (); |
7311 loop_optimizer_finalize (); | 7391 loop_optimizer_finalize (); |
7312 return 0; | 7392 return 0; |
7313 } | 7393 } |
7327 execute_vrp, /* execute */ | 7407 execute_vrp, /* execute */ |
7328 NULL, /* sub */ | 7408 NULL, /* sub */ |
7329 NULL, /* next */ | 7409 NULL, /* next */ |
7330 0, /* static_pass_number */ | 7410 0, /* static_pass_number */ |
7331 TV_TREE_VRP, /* tv_id */ | 7411 TV_TREE_VRP, /* tv_id */ |
7332 PROP_ssa | PROP_alias, /* properties_required */ | 7412 PROP_ssa, /* properties_required */ |
7333 0, /* properties_provided */ | 7413 0, /* properties_provided */ |
7334 0, /* properties_destroyed */ | 7414 0, /* properties_destroyed */ |
7335 0, /* todo_flags_start */ | 7415 0, /* todo_flags_start */ |
7336 TODO_cleanup_cfg | 7416 TODO_cleanup_cfg |
7337 | TODO_ggc_collect | 7417 | TODO_ggc_collect |