Mercurial > hg > CbC > CbC_gcc
comparison gcc/fold-const.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 | 3bfb6c00c1e0 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
97 static void decode (HOST_WIDE_INT *, unsigned HOST_WIDE_INT *, HOST_WIDE_INT *); | 97 static void decode (HOST_WIDE_INT *, unsigned HOST_WIDE_INT *, HOST_WIDE_INT *); |
98 static bool negate_mathfn_p (enum built_in_function); | 98 static bool negate_mathfn_p (enum built_in_function); |
99 static bool negate_expr_p (tree); | 99 static bool negate_expr_p (tree); |
100 static tree negate_expr (tree); | 100 static tree negate_expr (tree); |
101 static tree split_tree (tree, enum tree_code, tree *, tree *, tree *, int); | 101 static tree split_tree (tree, enum tree_code, tree *, tree *, tree *, int); |
102 static tree associate_trees (tree, tree, enum tree_code, tree); | 102 static tree associate_trees (location_t, tree, tree, enum tree_code, tree); |
103 static tree const_binop (enum tree_code, tree, tree, int); | 103 static tree const_binop (enum tree_code, tree, tree, int); |
104 static enum comparison_code comparison_to_compcode (enum tree_code); | 104 static enum comparison_code comparison_to_compcode (enum tree_code); |
105 static enum tree_code compcode_to_comparison (enum comparison_code); | 105 static enum tree_code compcode_to_comparison (enum comparison_code); |
106 static tree combine_comparisons (enum tree_code, enum tree_code, | |
107 enum tree_code, tree, tree, tree); | |
108 static int operand_equal_for_comparison_p (tree, tree, tree); | 106 static int operand_equal_for_comparison_p (tree, tree, tree); |
109 static int twoval_comparison_p (tree, tree *, tree *, int *); | 107 static int twoval_comparison_p (tree, tree *, tree *, int *); |
110 static tree eval_subst (tree, tree, tree, tree, tree); | 108 static tree eval_subst (location_t, tree, tree, tree, tree, tree); |
111 static tree pedantic_omit_one_operand (tree, tree, tree); | 109 static tree pedantic_omit_one_operand_loc (location_t, tree, tree, tree); |
112 static tree distribute_bit_expr (enum tree_code, tree, tree, tree); | 110 static tree distribute_bit_expr (location_t, enum tree_code, tree, tree, tree); |
113 static tree make_bit_field_ref (tree, tree, HOST_WIDE_INT, HOST_WIDE_INT, int); | 111 static tree make_bit_field_ref (location_t, tree, tree, |
114 static tree optimize_bit_field_compare (enum tree_code, tree, tree, tree); | 112 HOST_WIDE_INT, HOST_WIDE_INT, int); |
115 static tree decode_field_reference (tree, HOST_WIDE_INT *, HOST_WIDE_INT *, | 113 static tree optimize_bit_field_compare (location_t, enum tree_code, |
114 tree, tree, tree); | |
115 static tree decode_field_reference (location_t, tree, HOST_WIDE_INT *, | |
116 HOST_WIDE_INT *, | |
116 enum machine_mode *, int *, int *, | 117 enum machine_mode *, int *, int *, |
117 tree *, tree *); | 118 tree *, tree *); |
118 static int all_ones_mask_p (const_tree, int); | 119 static int all_ones_mask_p (const_tree, int); |
119 static tree sign_bit_p (tree, const_tree); | 120 static tree sign_bit_p (tree, const_tree); |
120 static int simple_operand_p (const_tree); | 121 static int simple_operand_p (const_tree); |
121 static tree range_binop (enum tree_code, tree, tree, int, tree, int); | 122 static tree range_binop (enum tree_code, tree, tree, int, tree, int); |
122 static tree range_predecessor (tree); | 123 static tree range_predecessor (tree); |
123 static tree range_successor (tree); | 124 static tree range_successor (tree); |
124 static tree make_range (tree, int *, tree *, tree *, bool *); | 125 extern tree make_range (tree, int *, tree *, tree *, bool *); |
125 static tree build_range_check (tree, tree, int, tree, tree); | 126 extern bool merge_ranges (int *, tree *, tree *, int, tree, tree, int, |
126 static int merge_ranges (int *, tree *, tree *, int, tree, tree, int, tree, | 127 tree, tree); |
127 tree); | 128 static tree fold_range_test (location_t, enum tree_code, tree, tree, tree); |
128 static tree fold_range_test (enum tree_code, tree, tree, tree); | 129 static tree fold_cond_expr_with_comparison (location_t, tree, tree, tree, tree); |
129 static tree fold_cond_expr_with_comparison (tree, tree, tree, tree); | |
130 static tree unextend (tree, int, int, tree); | 130 static tree unextend (tree, int, int, tree); |
131 static tree fold_truthop (enum tree_code, tree, tree, tree); | 131 static tree fold_truthop (location_t, enum tree_code, tree, tree, tree); |
132 static tree optimize_minmax_comparison (enum tree_code, tree, tree, tree); | 132 static tree optimize_minmax_comparison (location_t, enum tree_code, |
133 tree, tree, tree); | |
133 static tree extract_muldiv (tree, tree, enum tree_code, tree, bool *); | 134 static tree extract_muldiv (tree, tree, enum tree_code, tree, bool *); |
134 static tree extract_muldiv_1 (tree, tree, enum tree_code, tree, bool *); | 135 static tree extract_muldiv_1 (tree, tree, enum tree_code, tree, bool *); |
135 static tree fold_binary_op_with_conditional_arg (enum tree_code, tree, | 136 static tree fold_binary_op_with_conditional_arg (location_t, |
137 enum tree_code, tree, | |
136 tree, tree, | 138 tree, tree, |
137 tree, tree, int); | 139 tree, tree, int); |
138 static tree fold_mathfn_compare (enum built_in_function, enum tree_code, | 140 static tree fold_mathfn_compare (location_t, |
141 enum built_in_function, enum tree_code, | |
139 tree, tree, tree); | 142 tree, tree, tree); |
140 static tree fold_inf_compare (enum tree_code, tree, tree, tree); | 143 static tree fold_inf_compare (location_t, enum tree_code, tree, tree, tree); |
141 static tree fold_div_compare (enum tree_code, tree, tree, tree); | 144 static tree fold_div_compare (location_t, enum tree_code, tree, tree, tree); |
142 static bool reorder_operands_p (const_tree, const_tree); | 145 static bool reorder_operands_p (const_tree, const_tree); |
143 static tree fold_negate_const (tree, tree); | 146 static tree fold_negate_const (tree, tree); |
144 static tree fold_not_const (tree, tree); | 147 static tree fold_not_const (tree, tree); |
145 static tree fold_relational_const (enum tree_code, tree, tree, tree); | 148 static tree fold_relational_const (enum tree_code, tree, tree, tree); |
149 static tree fold_convert_const (enum tree_code, tree, tree); | |
146 | 150 |
147 | 151 |
148 /* We know that A1 + B1 = SUM1, using 2's complement arithmetic and ignoring | 152 /* We know that A1 + B1 = SUM1, using 2's complement arithmetic and ignoring |
149 overflow. Suppose A, B and SUM have the same respective signs as A1, B1, | 153 overflow. Suppose A, B and SUM have the same respective signs as A1, B1, |
150 and SUM1. Then this yields nonzero if overflow occurred during the | 154 and SUM1. Then this yields nonzero if overflow occurred during the |
200 fit_double_type (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1, | 204 fit_double_type (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1, |
201 unsigned HOST_WIDE_INT *lv, HOST_WIDE_INT *hv, const_tree type) | 205 unsigned HOST_WIDE_INT *lv, HOST_WIDE_INT *hv, const_tree type) |
202 { | 206 { |
203 unsigned HOST_WIDE_INT low0 = l1; | 207 unsigned HOST_WIDE_INT low0 = l1; |
204 HOST_WIDE_INT high0 = h1; | 208 HOST_WIDE_INT high0 = h1; |
205 unsigned int prec; | 209 unsigned int prec = TYPE_PRECISION (type); |
206 int sign_extended_type; | 210 int sign_extended_type; |
207 | |
208 if (POINTER_TYPE_P (type) | |
209 || TREE_CODE (type) == OFFSET_TYPE) | |
210 prec = POINTER_SIZE; | |
211 else | |
212 prec = TYPE_PRECISION (type); | |
213 | 211 |
214 /* Size types *are* sign extended. */ | 212 /* Size types *are* sign extended. */ |
215 sign_extended_type = (!TYPE_UNSIGNED (type) | 213 sign_extended_type = (!TYPE_UNSIGNED (type) |
216 || (TREE_CODE (type) == INTEGER_TYPE | 214 || (TREE_CODE (type) == INTEGER_TYPE |
217 && TYPE_IS_SIZETYPE (type))); | 215 && TYPE_IS_SIZETYPE (type))); |
326 { | 324 { |
327 unsigned HOST_WIDE_INT l; | 325 unsigned HOST_WIDE_INT l; |
328 HOST_WIDE_INT h; | 326 HOST_WIDE_INT h; |
329 | 327 |
330 l = l1 + l2; | 328 l = l1 + l2; |
331 h = (HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) h1 | 329 h = h1 + h2 + (l < l1); |
332 + (unsigned HOST_WIDE_INT) h2 | |
333 + (l < l1)); | |
334 | 330 |
335 *lv = l; | 331 *lv = l; |
336 *hv = h; | 332 *hv = h; |
337 | 333 |
338 if (unsigned_p) | 334 if (unsigned_p) |
339 return ((unsigned HOST_WIDE_INT) h < (unsigned HOST_WIDE_INT) h1 | 335 return (unsigned HOST_WIDE_INT) h < (unsigned HOST_WIDE_INT) h1; |
340 || (h == h1 | |
341 && l < l1)); | |
342 else | 336 else |
343 return OVERFLOW_SUM_SIGN (h1, h2, h); | 337 return OVERFLOW_SUM_SIGN (h1, h2, h); |
344 } | 338 } |
345 | 339 |
346 /* Negate a doubleword integer with doubleword result. | 340 /* Negate a doubleword integer with doubleword result. |
878 | 872 |
879 /* If ARG2 divides ARG1 with zero remainder, carries out the division | 873 /* If ARG2 divides ARG1 with zero remainder, carries out the division |
880 of type CODE and returns the quotient. | 874 of type CODE and returns the quotient. |
881 Otherwise returns NULL_TREE. */ | 875 Otherwise returns NULL_TREE. */ |
882 | 876 |
883 static tree | 877 tree |
884 div_if_zero_remainder (enum tree_code code, const_tree arg1, const_tree arg2) | 878 div_if_zero_remainder (enum tree_code code, const_tree arg1, const_tree arg2) |
885 { | 879 { |
886 unsigned HOST_WIDE_INT int1l, int2l; | 880 unsigned HOST_WIDE_INT int1l, int2l; |
887 HOST_WIDE_INT int1h, int2h; | 881 HOST_WIDE_INT int1h, int2h; |
888 unsigned HOST_WIDE_INT quol, reml; | 882 unsigned HOST_WIDE_INT quol, reml; |
889 HOST_WIDE_INT quoh, remh; | 883 HOST_WIDE_INT quoh, remh; |
890 tree type = TREE_TYPE (arg1); | 884 int uns; |
891 int uns = TYPE_UNSIGNED (type); | 885 |
886 /* The sign of the division is according to operand two, that | |
887 does the correct thing for POINTER_PLUS_EXPR where we want | |
888 a signed division. */ | |
889 uns = TYPE_UNSIGNED (TREE_TYPE (arg2)); | |
890 if (TREE_CODE (TREE_TYPE (arg2)) == INTEGER_TYPE | |
891 && TYPE_IS_SIZETYPE (TREE_TYPE (arg2))) | |
892 uns = false; | |
892 | 893 |
893 int1l = TREE_INT_CST_LOW (arg1); | 894 int1l = TREE_INT_CST_LOW (arg1); |
894 int1h = TREE_INT_CST_HIGH (arg1); | 895 int1h = TREE_INT_CST_HIGH (arg1); |
895 /* &obj[0] + -128 really should be compiled as &obj[-8] rather than | |
896 &obj[some_exotic_number]. */ | |
897 if (POINTER_TYPE_P (type)) | |
898 { | |
899 uns = false; | |
900 type = signed_type_for (type); | |
901 fit_double_type (int1l, int1h, &int1l, &int1h, | |
902 type); | |
903 } | |
904 else | |
905 fit_double_type (int1l, int1h, &int1l, &int1h, type); | |
906 int2l = TREE_INT_CST_LOW (arg2); | 896 int2l = TREE_INT_CST_LOW (arg2); |
907 int2h = TREE_INT_CST_HIGH (arg2); | 897 int2h = TREE_INT_CST_HIGH (arg2); |
908 | 898 |
909 div_and_round_double (code, uns, int1l, int1h, int2l, int2h, | 899 div_and_round_double (code, uns, int1l, int1h, int2l, int2h, |
910 &quol, &quoh, &reml, &remh); | 900 &quol, &quoh, &reml, &remh); |
911 if (remh != 0 || reml != 0) | 901 if (remh != 0 || reml != 0) |
912 return NULL_TREE; | 902 return NULL_TREE; |
913 | 903 |
914 return build_int_cst_wide (type, quol, quoh); | 904 return build_int_cst_wide (TREE_TYPE (arg1), quol, quoh); |
915 } | 905 } |
916 | 906 |
917 /* This is nonzero if we should defer warnings about undefined | 907 /* This is nonzero if we should defer warnings about undefined |
918 overflow. This facility exists because these warnings are a | 908 overflow. This facility exists because these warnings are a |
919 special case. The code to estimate loop iterations does not want | 909 special case. The code to estimate loop iterations does not want |
966 if (fold_deferring_overflow_warnings > 0) | 956 if (fold_deferring_overflow_warnings > 0) |
967 { | 957 { |
968 if (fold_deferred_overflow_warning != NULL | 958 if (fold_deferred_overflow_warning != NULL |
969 && code != 0 | 959 && code != 0 |
970 && code < (int) fold_deferred_overflow_code) | 960 && code < (int) fold_deferred_overflow_code) |
971 fold_deferred_overflow_code = code; | 961 fold_deferred_overflow_code = (enum warn_strict_overflow_code) code; |
972 return; | 962 return; |
973 } | 963 } |
974 | 964 |
975 warnmsg = fold_deferred_overflow_warning; | 965 warnmsg = fold_deferred_overflow_warning; |
976 fold_deferred_overflow_warning = NULL; | 966 fold_deferred_overflow_warning = NULL; |
991 | 981 |
992 if (stmt == NULL) | 982 if (stmt == NULL) |
993 locus = input_location; | 983 locus = input_location; |
994 else | 984 else |
995 locus = gimple_location (stmt); | 985 locus = gimple_location (stmt); |
996 warning (OPT_Wstrict_overflow, "%H%s", &locus, warnmsg); | 986 warning_at (locus, OPT_Wstrict_overflow, "%s", warnmsg); |
997 } | 987 } |
998 | 988 |
999 /* Stop deferring overflow warnings, ignoring any deferred | 989 /* Stop deferring overflow warnings, ignoring any deferred |
1000 warnings. */ | 990 warnings. */ |
1001 | 991 |
1068 CASE_FLT_FN (BUILT_IN_LLRINT): | 1058 CASE_FLT_FN (BUILT_IN_LLRINT): |
1069 CASE_FLT_FN (BUILT_IN_LRINT): | 1059 CASE_FLT_FN (BUILT_IN_LRINT): |
1070 CASE_FLT_FN (BUILT_IN_NEARBYINT): | 1060 CASE_FLT_FN (BUILT_IN_NEARBYINT): |
1071 CASE_FLT_FN (BUILT_IN_RINT): | 1061 CASE_FLT_FN (BUILT_IN_RINT): |
1072 return !flag_rounding_math; | 1062 return !flag_rounding_math; |
1073 | 1063 |
1074 default: | 1064 default: |
1075 break; | 1065 break; |
1076 } | 1066 } |
1077 return false; | 1067 return false; |
1078 } | 1068 } |
1235 simplification is possible. | 1225 simplification is possible. |
1236 If negate_expr_p would return true for T, NULL_TREE will never be | 1226 If negate_expr_p would return true for T, NULL_TREE will never be |
1237 returned. */ | 1227 returned. */ |
1238 | 1228 |
1239 static tree | 1229 static tree |
1240 fold_negate_expr (tree t) | 1230 fold_negate_expr (location_t loc, tree t) |
1241 { | 1231 { |
1242 tree type = TREE_TYPE (t); | 1232 tree type = TREE_TYPE (t); |
1243 tree tem; | 1233 tree tem; |
1244 | 1234 |
1245 switch (TREE_CODE (t)) | 1235 switch (TREE_CODE (t)) |
1246 { | 1236 { |
1247 /* Convert - (~A) to A + 1. */ | 1237 /* Convert - (~A) to A + 1. */ |
1248 case BIT_NOT_EXPR: | 1238 case BIT_NOT_EXPR: |
1249 if (INTEGRAL_TYPE_P (type)) | 1239 if (INTEGRAL_TYPE_P (type)) |
1250 return fold_build2 (PLUS_EXPR, type, TREE_OPERAND (t, 0), | 1240 return fold_build2_loc (loc, PLUS_EXPR, type, TREE_OPERAND (t, 0), |
1251 build_int_cst (type, 1)); | 1241 build_int_cst (type, 1)); |
1252 break; | 1242 break; |
1253 | 1243 |
1254 case INTEGER_CST: | 1244 case INTEGER_CST: |
1255 tem = fold_negate_const (t, type); | 1245 tem = fold_negate_const (t, type); |
1256 if (TREE_OVERFLOW (tem) == TREE_OVERFLOW (t) | 1246 if (TREE_OVERFLOW (tem) == TREE_OVERFLOW (t) |
1257 || !TYPE_OVERFLOW_TRAPS (type)) | 1247 || !TYPE_OVERFLOW_TRAPS (type)) |
1258 return tem; | 1248 return tem; |
1282 } | 1272 } |
1283 break; | 1273 break; |
1284 | 1274 |
1285 case COMPLEX_EXPR: | 1275 case COMPLEX_EXPR: |
1286 if (negate_expr_p (t)) | 1276 if (negate_expr_p (t)) |
1287 return fold_build2 (COMPLEX_EXPR, type, | 1277 return fold_build2_loc (loc, COMPLEX_EXPR, type, |
1288 fold_negate_expr (TREE_OPERAND (t, 0)), | 1278 fold_negate_expr (loc, TREE_OPERAND (t, 0)), |
1289 fold_negate_expr (TREE_OPERAND (t, 1))); | 1279 fold_negate_expr (loc, TREE_OPERAND (t, 1))); |
1290 break; | 1280 break; |
1291 | 1281 |
1292 case CONJ_EXPR: | 1282 case CONJ_EXPR: |
1293 if (negate_expr_p (t)) | 1283 if (negate_expr_p (t)) |
1294 return fold_build1 (CONJ_EXPR, type, | 1284 return fold_build1_loc (loc, CONJ_EXPR, type, |
1295 fold_negate_expr (TREE_OPERAND (t, 0))); | 1285 fold_negate_expr (loc, TREE_OPERAND (t, 0))); |
1296 break; | 1286 break; |
1297 | 1287 |
1298 case NEGATE_EXPR: | 1288 case NEGATE_EXPR: |
1299 return TREE_OPERAND (t, 0); | 1289 return TREE_OPERAND (t, 0); |
1300 | 1290 |
1306 if (negate_expr_p (TREE_OPERAND (t, 1)) | 1296 if (negate_expr_p (TREE_OPERAND (t, 1)) |
1307 && reorder_operands_p (TREE_OPERAND (t, 0), | 1297 && reorder_operands_p (TREE_OPERAND (t, 0), |
1308 TREE_OPERAND (t, 1))) | 1298 TREE_OPERAND (t, 1))) |
1309 { | 1299 { |
1310 tem = negate_expr (TREE_OPERAND (t, 1)); | 1300 tem = negate_expr (TREE_OPERAND (t, 1)); |
1311 return fold_build2 (MINUS_EXPR, type, | 1301 return fold_build2_loc (loc, MINUS_EXPR, type, |
1312 tem, TREE_OPERAND (t, 0)); | 1302 tem, TREE_OPERAND (t, 0)); |
1313 } | 1303 } |
1314 | 1304 |
1315 /* -(A + B) -> (-A) - B. */ | 1305 /* -(A + B) -> (-A) - B. */ |
1316 if (negate_expr_p (TREE_OPERAND (t, 0))) | 1306 if (negate_expr_p (TREE_OPERAND (t, 0))) |
1317 { | 1307 { |
1318 tem = negate_expr (TREE_OPERAND (t, 0)); | 1308 tem = negate_expr (TREE_OPERAND (t, 0)); |
1319 return fold_build2 (MINUS_EXPR, type, | 1309 return fold_build2_loc (loc, MINUS_EXPR, type, |
1320 tem, TREE_OPERAND (t, 1)); | 1310 tem, TREE_OPERAND (t, 1)); |
1321 } | 1311 } |
1322 } | 1312 } |
1323 break; | 1313 break; |
1324 | 1314 |
1325 case MINUS_EXPR: | 1315 case MINUS_EXPR: |
1326 /* - (A - B) -> B - A */ | 1316 /* - (A - B) -> B - A */ |
1327 if (!HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type)) | 1317 if (!HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type)) |
1328 && !HONOR_SIGNED_ZEROS (TYPE_MODE (type)) | 1318 && !HONOR_SIGNED_ZEROS (TYPE_MODE (type)) |
1329 && reorder_operands_p (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1))) | 1319 && reorder_operands_p (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1))) |
1330 return fold_build2 (MINUS_EXPR, type, | 1320 return fold_build2_loc (loc, MINUS_EXPR, type, |
1331 TREE_OPERAND (t, 1), TREE_OPERAND (t, 0)); | 1321 TREE_OPERAND (t, 1), TREE_OPERAND (t, 0)); |
1332 break; | 1322 break; |
1333 | 1323 |
1334 case MULT_EXPR: | 1324 case MULT_EXPR: |
1335 if (TYPE_UNSIGNED (type)) | 1325 if (TYPE_UNSIGNED (type)) |
1340 case RDIV_EXPR: | 1330 case RDIV_EXPR: |
1341 if (! HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type))) | 1331 if (! HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type))) |
1342 { | 1332 { |
1343 tem = TREE_OPERAND (t, 1); | 1333 tem = TREE_OPERAND (t, 1); |
1344 if (negate_expr_p (tem)) | 1334 if (negate_expr_p (tem)) |
1345 return fold_build2 (TREE_CODE (t), type, | 1335 return fold_build2_loc (loc, TREE_CODE (t), type, |
1346 TREE_OPERAND (t, 0), negate_expr (tem)); | 1336 TREE_OPERAND (t, 0), negate_expr (tem)); |
1347 tem = TREE_OPERAND (t, 0); | 1337 tem = TREE_OPERAND (t, 0); |
1348 if (negate_expr_p (tem)) | 1338 if (negate_expr_p (tem)) |
1349 return fold_build2 (TREE_CODE (t), type, | 1339 return fold_build2_loc (loc, TREE_CODE (t), type, |
1350 negate_expr (tem), TREE_OPERAND (t, 1)); | 1340 negate_expr (tem), TREE_OPERAND (t, 1)); |
1351 } | 1341 } |
1352 break; | 1342 break; |
1353 | 1343 |
1354 case TRUNC_DIV_EXPR: | 1344 case TRUNC_DIV_EXPR: |
1370 { | 1360 { |
1371 if (INTEGRAL_TYPE_P (type) | 1361 if (INTEGRAL_TYPE_P (type) |
1372 && (TREE_CODE (tem) != INTEGER_CST | 1362 && (TREE_CODE (tem) != INTEGER_CST |
1373 || integer_onep (tem))) | 1363 || integer_onep (tem))) |
1374 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MISC); | 1364 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MISC); |
1375 return fold_build2 (TREE_CODE (t), type, | 1365 return fold_build2_loc (loc, TREE_CODE (t), type, |
1376 TREE_OPERAND (t, 0), negate_expr (tem)); | 1366 TREE_OPERAND (t, 0), negate_expr (tem)); |
1377 } | 1367 } |
1378 tem = TREE_OPERAND (t, 0); | 1368 tem = TREE_OPERAND (t, 0); |
1379 if (negate_expr_p (tem)) | 1369 if (negate_expr_p (tem)) |
1380 { | 1370 { |
1381 if (INTEGRAL_TYPE_P (type) | 1371 if (INTEGRAL_TYPE_P (type) |
1382 && (TREE_CODE (tem) != INTEGER_CST | 1372 && (TREE_CODE (tem) != INTEGER_CST |
1383 || tree_int_cst_equal (tem, TYPE_MIN_VALUE (type)))) | 1373 || tree_int_cst_equal (tem, TYPE_MIN_VALUE (type)))) |
1384 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MISC); | 1374 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MISC); |
1385 return fold_build2 (TREE_CODE (t), type, | 1375 return fold_build2_loc (loc, TREE_CODE (t), type, |
1386 negate_expr (tem), TREE_OPERAND (t, 1)); | 1376 negate_expr (tem), TREE_OPERAND (t, 1)); |
1387 } | 1377 } |
1388 } | 1378 } |
1389 break; | 1379 break; |
1390 | 1380 |
1392 /* Convert -((double)float) into (double)(-float). */ | 1382 /* Convert -((double)float) into (double)(-float). */ |
1393 if (TREE_CODE (type) == REAL_TYPE) | 1383 if (TREE_CODE (type) == REAL_TYPE) |
1394 { | 1384 { |
1395 tem = strip_float_extensions (t); | 1385 tem = strip_float_extensions (t); |
1396 if (tem != t && negate_expr_p (tem)) | 1386 if (tem != t && negate_expr_p (tem)) |
1397 return fold_convert (type, negate_expr (tem)); | 1387 return fold_convert_loc (loc, type, negate_expr (tem)); |
1398 } | 1388 } |
1399 break; | 1389 break; |
1400 | 1390 |
1401 case CALL_EXPR: | 1391 case CALL_EXPR: |
1402 /* Negate -f(x) as f(-x). */ | 1392 /* Negate -f(x) as f(-x). */ |
1405 { | 1395 { |
1406 tree fndecl, arg; | 1396 tree fndecl, arg; |
1407 | 1397 |
1408 fndecl = get_callee_fndecl (t); | 1398 fndecl = get_callee_fndecl (t); |
1409 arg = negate_expr (CALL_EXPR_ARG (t, 0)); | 1399 arg = negate_expr (CALL_EXPR_ARG (t, 0)); |
1410 return build_call_expr (fndecl, 1, arg); | 1400 return build_call_expr_loc (loc, fndecl, 1, arg); |
1411 } | 1401 } |
1412 break; | 1402 break; |
1413 | 1403 |
1414 case RSHIFT_EXPR: | 1404 case RSHIFT_EXPR: |
1415 /* Optimize -((int)x >> 31) into (unsigned)x >> 31. */ | 1405 /* Optimize -((int)x >> 31) into (unsigned)x >> 31. */ |
1421 == TREE_INT_CST_LOW (op1)) | 1411 == TREE_INT_CST_LOW (op1)) |
1422 { | 1412 { |
1423 tree ntype = TYPE_UNSIGNED (type) | 1413 tree ntype = TYPE_UNSIGNED (type) |
1424 ? signed_type_for (type) | 1414 ? signed_type_for (type) |
1425 : unsigned_type_for (type); | 1415 : unsigned_type_for (type); |
1426 tree temp = fold_convert (ntype, TREE_OPERAND (t, 0)); | 1416 tree temp = fold_convert_loc (loc, ntype, TREE_OPERAND (t, 0)); |
1427 temp = fold_build2 (RSHIFT_EXPR, ntype, temp, op1); | 1417 temp = fold_build2_loc (loc, RSHIFT_EXPR, ntype, temp, op1); |
1428 return fold_convert (type, temp); | 1418 return fold_convert_loc (loc, type, temp); |
1429 } | 1419 } |
1430 } | 1420 } |
1431 break; | 1421 break; |
1432 | 1422 |
1433 default: | 1423 default: |
1443 | 1433 |
1444 static tree | 1434 static tree |
1445 negate_expr (tree t) | 1435 negate_expr (tree t) |
1446 { | 1436 { |
1447 tree type, tem; | 1437 tree type, tem; |
1438 location_t loc; | |
1448 | 1439 |
1449 if (t == NULL_TREE) | 1440 if (t == NULL_TREE) |
1450 return NULL_TREE; | 1441 return NULL_TREE; |
1451 | 1442 |
1443 loc = EXPR_LOCATION (t); | |
1452 type = TREE_TYPE (t); | 1444 type = TREE_TYPE (t); |
1453 STRIP_SIGN_NOPS (t); | 1445 STRIP_SIGN_NOPS (t); |
1454 | 1446 |
1455 tem = fold_negate_expr (t); | 1447 tem = fold_negate_expr (loc, t); |
1456 if (!tem) | 1448 if (!tem) |
1457 tem = build1 (NEGATE_EXPR, TREE_TYPE (t), t); | 1449 { |
1458 return fold_convert (type, tem); | 1450 tem = build1 (NEGATE_EXPR, TREE_TYPE (t), t); |
1451 SET_EXPR_LOCATION (tem, loc); | |
1452 } | |
1453 return fold_convert_loc (loc, type, tem); | |
1459 } | 1454 } |
1460 | 1455 |
1461 /* Split a tree IN into a constant, literal and variable parts that could be | 1456 /* Split a tree IN into a constant, literal and variable parts that could be |
1462 combined with CODE to make IN. "constant" means an expression with | 1457 combined with CODE to make IN. "constant" means an expression with |
1463 TREE_CONSTANT but that isn't an actual constant. CODE must be a | 1458 TREE_CONSTANT but that isn't an actual constant. CODE must be a |
1555 } | 1550 } |
1556 | 1551 |
1557 return var; | 1552 return var; |
1558 } | 1553 } |
1559 | 1554 |
1560 /* Re-associate trees split by the above function. T1 and T2 are either | 1555 /* Re-associate trees split by the above function. T1 and T2 are |
1561 expressions to associate or null. Return the new expression, if any. If | 1556 either expressions to associate or null. Return the new |
1557 expression, if any. LOC is the location of the new expression. If | |
1562 we build an operation, do it in TYPE and with CODE. */ | 1558 we build an operation, do it in TYPE and with CODE. */ |
1563 | 1559 |
1564 static tree | 1560 static tree |
1565 associate_trees (tree t1, tree t2, enum tree_code code, tree type) | 1561 associate_trees (location_t loc, tree t1, tree t2, enum tree_code code, tree type) |
1566 { | 1562 { |
1563 tree tem; | |
1564 | |
1567 if (t1 == 0) | 1565 if (t1 == 0) |
1568 return t2; | 1566 return t2; |
1569 else if (t2 == 0) | 1567 else if (t2 == 0) |
1570 return t1; | 1568 return t1; |
1571 | 1569 |
1576 || TREE_CODE (t1) == MINUS_EXPR || TREE_CODE (t2) == MINUS_EXPR) | 1574 || TREE_CODE (t1) == MINUS_EXPR || TREE_CODE (t2) == MINUS_EXPR) |
1577 { | 1575 { |
1578 if (code == PLUS_EXPR) | 1576 if (code == PLUS_EXPR) |
1579 { | 1577 { |
1580 if (TREE_CODE (t1) == NEGATE_EXPR) | 1578 if (TREE_CODE (t1) == NEGATE_EXPR) |
1581 return build2 (MINUS_EXPR, type, fold_convert (type, t2), | 1579 tem = build2 (MINUS_EXPR, type, fold_convert_loc (loc, type, t2), |
1582 fold_convert (type, TREE_OPERAND (t1, 0))); | 1580 fold_convert_loc (loc, type, TREE_OPERAND (t1, 0))); |
1583 else if (TREE_CODE (t2) == NEGATE_EXPR) | 1581 else if (TREE_CODE (t2) == NEGATE_EXPR) |
1584 return build2 (MINUS_EXPR, type, fold_convert (type, t1), | 1582 tem = build2 (MINUS_EXPR, type, fold_convert_loc (loc, type, t1), |
1585 fold_convert (type, TREE_OPERAND (t2, 0))); | 1583 fold_convert_loc (loc, type, TREE_OPERAND (t2, 0))); |
1586 else if (integer_zerop (t2)) | 1584 else if (integer_zerop (t2)) |
1587 return fold_convert (type, t1); | 1585 return fold_convert_loc (loc, type, t1); |
1588 } | 1586 } |
1589 else if (code == MINUS_EXPR) | 1587 else if (code == MINUS_EXPR) |
1590 { | 1588 { |
1591 if (integer_zerop (t2)) | 1589 if (integer_zerop (t2)) |
1592 return fold_convert (type, t1); | 1590 return fold_convert_loc (loc, type, t1); |
1593 } | 1591 } |
1594 | 1592 |
1595 return build2 (code, type, fold_convert (type, t1), | 1593 tem = build2 (code, type, fold_convert_loc (loc, type, t1), |
1596 fold_convert (type, t2)); | 1594 fold_convert_loc (loc, type, t2)); |
1597 } | 1595 goto associate_trees_exit; |
1598 | 1596 } |
1599 return fold_build2 (code, type, fold_convert (type, t1), | 1597 |
1600 fold_convert (type, t2)); | 1598 return fold_build2_loc (loc, code, type, fold_convert_loc (loc, type, t1), |
1599 fold_convert_loc (loc, type, t2)); | |
1600 associate_trees_exit: | |
1601 protected_set_expr_location (tem, loc); | |
1602 return tem; | |
1601 } | 1603 } |
1602 | 1604 |
1603 /* Check whether TYPE1 and TYPE2 are equivalent integer types, suitable | 1605 /* Check whether TYPE1 and TYPE2 are equivalent integer types, suitable |
1604 for use in int_const_binop, size_binop and size_diffop. */ | 1606 for use in int_const_binop, size_binop and size_diffop. */ |
1605 | 1607 |
1936 sat_p = TYPE_SATURATING (type); | 1938 sat_p = TYPE_SATURATING (type); |
1937 overflow_p = fixed_arithmetic (&result, code, &f1, &f2, sat_p); | 1939 overflow_p = fixed_arithmetic (&result, code, &f1, &f2, sat_p); |
1938 t = build_fixed (type, result); | 1940 t = build_fixed (type, result); |
1939 /* Propagate overflow flags. */ | 1941 /* Propagate overflow flags. */ |
1940 if (overflow_p | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2)) | 1942 if (overflow_p | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2)) |
1941 { | 1943 TREE_OVERFLOW (t) = 1; |
1942 TREE_OVERFLOW (t) = 1; | |
1943 TREE_CONSTANT_OVERFLOW (t) = 1; | |
1944 } | |
1945 else if (TREE_CONSTANT_OVERFLOW (arg1) | TREE_CONSTANT_OVERFLOW (arg2)) | |
1946 TREE_CONSTANT_OVERFLOW (t) = 1; | |
1947 return t; | 1944 return t; |
1948 } | 1945 } |
1949 | 1946 |
1950 if (TREE_CODE (arg1) == COMPLEX_CST) | 1947 if (TREE_CODE (arg1) == COMPLEX_CST) |
1951 { | 1948 { |
1963 real = const_binop (code, r1, r2, notrunc); | 1960 real = const_binop (code, r1, r2, notrunc); |
1964 imag = const_binop (code, i1, i2, notrunc); | 1961 imag = const_binop (code, i1, i2, notrunc); |
1965 break; | 1962 break; |
1966 | 1963 |
1967 case MULT_EXPR: | 1964 case MULT_EXPR: |
1965 if (COMPLEX_FLOAT_TYPE_P (type)) | |
1966 return do_mpc_arg2 (arg1, arg2, type, | |
1967 /* do_nonfinite= */ folding_initializer, | |
1968 mpc_mul); | |
1969 | |
1968 real = const_binop (MINUS_EXPR, | 1970 real = const_binop (MINUS_EXPR, |
1969 const_binop (MULT_EXPR, r1, r2, notrunc), | 1971 const_binop (MULT_EXPR, r1, r2, notrunc), |
1970 const_binop (MULT_EXPR, i1, i2, notrunc), | 1972 const_binop (MULT_EXPR, i1, i2, notrunc), |
1971 notrunc); | 1973 notrunc); |
1972 imag = const_binop (PLUS_EXPR, | 1974 imag = const_binop (PLUS_EXPR, |
1974 const_binop (MULT_EXPR, i1, r2, notrunc), | 1976 const_binop (MULT_EXPR, i1, r2, notrunc), |
1975 notrunc); | 1977 notrunc); |
1976 break; | 1978 break; |
1977 | 1979 |
1978 case RDIV_EXPR: | 1980 case RDIV_EXPR: |
1981 if (COMPLEX_FLOAT_TYPE_P (type)) | |
1982 return do_mpc_arg2 (arg1, arg2, type, | |
1983 /* do_nonfinite= */ folding_initializer, | |
1984 mpc_div); | |
1985 /* Fallthru ... */ | |
1986 case TRUNC_DIV_EXPR: | |
1987 case CEIL_DIV_EXPR: | |
1988 case FLOOR_DIV_EXPR: | |
1989 case ROUND_DIV_EXPR: | |
1990 if (flag_complex_method == 0) | |
1979 { | 1991 { |
1992 /* Keep this algorithm in sync with | |
1993 tree-complex.c:expand_complex_div_straight(). | |
1994 | |
1995 Expand complex division to scalars, straightforward algorithm. | |
1996 a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t) | |
1997 t = br*br + bi*bi | |
1998 */ | |
1980 tree magsquared | 1999 tree magsquared |
1981 = const_binop (PLUS_EXPR, | 2000 = const_binop (PLUS_EXPR, |
1982 const_binop (MULT_EXPR, r2, r2, notrunc), | 2001 const_binop (MULT_EXPR, r2, r2, notrunc), |
1983 const_binop (MULT_EXPR, i2, i2, notrunc), | 2002 const_binop (MULT_EXPR, i2, i2, notrunc), |
1984 notrunc); | 2003 notrunc); |
1991 = const_binop (MINUS_EXPR, | 2010 = const_binop (MINUS_EXPR, |
1992 const_binop (MULT_EXPR, i1, r2, notrunc), | 2011 const_binop (MULT_EXPR, i1, r2, notrunc), |
1993 const_binop (MULT_EXPR, r1, i2, notrunc), | 2012 const_binop (MULT_EXPR, r1, i2, notrunc), |
1994 notrunc); | 2013 notrunc); |
1995 | 2014 |
1996 if (INTEGRAL_TYPE_P (TREE_TYPE (r1))) | |
1997 code = TRUNC_DIV_EXPR; | |
1998 | |
1999 real = const_binop (code, t1, magsquared, notrunc); | 2015 real = const_binop (code, t1, magsquared, notrunc); |
2000 imag = const_binop (code, t2, magsquared, notrunc); | 2016 imag = const_binop (code, t2, magsquared, notrunc); |
2001 } | 2017 } |
2018 else | |
2019 { | |
2020 /* Keep this algorithm in sync with | |
2021 tree-complex.c:expand_complex_div_wide(). | |
2022 | |
2023 Expand complex division to scalars, modified algorithm to minimize | |
2024 overflow with wide input ranges. */ | |
2025 tree compare = fold_build2 (LT_EXPR, boolean_type_node, | |
2026 fold_abs_const (r2, TREE_TYPE (type)), | |
2027 fold_abs_const (i2, TREE_TYPE (type))); | |
2028 | |
2029 if (integer_nonzerop (compare)) | |
2030 { | |
2031 /* In the TRUE branch, we compute | |
2032 ratio = br/bi; | |
2033 div = (br * ratio) + bi; | |
2034 tr = (ar * ratio) + ai; | |
2035 ti = (ai * ratio) - ar; | |
2036 tr = tr / div; | |
2037 ti = ti / div; */ | |
2038 tree ratio = const_binop (code, r2, i2, notrunc); | |
2039 tree div = const_binop (PLUS_EXPR, i2, | |
2040 const_binop (MULT_EXPR, r2, ratio, | |
2041 notrunc), | |
2042 notrunc); | |
2043 real = const_binop (MULT_EXPR, r1, ratio, notrunc); | |
2044 real = const_binop (PLUS_EXPR, real, i1, notrunc); | |
2045 real = const_binop (code, real, div, notrunc); | |
2046 | |
2047 imag = const_binop (MULT_EXPR, i1, ratio, notrunc); | |
2048 imag = const_binop (MINUS_EXPR, imag, r1, notrunc); | |
2049 imag = const_binop (code, imag, div, notrunc); | |
2050 } | |
2051 else | |
2052 { | |
2053 /* In the FALSE branch, we compute | |
2054 ratio = d/c; | |
2055 divisor = (d * ratio) + c; | |
2056 tr = (b * ratio) + a; | |
2057 ti = b - (a * ratio); | |
2058 tr = tr / div; | |
2059 ti = ti / div; */ | |
2060 tree ratio = const_binop (code, i2, r2, notrunc); | |
2061 tree div = const_binop (PLUS_EXPR, r2, | |
2062 const_binop (MULT_EXPR, i2, ratio, | |
2063 notrunc), | |
2064 notrunc); | |
2065 | |
2066 real = const_binop (MULT_EXPR, i1, ratio, notrunc); | |
2067 real = const_binop (PLUS_EXPR, real, r1, notrunc); | |
2068 real = const_binop (code, real, div, notrunc); | |
2069 | |
2070 imag = const_binop (MULT_EXPR, r1, ratio, notrunc); | |
2071 imag = const_binop (MINUS_EXPR, i1, imag, notrunc); | |
2072 imag = const_binop (code, imag, div, notrunc); | |
2073 } | |
2074 } | |
2002 break; | 2075 break; |
2003 | 2076 |
2004 default: | 2077 default: |
2005 return NULL_TREE; | 2078 return NULL_TREE; |
2006 } | 2079 } |
2007 | 2080 |
2008 if (real && imag) | 2081 if (real && imag) |
2009 return build_complex (type, real, imag); | 2082 return build_complex (type, real, imag); |
2010 } | 2083 } |
2011 | 2084 |
2085 if (TREE_CODE (arg1) == VECTOR_CST) | |
2086 { | |
2087 tree type = TREE_TYPE(arg1); | |
2088 int count = TYPE_VECTOR_SUBPARTS (type), i; | |
2089 tree elements1, elements2, list = NULL_TREE; | |
2090 | |
2091 if(TREE_CODE(arg2) != VECTOR_CST) | |
2092 return NULL_TREE; | |
2093 | |
2094 elements1 = TREE_VECTOR_CST_ELTS (arg1); | |
2095 elements2 = TREE_VECTOR_CST_ELTS (arg2); | |
2096 | |
2097 for (i = 0; i < count; i++) | |
2098 { | |
2099 tree elem1, elem2, elem; | |
2100 | |
2101 /* The trailing elements can be empty and should be treated as 0 */ | |
2102 if(!elements1) | |
2103 elem1 = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node); | |
2104 else | |
2105 { | |
2106 elem1 = TREE_VALUE(elements1); | |
2107 elements1 = TREE_CHAIN (elements1); | |
2108 } | |
2109 | |
2110 if(!elements2) | |
2111 elem2 = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node); | |
2112 else | |
2113 { | |
2114 elem2 = TREE_VALUE(elements2); | |
2115 elements2 = TREE_CHAIN (elements2); | |
2116 } | |
2117 | |
2118 elem = const_binop (code, elem1, elem2, notrunc); | |
2119 | |
2120 /* It is possible that const_binop cannot handle the given | |
2121 code and return NULL_TREE */ | |
2122 if(elem == NULL_TREE) | |
2123 return NULL_TREE; | |
2124 | |
2125 list = tree_cons (NULL_TREE, elem, list); | |
2126 } | |
2127 return build_vector(type, nreverse(list)); | |
2128 } | |
2012 return NULL_TREE; | 2129 return NULL_TREE; |
2013 } | 2130 } |
2014 | 2131 |
2015 /* Create a size type INT_CST node with NUMBER sign extended. KIND | 2132 /* Create a size type INT_CST node with NUMBER sign extended. KIND |
2016 indicates which particular sizetype to create. */ | 2133 indicates which particular sizetype to create. */ |
2025 is a tree code. The type of the result is taken from the operands. | 2142 is a tree code. The type of the result is taken from the operands. |
2026 Both must be equivalent integer types, ala int_binop_types_match_p. | 2143 Both must be equivalent integer types, ala int_binop_types_match_p. |
2027 If the operands are constant, so is the result. */ | 2144 If the operands are constant, so is the result. */ |
2028 | 2145 |
2029 tree | 2146 tree |
2030 size_binop (enum tree_code code, tree arg0, tree arg1) | 2147 size_binop_loc (location_t loc, enum tree_code code, tree arg0, tree arg1) |
2031 { | 2148 { |
2032 tree type = TREE_TYPE (arg0); | 2149 tree type = TREE_TYPE (arg0); |
2033 | 2150 |
2034 if (arg0 == error_mark_node || arg1 == error_mark_node) | 2151 if (arg0 == error_mark_node || arg1 == error_mark_node) |
2035 return error_mark_node; | 2152 return error_mark_node; |
2061 | 2178 |
2062 /* Handle general case of two integer constants. */ | 2179 /* Handle general case of two integer constants. */ |
2063 return int_const_binop (code, arg0, arg1, 0); | 2180 return int_const_binop (code, arg0, arg1, 0); |
2064 } | 2181 } |
2065 | 2182 |
2066 return fold_build2 (code, type, arg0, arg1); | 2183 return fold_build2_loc (loc, code, type, arg0, arg1); |
2067 } | 2184 } |
2068 | 2185 |
2069 /* Given two values, either both of sizetype or both of bitsizetype, | 2186 /* Given two values, either both of sizetype or both of bitsizetype, |
2070 compute the difference between the two values. Return the value | 2187 compute the difference between the two values. Return the value |
2071 in signed type corresponding to the type of the operands. */ | 2188 in signed type corresponding to the type of the operands. */ |
2072 | 2189 |
2073 tree | 2190 tree |
2074 size_diffop (tree arg0, tree arg1) | 2191 size_diffop_loc (location_t loc, tree arg0, tree arg1) |
2075 { | 2192 { |
2076 tree type = TREE_TYPE (arg0); | 2193 tree type = TREE_TYPE (arg0); |
2077 tree ctype; | 2194 tree ctype; |
2078 | 2195 |
2079 gcc_assert (int_binop_types_match_p (MINUS_EXPR, TREE_TYPE (arg0), | 2196 gcc_assert (int_binop_types_match_p (MINUS_EXPR, TREE_TYPE (arg0), |
2080 TREE_TYPE (arg1))); | 2197 TREE_TYPE (arg1))); |
2081 | 2198 |
2082 /* If the type is already signed, just do the simple thing. */ | 2199 /* If the type is already signed, just do the simple thing. */ |
2083 if (!TYPE_UNSIGNED (type)) | 2200 if (!TYPE_UNSIGNED (type)) |
2084 return size_binop (MINUS_EXPR, arg0, arg1); | 2201 return size_binop_loc (loc, MINUS_EXPR, arg0, arg1); |
2085 | 2202 |
2086 if (type == sizetype) | 2203 if (type == sizetype) |
2087 ctype = ssizetype; | 2204 ctype = ssizetype; |
2088 else if (type == bitsizetype) | 2205 else if (type == bitsizetype) |
2089 ctype = sbitsizetype; | 2206 ctype = sbitsizetype; |
2092 | 2209 |
2093 /* If either operand is not a constant, do the conversions to the signed | 2210 /* If either operand is not a constant, do the conversions to the signed |
2094 type and subtract. The hardware will do the right thing with any | 2211 type and subtract. The hardware will do the right thing with any |
2095 overflow in the subtraction. */ | 2212 overflow in the subtraction. */ |
2096 if (TREE_CODE (arg0) != INTEGER_CST || TREE_CODE (arg1) != INTEGER_CST) | 2213 if (TREE_CODE (arg0) != INTEGER_CST || TREE_CODE (arg1) != INTEGER_CST) |
2097 return size_binop (MINUS_EXPR, fold_convert (ctype, arg0), | 2214 return size_binop_loc (loc, MINUS_EXPR, |
2098 fold_convert (ctype, arg1)); | 2215 fold_convert_loc (loc, ctype, arg0), |
2216 fold_convert_loc (loc, ctype, arg1)); | |
2099 | 2217 |
2100 /* If ARG0 is larger than ARG1, subtract and return the result in CTYPE. | 2218 /* If ARG0 is larger than ARG1, subtract and return the result in CTYPE. |
2101 Otherwise, subtract the other way, convert to CTYPE (we know that can't | 2219 Otherwise, subtract the other way, convert to CTYPE (we know that can't |
2102 overflow) and negate (which can't either). Special-case a result | 2220 overflow) and negate (which can't either). Special-case a result |
2103 of zero while we're here. */ | 2221 of zero while we're here. */ |
2104 if (tree_int_cst_equal (arg0, arg1)) | 2222 if (tree_int_cst_equal (arg0, arg1)) |
2105 return build_int_cst (ctype, 0); | 2223 return build_int_cst (ctype, 0); |
2106 else if (tree_int_cst_lt (arg1, arg0)) | 2224 else if (tree_int_cst_lt (arg1, arg0)) |
2107 return fold_convert (ctype, size_binop (MINUS_EXPR, arg0, arg1)); | 2225 return fold_convert_loc (loc, ctype, |
2226 size_binop_loc (loc, MINUS_EXPR, arg0, arg1)); | |
2108 else | 2227 else |
2109 return size_binop (MINUS_EXPR, build_int_cst (ctype, 0), | 2228 return size_binop_loc (loc, MINUS_EXPR, build_int_cst (ctype, 0), |
2110 fold_convert (ctype, size_binop (MINUS_EXPR, | 2229 fold_convert_loc (loc, ctype, |
2111 arg1, arg0))); | 2230 size_binop_loc (loc, |
2231 MINUS_EXPR, | |
2232 arg1, arg0))); | |
2112 } | 2233 } |
2113 | 2234 |
2114 /* A subroutine of fold_convert_const handling conversions of an | 2235 /* A subroutine of fold_convert_const handling conversions of an |
2115 INTEGER_CST to another integer type. */ | 2236 INTEGER_CST to another integer type. */ |
2116 | 2237 |
2291 tree t; | 2412 tree t; |
2292 | 2413 |
2293 real_convert (&value, TYPE_MODE (type), &TREE_REAL_CST (arg1)); | 2414 real_convert (&value, TYPE_MODE (type), &TREE_REAL_CST (arg1)); |
2294 t = build_real (type, value); | 2415 t = build_real (type, value); |
2295 | 2416 |
2296 TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1); | 2417 /* If converting an infinity or NAN to a representation that doesn't |
2418 have one, set the overflow bit so that we can produce some kind of | |
2419 error message at the appropriate point if necessary. It's not the | |
2420 most user-friendly message, but it's better than nothing. */ | |
2421 if (REAL_VALUE_ISINF (TREE_REAL_CST (arg1)) | |
2422 && !MODE_HAS_INFINITIES (TYPE_MODE (type))) | |
2423 TREE_OVERFLOW (t) = 1; | |
2424 else if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)) | |
2425 && !MODE_HAS_NANS (TYPE_MODE (type))) | |
2426 TREE_OVERFLOW (t) = 1; | |
2427 /* Regular overflow, conversion produced an infinity in a mode that | |
2428 can't represent them. */ | |
2429 else if (!MODE_HAS_INFINITIES (TYPE_MODE (type)) | |
2430 && REAL_VALUE_ISINF (value) | |
2431 && !REAL_VALUE_ISINF (TREE_REAL_CST (arg1))) | |
2432 TREE_OVERFLOW (t) = 1; | |
2433 else | |
2434 TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1); | |
2297 return t; | 2435 return t; |
2298 } | 2436 } |
2299 | 2437 |
2300 /* A subroutine of fold_convert_const handling conversions a FIXED_CST | 2438 /* A subroutine of fold_convert_const handling conversions a FIXED_CST |
2301 to a floating point type. */ | 2439 to a floating point type. */ |
2308 | 2446 |
2309 real_convert_from_fixed (&value, TYPE_MODE (type), &TREE_FIXED_CST (arg1)); | 2447 real_convert_from_fixed (&value, TYPE_MODE (type), &TREE_FIXED_CST (arg1)); |
2310 t = build_real (type, value); | 2448 t = build_real (type, value); |
2311 | 2449 |
2312 TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1); | 2450 TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1); |
2313 TREE_CONSTANT_OVERFLOW (t) | |
2314 = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1); | |
2315 return t; | 2451 return t; |
2316 } | 2452 } |
2317 | 2453 |
2318 /* A subroutine of fold_convert_const handling conversions a FIXED_CST | 2454 /* A subroutine of fold_convert_const handling conversions a FIXED_CST |
2319 to another fixed-point type. */ | 2455 to another fixed-point type. */ |
2329 TYPE_SATURATING (type)); | 2465 TYPE_SATURATING (type)); |
2330 t = build_fixed (type, value); | 2466 t = build_fixed (type, value); |
2331 | 2467 |
2332 /* Propagate overflow flags. */ | 2468 /* Propagate overflow flags. */ |
2333 if (overflow_p | TREE_OVERFLOW (arg1)) | 2469 if (overflow_p | TREE_OVERFLOW (arg1)) |
2334 { | 2470 TREE_OVERFLOW (t) = 1; |
2335 TREE_OVERFLOW (t) = 1; | |
2336 TREE_CONSTANT_OVERFLOW (t) = 1; | |
2337 } | |
2338 else if (TREE_CONSTANT_OVERFLOW (arg1)) | |
2339 TREE_CONSTANT_OVERFLOW (t) = 1; | |
2340 return t; | 2471 return t; |
2341 } | 2472 } |
2342 | 2473 |
2343 /* A subroutine of fold_convert_const handling conversions an INTEGER_CST | 2474 /* A subroutine of fold_convert_const handling conversions an INTEGER_CST |
2344 to a fixed-point type. */ | 2475 to a fixed-point type. */ |
2356 TYPE_SATURATING (type)); | 2487 TYPE_SATURATING (type)); |
2357 t = build_fixed (type, value); | 2488 t = build_fixed (type, value); |
2358 | 2489 |
2359 /* Propagate overflow flags. */ | 2490 /* Propagate overflow flags. */ |
2360 if (overflow_p | TREE_OVERFLOW (arg1)) | 2491 if (overflow_p | TREE_OVERFLOW (arg1)) |
2361 { | 2492 TREE_OVERFLOW (t) = 1; |
2362 TREE_OVERFLOW (t) = 1; | |
2363 TREE_CONSTANT_OVERFLOW (t) = 1; | |
2364 } | |
2365 else if (TREE_CONSTANT_OVERFLOW (arg1)) | |
2366 TREE_CONSTANT_OVERFLOW (t) = 1; | |
2367 return t; | 2493 return t; |
2368 } | 2494 } |
2369 | 2495 |
2370 /* A subroutine of fold_convert_const handling conversions a REAL_CST | 2496 /* A subroutine of fold_convert_const handling conversions a REAL_CST |
2371 to a fixed-point type. */ | 2497 to a fixed-point type. */ |
2382 TYPE_SATURATING (type)); | 2508 TYPE_SATURATING (type)); |
2383 t = build_fixed (type, value); | 2509 t = build_fixed (type, value); |
2384 | 2510 |
2385 /* Propagate overflow flags. */ | 2511 /* Propagate overflow flags. */ |
2386 if (overflow_p | TREE_OVERFLOW (arg1)) | 2512 if (overflow_p | TREE_OVERFLOW (arg1)) |
2387 { | 2513 TREE_OVERFLOW (t) = 1; |
2388 TREE_OVERFLOW (t) = 1; | |
2389 TREE_CONSTANT_OVERFLOW (t) = 1; | |
2390 } | |
2391 else if (TREE_CONSTANT_OVERFLOW (arg1)) | |
2392 TREE_CONSTANT_OVERFLOW (t) = 1; | |
2393 return t; | 2514 return t; |
2394 } | 2515 } |
2395 | 2516 |
2396 /* Attempt to fold type conversion operation CODE of expression ARG1 to | 2517 /* Attempt to fold type conversion operation CODE of expression ARG1 to |
2397 type TYPE. If no simplification can be done return NULL_TREE. */ | 2518 type TYPE. If no simplification can be done return NULL_TREE. */ |
2441 tree elem, list; | 2562 tree elem, list; |
2442 int i, units; | 2563 int i, units; |
2443 | 2564 |
2444 elem = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node); | 2565 elem = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node); |
2445 units = TYPE_VECTOR_SUBPARTS (type); | 2566 units = TYPE_VECTOR_SUBPARTS (type); |
2446 | 2567 |
2447 list = NULL_TREE; | 2568 list = NULL_TREE; |
2448 for (i = 0; i < units; i++) | 2569 for (i = 0; i < units; i++) |
2449 list = tree_cons (NULL_TREE, elem, list); | 2570 list = tree_cons (NULL_TREE, elem, list); |
2450 return build_vector (type, list); | 2571 return build_vector (type, list); |
2451 } | 2572 } |
2493 | 2614 |
2494 /* Convert expression ARG to type TYPE. Used by the middle-end for | 2615 /* Convert expression ARG to type TYPE. Used by the middle-end for |
2495 simple conversions in preference to calling the front-end's convert. */ | 2616 simple conversions in preference to calling the front-end's convert. */ |
2496 | 2617 |
2497 tree | 2618 tree |
2498 fold_convert (tree type, tree arg) | 2619 fold_convert_loc (location_t loc, tree type, tree arg) |
2499 { | 2620 { |
2500 tree orig = TREE_TYPE (arg); | 2621 tree orig = TREE_TYPE (arg); |
2501 tree tem; | 2622 tree tem; |
2502 | 2623 |
2503 if (type == orig) | 2624 if (type == orig) |
2507 || TREE_CODE (type) == ERROR_MARK | 2628 || TREE_CODE (type) == ERROR_MARK |
2508 || TREE_CODE (orig) == ERROR_MARK) | 2629 || TREE_CODE (orig) == ERROR_MARK) |
2509 return error_mark_node; | 2630 return error_mark_node; |
2510 | 2631 |
2511 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig)) | 2632 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig)) |
2512 return fold_build1 (NOP_EXPR, type, arg); | 2633 return fold_build1_loc (loc, NOP_EXPR, type, arg); |
2513 | 2634 |
2514 switch (TREE_CODE (type)) | 2635 switch (TREE_CODE (type)) |
2515 { | 2636 { |
2637 case POINTER_TYPE: | |
2638 case REFERENCE_TYPE: | |
2639 /* Handle conversions between pointers to different address spaces. */ | |
2640 if (POINTER_TYPE_P (orig) | |
2641 && (TYPE_ADDR_SPACE (TREE_TYPE (type)) | |
2642 != TYPE_ADDR_SPACE (TREE_TYPE (orig)))) | |
2643 return fold_build1_loc (loc, ADDR_SPACE_CONVERT_EXPR, type, arg); | |
2644 /* fall through */ | |
2645 | |
2516 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: | 2646 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE: |
2517 case POINTER_TYPE: case REFERENCE_TYPE: | |
2518 case OFFSET_TYPE: | 2647 case OFFSET_TYPE: |
2519 if (TREE_CODE (arg) == INTEGER_CST) | 2648 if (TREE_CODE (arg) == INTEGER_CST) |
2520 { | 2649 { |
2521 tem = fold_convert_const (NOP_EXPR, type, arg); | 2650 tem = fold_convert_const (NOP_EXPR, type, arg); |
2522 if (tem != NULL_TREE) | 2651 if (tem != NULL_TREE) |
2523 return tem; | 2652 return tem; |
2524 } | 2653 } |
2525 if (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig) | 2654 if (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig) |
2526 || TREE_CODE (orig) == OFFSET_TYPE) | 2655 || TREE_CODE (orig) == OFFSET_TYPE) |
2527 return fold_build1 (NOP_EXPR, type, arg); | 2656 return fold_build1_loc (loc, NOP_EXPR, type, arg); |
2528 if (TREE_CODE (orig) == COMPLEX_TYPE) | 2657 if (TREE_CODE (orig) == COMPLEX_TYPE) |
2529 { | 2658 return fold_convert_loc (loc, type, |
2530 tem = fold_build1 (REALPART_EXPR, TREE_TYPE (orig), arg); | 2659 fold_build1_loc (loc, REALPART_EXPR, |
2531 return fold_convert (type, tem); | 2660 TREE_TYPE (orig), arg)); |
2532 } | |
2533 gcc_assert (TREE_CODE (orig) == VECTOR_TYPE | 2661 gcc_assert (TREE_CODE (orig) == VECTOR_TYPE |
2534 && tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig))); | 2662 && tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig))); |
2535 return fold_build1 (NOP_EXPR, type, arg); | 2663 return fold_build1_loc (loc, NOP_EXPR, type, arg); |
2536 | 2664 |
2537 case REAL_TYPE: | 2665 case REAL_TYPE: |
2538 if (TREE_CODE (arg) == INTEGER_CST) | 2666 if (TREE_CODE (arg) == INTEGER_CST) |
2539 { | 2667 { |
2540 tem = fold_convert_const (FLOAT_EXPR, type, arg); | 2668 tem = fold_convert_const (FLOAT_EXPR, type, arg); |
2557 switch (TREE_CODE (orig)) | 2685 switch (TREE_CODE (orig)) |
2558 { | 2686 { |
2559 case INTEGER_TYPE: | 2687 case INTEGER_TYPE: |
2560 case BOOLEAN_TYPE: case ENUMERAL_TYPE: | 2688 case BOOLEAN_TYPE: case ENUMERAL_TYPE: |
2561 case POINTER_TYPE: case REFERENCE_TYPE: | 2689 case POINTER_TYPE: case REFERENCE_TYPE: |
2562 return fold_build1 (FLOAT_EXPR, type, arg); | 2690 return fold_build1_loc (loc, FLOAT_EXPR, type, arg); |
2563 | 2691 |
2564 case REAL_TYPE: | 2692 case REAL_TYPE: |
2565 return fold_build1 (NOP_EXPR, type, arg); | 2693 return fold_build1_loc (loc, NOP_EXPR, type, arg); |
2566 | 2694 |
2567 case FIXED_POINT_TYPE: | 2695 case FIXED_POINT_TYPE: |
2568 return fold_build1 (FIXED_CONVERT_EXPR, type, arg); | 2696 return fold_build1_loc (loc, FIXED_CONVERT_EXPR, type, arg); |
2569 | 2697 |
2570 case COMPLEX_TYPE: | 2698 case COMPLEX_TYPE: |
2571 tem = fold_build1 (REALPART_EXPR, TREE_TYPE (orig), arg); | 2699 tem = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg); |
2572 return fold_convert (type, tem); | 2700 return fold_convert_loc (loc, type, tem); |
2573 | 2701 |
2574 default: | 2702 default: |
2575 gcc_unreachable (); | 2703 gcc_unreachable (); |
2576 } | 2704 } |
2577 | 2705 |
2579 if (TREE_CODE (arg) == FIXED_CST || TREE_CODE (arg) == INTEGER_CST | 2707 if (TREE_CODE (arg) == FIXED_CST || TREE_CODE (arg) == INTEGER_CST |
2580 || TREE_CODE (arg) == REAL_CST) | 2708 || TREE_CODE (arg) == REAL_CST) |
2581 { | 2709 { |
2582 tem = fold_convert_const (FIXED_CONVERT_EXPR, type, arg); | 2710 tem = fold_convert_const (FIXED_CONVERT_EXPR, type, arg); |
2583 if (tem != NULL_TREE) | 2711 if (tem != NULL_TREE) |
2584 return tem; | 2712 goto fold_convert_exit; |
2585 } | 2713 } |
2586 | 2714 |
2587 switch (TREE_CODE (orig)) | 2715 switch (TREE_CODE (orig)) |
2588 { | 2716 { |
2589 case FIXED_POINT_TYPE: | 2717 case FIXED_POINT_TYPE: |
2590 case INTEGER_TYPE: | 2718 case INTEGER_TYPE: |
2591 case ENUMERAL_TYPE: | 2719 case ENUMERAL_TYPE: |
2592 case BOOLEAN_TYPE: | 2720 case BOOLEAN_TYPE: |
2593 case REAL_TYPE: | 2721 case REAL_TYPE: |
2594 return fold_build1 (FIXED_CONVERT_EXPR, type, arg); | 2722 return fold_build1_loc (loc, FIXED_CONVERT_EXPR, type, arg); |
2595 | 2723 |
2596 case COMPLEX_TYPE: | 2724 case COMPLEX_TYPE: |
2597 tem = fold_build1 (REALPART_EXPR, TREE_TYPE (orig), arg); | 2725 tem = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg); |
2598 return fold_convert (type, tem); | 2726 return fold_convert_loc (loc, type, tem); |
2599 | 2727 |
2600 default: | 2728 default: |
2601 gcc_unreachable (); | 2729 gcc_unreachable (); |
2602 } | 2730 } |
2603 | 2731 |
2607 case INTEGER_TYPE: | 2735 case INTEGER_TYPE: |
2608 case BOOLEAN_TYPE: case ENUMERAL_TYPE: | 2736 case BOOLEAN_TYPE: case ENUMERAL_TYPE: |
2609 case POINTER_TYPE: case REFERENCE_TYPE: | 2737 case POINTER_TYPE: case REFERENCE_TYPE: |
2610 case REAL_TYPE: | 2738 case REAL_TYPE: |
2611 case FIXED_POINT_TYPE: | 2739 case FIXED_POINT_TYPE: |
2612 return fold_build2 (COMPLEX_EXPR, type, | 2740 return fold_build2_loc (loc, COMPLEX_EXPR, type, |
2613 fold_convert (TREE_TYPE (type), arg), | 2741 fold_convert_loc (loc, TREE_TYPE (type), arg), |
2614 fold_convert (TREE_TYPE (type), | 2742 fold_convert_loc (loc, TREE_TYPE (type), |
2615 integer_zero_node)); | 2743 integer_zero_node)); |
2616 case COMPLEX_TYPE: | 2744 case COMPLEX_TYPE: |
2617 { | 2745 { |
2618 tree rpart, ipart; | 2746 tree rpart, ipart; |
2619 | 2747 |
2620 if (TREE_CODE (arg) == COMPLEX_EXPR) | 2748 if (TREE_CODE (arg) == COMPLEX_EXPR) |
2621 { | 2749 { |
2622 rpart = fold_convert (TREE_TYPE (type), TREE_OPERAND (arg, 0)); | 2750 rpart = fold_convert_loc (loc, TREE_TYPE (type), |
2623 ipart = fold_convert (TREE_TYPE (type), TREE_OPERAND (arg, 1)); | 2751 TREE_OPERAND (arg, 0)); |
2624 return fold_build2 (COMPLEX_EXPR, type, rpart, ipart); | 2752 ipart = fold_convert_loc (loc, TREE_TYPE (type), |
2753 TREE_OPERAND (arg, 1)); | |
2754 return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart, ipart); | |
2625 } | 2755 } |
2626 | 2756 |
2627 arg = save_expr (arg); | 2757 arg = save_expr (arg); |
2628 rpart = fold_build1 (REALPART_EXPR, TREE_TYPE (orig), arg); | 2758 rpart = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg); |
2629 ipart = fold_build1 (IMAGPART_EXPR, TREE_TYPE (orig), arg); | 2759 ipart = fold_build1_loc (loc, IMAGPART_EXPR, TREE_TYPE (orig), arg); |
2630 rpart = fold_convert (TREE_TYPE (type), rpart); | 2760 rpart = fold_convert_loc (loc, TREE_TYPE (type), rpart); |
2631 ipart = fold_convert (TREE_TYPE (type), ipart); | 2761 ipart = fold_convert_loc (loc, TREE_TYPE (type), ipart); |
2632 return fold_build2 (COMPLEX_EXPR, type, rpart, ipart); | 2762 return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart, ipart); |
2633 } | 2763 } |
2634 | 2764 |
2635 default: | 2765 default: |
2636 gcc_unreachable (); | 2766 gcc_unreachable (); |
2637 } | 2767 } |
2640 if (integer_zerop (arg)) | 2770 if (integer_zerop (arg)) |
2641 return build_zero_vector (type); | 2771 return build_zero_vector (type); |
2642 gcc_assert (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig))); | 2772 gcc_assert (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig))); |
2643 gcc_assert (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig) | 2773 gcc_assert (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig) |
2644 || TREE_CODE (orig) == VECTOR_TYPE); | 2774 || TREE_CODE (orig) == VECTOR_TYPE); |
2645 return fold_build1 (VIEW_CONVERT_EXPR, type, arg); | 2775 return fold_build1_loc (loc, VIEW_CONVERT_EXPR, type, arg); |
2646 | 2776 |
2647 case VOID_TYPE: | 2777 case VOID_TYPE: |
2648 tem = fold_ignored_result (arg); | 2778 tem = fold_ignored_result (arg); |
2649 if (TREE_CODE (tem) == MODIFY_EXPR) | 2779 if (TREE_CODE (tem) == MODIFY_EXPR) |
2650 return tem; | 2780 goto fold_convert_exit; |
2651 return fold_build1 (NOP_EXPR, type, tem); | 2781 return fold_build1_loc (loc, NOP_EXPR, type, tem); |
2652 | 2782 |
2653 default: | 2783 default: |
2654 gcc_unreachable (); | 2784 gcc_unreachable (); |
2655 } | 2785 } |
2786 fold_convert_exit: | |
2787 protected_set_expr_location (tem, loc); | |
2788 return tem; | |
2656 } | 2789 } |
2657 | 2790 |
2658 /* Return false if expr can be assumed not to be an lvalue, true | 2791 /* Return false if expr can be assumed not to be an lvalue, true |
2659 otherwise. */ | 2792 otherwise. */ |
2660 | 2793 |
2690 case COMPOUND_EXPR: | 2823 case COMPOUND_EXPR: |
2691 case MODIFY_EXPR: | 2824 case MODIFY_EXPR: |
2692 case TARGET_EXPR: | 2825 case TARGET_EXPR: |
2693 case COND_EXPR: | 2826 case COND_EXPR: |
2694 case BIND_EXPR: | 2827 case BIND_EXPR: |
2695 case MIN_EXPR: | |
2696 case MAX_EXPR: | |
2697 break; | 2828 break; |
2698 | 2829 |
2699 default: | 2830 default: |
2700 /* Assume the worst for front-end tree codes. */ | 2831 /* Assume the worst for front-end tree codes. */ |
2701 if ((int)TREE_CODE (x) >= NUM_TREE_CODES) | 2832 if ((int)TREE_CODE (x) >= NUM_TREE_CODES) |
2707 } | 2838 } |
2708 | 2839 |
2709 /* Return an expr equal to X but certainly not valid as an lvalue. */ | 2840 /* Return an expr equal to X but certainly not valid as an lvalue. */ |
2710 | 2841 |
2711 tree | 2842 tree |
2712 non_lvalue (tree x) | 2843 non_lvalue_loc (location_t loc, tree x) |
2713 { | 2844 { |
2714 /* While we are in GIMPLE, NON_LVALUE_EXPR doesn't mean anything to | 2845 /* While we are in GIMPLE, NON_LVALUE_EXPR doesn't mean anything to |
2715 us. */ | 2846 us. */ |
2716 if (in_gimple_form) | 2847 if (in_gimple_form) |
2717 return x; | 2848 return x; |
2718 | 2849 |
2719 if (! maybe_lvalue_p (x)) | 2850 if (! maybe_lvalue_p (x)) |
2720 return x; | 2851 return x; |
2721 return build1 (NON_LVALUE_EXPR, TREE_TYPE (x), x); | 2852 x = build1 (NON_LVALUE_EXPR, TREE_TYPE (x), x); |
2853 SET_EXPR_LOCATION (x, loc); | |
2854 return x; | |
2722 } | 2855 } |
2723 | 2856 |
2724 /* Nonzero means lvalues are limited to those valid in pedantic ANSI C. | 2857 /* Nonzero means lvalues are limited to those valid in pedantic ANSI C. |
2725 Zero means allow extended lvalues. */ | 2858 Zero means allow extended lvalues. */ |
2726 | 2859 |
2728 | 2861 |
2729 /* When pedantic, return an expr equal to X but certainly not valid as a | 2862 /* When pedantic, return an expr equal to X but certainly not valid as a |
2730 pedantic lvalue. Otherwise, return X. */ | 2863 pedantic lvalue. Otherwise, return X. */ |
2731 | 2864 |
2732 static tree | 2865 static tree |
2733 pedantic_non_lvalue (tree x) | 2866 pedantic_non_lvalue_loc (location_t loc, tree x) |
2734 { | 2867 { |
2735 if (pedantic_lvalues) | 2868 if (pedantic_lvalues) |
2736 return non_lvalue (x); | 2869 return non_lvalue_loc (loc, x); |
2737 else | 2870 protected_set_expr_location (x, loc); |
2738 return x; | 2871 return x; |
2739 } | 2872 } |
2740 | 2873 |
2741 /* Given a tree comparison code, return the code that is the logical inverse | 2874 /* Given a tree comparison code, return the code that is the logical inverse |
2742 of the given code. It is not safe to do this for floating-point | 2875 of the given code. It is not safe to do this for floating-point |
2743 comparisons, except for NE_EXPR and EQ_EXPR, so we receive a machine mode | 2876 comparisons, except for NE_EXPR and EQ_EXPR, so we receive a machine mode |
2910 and RCODE on the identical operands LL_ARG and LR_ARG. Take into account | 3043 and RCODE on the identical operands LL_ARG and LR_ARG. Take into account |
2911 the possibility of trapping if the mode has NaNs, and return NULL_TREE | 3044 the possibility of trapping if the mode has NaNs, and return NULL_TREE |
2912 if this makes the transformation invalid. */ | 3045 if this makes the transformation invalid. */ |
2913 | 3046 |
2914 tree | 3047 tree |
2915 combine_comparisons (enum tree_code code, enum tree_code lcode, | 3048 combine_comparisons (location_t loc, |
3049 enum tree_code code, enum tree_code lcode, | |
2916 enum tree_code rcode, tree truth_type, | 3050 enum tree_code rcode, tree truth_type, |
2917 tree ll_arg, tree lr_arg) | 3051 tree ll_arg, tree lr_arg) |
2918 { | 3052 { |
2919 bool honor_nans = HONOR_NANS (TYPE_MODE (TREE_TYPE (ll_arg))); | 3053 bool honor_nans = HONOR_NANS (TYPE_MODE (TREE_TYPE (ll_arg))); |
2920 enum comparison_code lcompcode = comparison_to_compcode (lcode); | 3054 enum comparison_code lcompcode = comparison_to_compcode (lcode); |
2921 enum comparison_code rcompcode = comparison_to_compcode (rcode); | 3055 enum comparison_code rcompcode = comparison_to_compcode (rcode); |
2922 enum comparison_code compcode; | 3056 int compcode; |
2923 | 3057 |
2924 switch (code) | 3058 switch (code) |
2925 { | 3059 { |
2926 case TRUTH_AND_EXPR: case TRUTH_ANDIF_EXPR: | 3060 case TRUTH_AND_EXPR: case TRUTH_ANDIF_EXPR: |
2927 compcode = lcompcode & rcompcode; | 3061 compcode = lcompcode & rcompcode; |
2983 if (compcode == COMPCODE_TRUE) | 3117 if (compcode == COMPCODE_TRUE) |
2984 return constant_boolean_node (true, truth_type); | 3118 return constant_boolean_node (true, truth_type); |
2985 else if (compcode == COMPCODE_FALSE) | 3119 else if (compcode == COMPCODE_FALSE) |
2986 return constant_boolean_node (false, truth_type); | 3120 return constant_boolean_node (false, truth_type); |
2987 else | 3121 else |
2988 return fold_build2 (compcode_to_comparison (compcode), | 3122 { |
2989 truth_type, ll_arg, lr_arg); | 3123 enum tree_code tcode; |
3124 | |
3125 tcode = compcode_to_comparison ((enum comparison_code) compcode); | |
3126 return fold_build2_loc (loc, tcode, truth_type, ll_arg, lr_arg); | |
3127 } | |
2990 } | 3128 } |
2991 | 3129 |
2992 /* Return nonzero if two operands (typically of the same tree node) | 3130 /* Return nonzero if two operands (typically of the same tree node) |
2993 are necessarily equal. If either argument has side-effects this | 3131 are necessarily equal. If either argument has side-effects this |
2994 function returns zero. FLAGS modifies behavior as follows: | 3132 function returns zero. FLAGS modifies behavior as follows: |
3032 because they may change the signedness of the arguments. As pointers | 3170 because they may change the signedness of the arguments. As pointers |
3033 strictly don't have a signedness, require either two pointers or | 3171 strictly don't have a signedness, require either two pointers or |
3034 two non-pointers as well. */ | 3172 two non-pointers as well. */ |
3035 if (TYPE_UNSIGNED (TREE_TYPE (arg0)) != TYPE_UNSIGNED (TREE_TYPE (arg1)) | 3173 if (TYPE_UNSIGNED (TREE_TYPE (arg0)) != TYPE_UNSIGNED (TREE_TYPE (arg1)) |
3036 || POINTER_TYPE_P (TREE_TYPE (arg0)) != POINTER_TYPE_P (TREE_TYPE (arg1))) | 3174 || POINTER_TYPE_P (TREE_TYPE (arg0)) != POINTER_TYPE_P (TREE_TYPE (arg1))) |
3175 return 0; | |
3176 | |
3177 /* We cannot consider pointers to different address space equal. */ | |
3178 if (POINTER_TYPE_P (TREE_TYPE (arg0)) && POINTER_TYPE_P (TREE_TYPE (arg1)) | |
3179 && (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0))) | |
3180 != TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1))))) | |
3037 return 0; | 3181 return 0; |
3038 | 3182 |
3039 /* If both types don't have the same precision, then it is not safe | 3183 /* If both types don't have the same precision, then it is not safe |
3040 to strip NOPs. */ | 3184 to strip NOPs. */ |
3041 if (TYPE_PRECISION (TREE_TYPE (arg0)) != TYPE_PRECISION (TREE_TYPE (arg1))) | 3185 if (TYPE_PRECISION (TREE_TYPE (arg0)) != TYPE_PRECISION (TREE_TYPE (arg1))) |
3095 case REAL_CST: | 3239 case REAL_CST: |
3096 if (REAL_VALUES_IDENTICAL (TREE_REAL_CST (arg0), | 3240 if (REAL_VALUES_IDENTICAL (TREE_REAL_CST (arg0), |
3097 TREE_REAL_CST (arg1))) | 3241 TREE_REAL_CST (arg1))) |
3098 return 1; | 3242 return 1; |
3099 | 3243 |
3100 | 3244 |
3101 if (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))) | 3245 if (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))) |
3102 { | 3246 { |
3103 /* If we do not distinguish between signed and unsigned zero, | 3247 /* If we do not distinguish between signed and unsigned zero, |
3104 consider them equal. */ | 3248 consider them equal. */ |
3105 if (real_zerop (arg0) && real_zerop (arg1)) | 3249 if (real_zerop (arg0) && real_zerop (arg1)) |
3254 && operand_equal_p (TREE_OPERAND (arg0, 1), | 3398 && operand_equal_p (TREE_OPERAND (arg0, 1), |
3255 TREE_OPERAND (arg1, 0), flags)); | 3399 TREE_OPERAND (arg1, 0), flags)); |
3256 | 3400 |
3257 case COND_EXPR: | 3401 case COND_EXPR: |
3258 return OP_SAME (0) && OP_SAME (1) && OP_SAME (2); | 3402 return OP_SAME (0) && OP_SAME (1) && OP_SAME (2); |
3259 | 3403 |
3260 default: | 3404 default: |
3261 return 0; | 3405 return 0; |
3262 } | 3406 } |
3263 | 3407 |
3264 case tcc_vl_exp: | 3408 case tcc_vl_exp: |
3473 comparisons. Evaluate the operations in the tree substituting NEW0 for | 3617 comparisons. Evaluate the operations in the tree substituting NEW0 for |
3474 any occurrence of OLD0 as an operand of a comparison and likewise for | 3618 any occurrence of OLD0 as an operand of a comparison and likewise for |
3475 NEW1 and OLD1. */ | 3619 NEW1 and OLD1. */ |
3476 | 3620 |
3477 static tree | 3621 static tree |
3478 eval_subst (tree arg, tree old0, tree new0, tree old1, tree new1) | 3622 eval_subst (location_t loc, tree arg, tree old0, tree new0, |
3623 tree old1, tree new1) | |
3479 { | 3624 { |
3480 tree type = TREE_TYPE (arg); | 3625 tree type = TREE_TYPE (arg); |
3481 enum tree_code code = TREE_CODE (arg); | 3626 enum tree_code code = TREE_CODE (arg); |
3482 enum tree_code_class tclass = TREE_CODE_CLASS (code); | 3627 enum tree_code_class tclass = TREE_CODE_CLASS (code); |
3483 | 3628 |
3489 tclass = tcc_binary; | 3634 tclass = tcc_binary; |
3490 | 3635 |
3491 switch (tclass) | 3636 switch (tclass) |
3492 { | 3637 { |
3493 case tcc_unary: | 3638 case tcc_unary: |
3494 return fold_build1 (code, type, | 3639 return fold_build1_loc (loc, code, type, |
3495 eval_subst (TREE_OPERAND (arg, 0), | 3640 eval_subst (loc, TREE_OPERAND (arg, 0), |
3496 old0, new0, old1, new1)); | 3641 old0, new0, old1, new1)); |
3497 | 3642 |
3498 case tcc_binary: | 3643 case tcc_binary: |
3499 return fold_build2 (code, type, | 3644 return fold_build2_loc (loc, code, type, |
3500 eval_subst (TREE_OPERAND (arg, 0), | 3645 eval_subst (loc, TREE_OPERAND (arg, 0), |
3501 old0, new0, old1, new1), | 3646 old0, new0, old1, new1), |
3502 eval_subst (TREE_OPERAND (arg, 1), | 3647 eval_subst (loc, TREE_OPERAND (arg, 1), |
3503 old0, new0, old1, new1)); | 3648 old0, new0, old1, new1)); |
3504 | 3649 |
3505 case tcc_expression: | 3650 case tcc_expression: |
3506 switch (code) | 3651 switch (code) |
3507 { | 3652 { |
3508 case SAVE_EXPR: | 3653 case SAVE_EXPR: |
3509 return eval_subst (TREE_OPERAND (arg, 0), old0, new0, old1, new1); | 3654 return eval_subst (loc, TREE_OPERAND (arg, 0), old0, new0, |
3655 old1, new1); | |
3510 | 3656 |
3511 case COMPOUND_EXPR: | 3657 case COMPOUND_EXPR: |
3512 return eval_subst (TREE_OPERAND (arg, 1), old0, new0, old1, new1); | 3658 return eval_subst (loc, TREE_OPERAND (arg, 1), old0, new0, |
3659 old1, new1); | |
3513 | 3660 |
3514 case COND_EXPR: | 3661 case COND_EXPR: |
3515 return fold_build3 (code, type, | 3662 return fold_build3_loc (loc, code, type, |
3516 eval_subst (TREE_OPERAND (arg, 0), | 3663 eval_subst (loc, TREE_OPERAND (arg, 0), |
3517 old0, new0, old1, new1), | 3664 old0, new0, old1, new1), |
3518 eval_subst (TREE_OPERAND (arg, 1), | 3665 eval_subst (loc, TREE_OPERAND (arg, 1), |
3519 old0, new0, old1, new1), | 3666 old0, new0, old1, new1), |
3520 eval_subst (TREE_OPERAND (arg, 2), | 3667 eval_subst (loc, TREE_OPERAND (arg, 2), |
3521 old0, new0, old1, new1)); | 3668 old0, new0, old1, new1)); |
3522 default: | 3669 default: |
3523 break; | 3670 break; |
3524 } | 3671 } |
3525 /* Fall through - ??? */ | 3672 /* Fall through - ??? */ |
3541 if (arg1 == old0 || operand_equal_p (arg1, old0, 0)) | 3688 if (arg1 == old0 || operand_equal_p (arg1, old0, 0)) |
3542 arg1 = new0; | 3689 arg1 = new0; |
3543 else if (arg1 == old1 || operand_equal_p (arg1, old1, 0)) | 3690 else if (arg1 == old1 || operand_equal_p (arg1, old1, 0)) |
3544 arg1 = new1; | 3691 arg1 = new1; |
3545 | 3692 |
3546 return fold_build2 (code, type, arg0, arg1); | 3693 return fold_build2_loc (loc, code, type, arg0, arg1); |
3547 } | 3694 } |
3548 | 3695 |
3549 default: | 3696 default: |
3550 return arg; | 3697 return arg; |
3551 } | 3698 } |
3557 | 3704 |
3558 If OMITTED has side effects, we must evaluate it. Otherwise, just do | 3705 If OMITTED has side effects, we must evaluate it. Otherwise, just do |
3559 the conversion of RESULT to TYPE. */ | 3706 the conversion of RESULT to TYPE. */ |
3560 | 3707 |
3561 tree | 3708 tree |
3562 omit_one_operand (tree type, tree result, tree omitted) | 3709 omit_one_operand_loc (location_t loc, tree type, tree result, tree omitted) |
3563 { | 3710 { |
3564 tree t = fold_convert (type, result); | 3711 tree t = fold_convert_loc (loc, type, result); |
3565 | 3712 |
3566 /* If the resulting operand is an empty statement, just return the omitted | 3713 /* If the resulting operand is an empty statement, just return the omitted |
3567 statement casted to void. */ | 3714 statement casted to void. */ |
3568 if (IS_EMPTY_STMT (t) && TREE_SIDE_EFFECTS (omitted)) | 3715 if (IS_EMPTY_STMT (t) && TREE_SIDE_EFFECTS (omitted)) |
3569 return build1 (NOP_EXPR, void_type_node, fold_ignored_result (omitted)); | 3716 { |
3717 t = build1 (NOP_EXPR, void_type_node, fold_ignored_result (omitted)); | |
3718 goto omit_one_operand_exit; | |
3719 } | |
3570 | 3720 |
3571 if (TREE_SIDE_EFFECTS (omitted)) | 3721 if (TREE_SIDE_EFFECTS (omitted)) |
3572 return build2 (COMPOUND_EXPR, type, fold_ignored_result (omitted), t); | 3722 { |
3573 | 3723 t = build2 (COMPOUND_EXPR, type, fold_ignored_result (omitted), t); |
3574 return non_lvalue (t); | 3724 goto omit_one_operand_exit; |
3725 } | |
3726 | |
3727 return non_lvalue_loc (loc, t); | |
3728 | |
3729 omit_one_operand_exit: | |
3730 protected_set_expr_location (t, loc); | |
3731 return t; | |
3575 } | 3732 } |
3576 | 3733 |
3577 /* Similar, but call pedantic_non_lvalue instead of non_lvalue. */ | 3734 /* Similar, but call pedantic_non_lvalue instead of non_lvalue. */ |
3578 | 3735 |
3579 static tree | 3736 static tree |
3580 pedantic_omit_one_operand (tree type, tree result, tree omitted) | 3737 pedantic_omit_one_operand_loc (location_t loc, tree type, tree result, |
3581 { | 3738 tree omitted) |
3582 tree t = fold_convert (type, result); | 3739 { |
3740 tree t = fold_convert_loc (loc, type, result); | |
3583 | 3741 |
3584 /* If the resulting operand is an empty statement, just return the omitted | 3742 /* If the resulting operand is an empty statement, just return the omitted |
3585 statement casted to void. */ | 3743 statement casted to void. */ |
3586 if (IS_EMPTY_STMT (t) && TREE_SIDE_EFFECTS (omitted)) | 3744 if (IS_EMPTY_STMT (t) && TREE_SIDE_EFFECTS (omitted)) |
3587 return build1 (NOP_EXPR, void_type_node, fold_ignored_result (omitted)); | 3745 { |
3746 t = build1 (NOP_EXPR, void_type_node, fold_ignored_result (omitted)); | |
3747 goto pedantic_omit_one_operand_exit; | |
3748 } | |
3588 | 3749 |
3589 if (TREE_SIDE_EFFECTS (omitted)) | 3750 if (TREE_SIDE_EFFECTS (omitted)) |
3590 return build2 (COMPOUND_EXPR, type, fold_ignored_result (omitted), t); | 3751 { |
3591 | 3752 t = build2 (COMPOUND_EXPR, type, fold_ignored_result (omitted), t); |
3592 return pedantic_non_lvalue (t); | 3753 goto pedantic_omit_one_operand_exit; |
3754 } | |
3755 | |
3756 return pedantic_non_lvalue_loc (loc, t); | |
3757 | |
3758 pedantic_omit_one_operand_exit: | |
3759 protected_set_expr_location (t, loc); | |
3760 return t; | |
3593 } | 3761 } |
3594 | 3762 |
3595 /* Return a tree for the case when the result of an expression is RESULT | 3763 /* Return a tree for the case when the result of an expression is RESULT |
3596 converted to TYPE and OMITTED1 and OMITTED2 were previously operands | 3764 converted to TYPE and OMITTED1 and OMITTED2 were previously operands |
3597 of the expression but are now not needed. | 3765 of the expression but are now not needed. |
3600 If both OMITTED1 and OMITTED2 have side effects, OMITTED1 is | 3768 If both OMITTED1 and OMITTED2 have side effects, OMITTED1 is |
3601 evaluated before OMITTED2. Otherwise, if neither has side effects, | 3769 evaluated before OMITTED2. Otherwise, if neither has side effects, |
3602 just do the conversion of RESULT to TYPE. */ | 3770 just do the conversion of RESULT to TYPE. */ |
3603 | 3771 |
3604 tree | 3772 tree |
3605 omit_two_operands (tree type, tree result, tree omitted1, tree omitted2) | 3773 omit_two_operands_loc (location_t loc, tree type, tree result, |
3606 { | 3774 tree omitted1, tree omitted2) |
3607 tree t = fold_convert (type, result); | 3775 { |
3776 tree t = fold_convert_loc (loc, type, result); | |
3608 | 3777 |
3609 if (TREE_SIDE_EFFECTS (omitted2)) | 3778 if (TREE_SIDE_EFFECTS (omitted2)) |
3610 t = build2 (COMPOUND_EXPR, type, omitted2, t); | 3779 { |
3780 t = build2 (COMPOUND_EXPR, type, omitted2, t); | |
3781 SET_EXPR_LOCATION (t, loc); | |
3782 } | |
3611 if (TREE_SIDE_EFFECTS (omitted1)) | 3783 if (TREE_SIDE_EFFECTS (omitted1)) |
3612 t = build2 (COMPOUND_EXPR, type, omitted1, t); | 3784 { |
3613 | 3785 t = build2 (COMPOUND_EXPR, type, omitted1, t); |
3614 return TREE_CODE (t) != COMPOUND_EXPR ? non_lvalue (t) : t; | 3786 SET_EXPR_LOCATION (t, loc); |
3787 } | |
3788 | |
3789 return TREE_CODE (t) != COMPOUND_EXPR ? non_lvalue_loc (loc, t) : t; | |
3615 } | 3790 } |
3616 | 3791 |
3617 | 3792 |
3618 /* Return a simplified tree node for the truth-negation of ARG. This | 3793 /* Return a simplified tree node for the truth-negation of ARG. This |
3619 never alters ARG itself. We assume that ARG is an operation that | 3794 never alters ARG itself. We assume that ARG is an operation that |
3621 | 3796 |
3622 FIXME: one would think we would fold the result, but it causes | 3797 FIXME: one would think we would fold the result, but it causes |
3623 problems with the dominator optimizer. */ | 3798 problems with the dominator optimizer. */ |
3624 | 3799 |
3625 tree | 3800 tree |
3626 fold_truth_not_expr (tree arg) | 3801 fold_truth_not_expr (location_t loc, tree arg) |
3627 { | 3802 { |
3628 tree type = TREE_TYPE (arg); | 3803 tree t, type = TREE_TYPE (arg); |
3629 enum tree_code code = TREE_CODE (arg); | 3804 enum tree_code code = TREE_CODE (arg); |
3805 location_t loc1, loc2; | |
3630 | 3806 |
3631 /* If this is a comparison, we can simply invert it, except for | 3807 /* If this is a comparison, we can simply invert it, except for |
3632 floating-point non-equality comparisons, in which case we just | 3808 floating-point non-equality comparisons, in which case we just |
3633 enclose a TRUTH_NOT_EXPR around what we have. */ | 3809 enclose a TRUTH_NOT_EXPR around what we have. */ |
3634 | 3810 |
3638 if (FLOAT_TYPE_P (op_type) | 3814 if (FLOAT_TYPE_P (op_type) |
3639 && flag_trapping_math | 3815 && flag_trapping_math |
3640 && code != ORDERED_EXPR && code != UNORDERED_EXPR | 3816 && code != ORDERED_EXPR && code != UNORDERED_EXPR |
3641 && code != NE_EXPR && code != EQ_EXPR) | 3817 && code != NE_EXPR && code != EQ_EXPR) |
3642 return NULL_TREE; | 3818 return NULL_TREE; |
3643 else | 3819 |
3644 { | 3820 code = invert_tree_comparison (code, HONOR_NANS (TYPE_MODE (op_type))); |
3645 code = invert_tree_comparison (code, | 3821 if (code == ERROR_MARK) |
3646 HONOR_NANS (TYPE_MODE (op_type))); | 3822 return NULL_TREE; |
3647 if (code == ERROR_MARK) | 3823 |
3648 return NULL_TREE; | 3824 t = build2 (code, type, TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1)); |
3649 else | 3825 SET_EXPR_LOCATION (t, loc); |
3650 return build2 (code, type, | 3826 return t; |
3651 TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1)); | |
3652 } | |
3653 } | 3827 } |
3654 | 3828 |
3655 switch (code) | 3829 switch (code) |
3656 { | 3830 { |
3657 case INTEGER_CST: | 3831 case INTEGER_CST: |
3658 return constant_boolean_node (integer_zerop (arg), type); | 3832 return constant_boolean_node (integer_zerop (arg), type); |
3659 | 3833 |
3660 case TRUTH_AND_EXPR: | 3834 case TRUTH_AND_EXPR: |
3661 return build2 (TRUTH_OR_EXPR, type, | 3835 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); |
3662 invert_truthvalue (TREE_OPERAND (arg, 0)), | 3836 loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); |
3663 invert_truthvalue (TREE_OPERAND (arg, 1))); | 3837 if (loc1 == UNKNOWN_LOCATION) |
3838 loc1 = loc; | |
3839 if (loc2 == UNKNOWN_LOCATION) | |
3840 loc2 = loc; | |
3841 t = build2 (TRUTH_OR_EXPR, type, | |
3842 invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)), | |
3843 invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1))); | |
3844 break; | |
3664 | 3845 |
3665 case TRUTH_OR_EXPR: | 3846 case TRUTH_OR_EXPR: |
3666 return build2 (TRUTH_AND_EXPR, type, | 3847 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); |
3667 invert_truthvalue (TREE_OPERAND (arg, 0)), | 3848 loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); |
3668 invert_truthvalue (TREE_OPERAND (arg, 1))); | 3849 if (loc1 == UNKNOWN_LOCATION) |
3850 loc1 = loc; | |
3851 if (loc2 == UNKNOWN_LOCATION) | |
3852 loc2 = loc; | |
3853 t = build2 (TRUTH_AND_EXPR, type, | |
3854 invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)), | |
3855 invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1))); | |
3856 break; | |
3669 | 3857 |
3670 case TRUTH_XOR_EXPR: | 3858 case TRUTH_XOR_EXPR: |
3671 /* Here we can invert either operand. We invert the first operand | 3859 /* Here we can invert either operand. We invert the first operand |
3672 unless the second operand is a TRUTH_NOT_EXPR in which case our | 3860 unless the second operand is a TRUTH_NOT_EXPR in which case our |
3673 result is the XOR of the first operand with the inside of the | 3861 result is the XOR of the first operand with the inside of the |
3674 negation of the second operand. */ | 3862 negation of the second operand. */ |
3675 | 3863 |
3676 if (TREE_CODE (TREE_OPERAND (arg, 1)) == TRUTH_NOT_EXPR) | 3864 if (TREE_CODE (TREE_OPERAND (arg, 1)) == TRUTH_NOT_EXPR) |
3677 return build2 (TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0), | 3865 t = build2 (TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0), |
3678 TREE_OPERAND (TREE_OPERAND (arg, 1), 0)); | 3866 TREE_OPERAND (TREE_OPERAND (arg, 1), 0)); |
3679 else | 3867 else |
3680 return build2 (TRUTH_XOR_EXPR, type, | 3868 t = build2 (TRUTH_XOR_EXPR, type, |
3681 invert_truthvalue (TREE_OPERAND (arg, 0)), | 3869 invert_truthvalue_loc (loc, TREE_OPERAND (arg, 0)), |
3682 TREE_OPERAND (arg, 1)); | 3870 TREE_OPERAND (arg, 1)); |
3871 break; | |
3683 | 3872 |
3684 case TRUTH_ANDIF_EXPR: | 3873 case TRUTH_ANDIF_EXPR: |
3685 return build2 (TRUTH_ORIF_EXPR, type, | 3874 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); |
3686 invert_truthvalue (TREE_OPERAND (arg, 0)), | 3875 loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); |
3687 invert_truthvalue (TREE_OPERAND (arg, 1))); | 3876 if (loc1 == UNKNOWN_LOCATION) |
3877 loc1 = loc; | |
3878 if (loc2 == UNKNOWN_LOCATION) | |
3879 loc2 = loc; | |
3880 t = build2 (TRUTH_ORIF_EXPR, type, | |
3881 invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)), | |
3882 invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1))); | |
3883 break; | |
3688 | 3884 |
3689 case TRUTH_ORIF_EXPR: | 3885 case TRUTH_ORIF_EXPR: |
3690 return build2 (TRUTH_ANDIF_EXPR, type, | 3886 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); |
3691 invert_truthvalue (TREE_OPERAND (arg, 0)), | 3887 loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); |
3692 invert_truthvalue (TREE_OPERAND (arg, 1))); | 3888 if (loc1 == UNKNOWN_LOCATION) |
3889 loc1 = loc; | |
3890 if (loc2 == UNKNOWN_LOCATION) | |
3891 loc2 = loc; | |
3892 t = build2 (TRUTH_ANDIF_EXPR, type, | |
3893 invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)), | |
3894 invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1))); | |
3895 break; | |
3693 | 3896 |
3694 case TRUTH_NOT_EXPR: | 3897 case TRUTH_NOT_EXPR: |
3695 return TREE_OPERAND (arg, 0); | 3898 return TREE_OPERAND (arg, 0); |
3696 | 3899 |
3697 case COND_EXPR: | 3900 case COND_EXPR: |
3698 { | 3901 { |
3699 tree arg1 = TREE_OPERAND (arg, 1); | 3902 tree arg1 = TREE_OPERAND (arg, 1); |
3700 tree arg2 = TREE_OPERAND (arg, 2); | 3903 tree arg2 = TREE_OPERAND (arg, 2); |
3904 | |
3905 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); | |
3906 loc2 = EXPR_LOCATION (TREE_OPERAND (arg, 2)); | |
3907 if (loc1 == UNKNOWN_LOCATION) | |
3908 loc1 = loc; | |
3909 if (loc2 == UNKNOWN_LOCATION) | |
3910 loc2 = loc; | |
3911 | |
3701 /* A COND_EXPR may have a throw as one operand, which | 3912 /* A COND_EXPR may have a throw as one operand, which |
3702 then has void type. Just leave void operands | 3913 then has void type. Just leave void operands |
3703 as they are. */ | 3914 as they are. */ |
3704 return build3 (COND_EXPR, type, TREE_OPERAND (arg, 0), | 3915 t = build3 (COND_EXPR, type, TREE_OPERAND (arg, 0), |
3705 VOID_TYPE_P (TREE_TYPE (arg1)) | 3916 VOID_TYPE_P (TREE_TYPE (arg1)) |
3706 ? arg1 : invert_truthvalue (arg1), | 3917 ? arg1 : invert_truthvalue_loc (loc1, arg1), |
3707 VOID_TYPE_P (TREE_TYPE (arg2)) | 3918 VOID_TYPE_P (TREE_TYPE (arg2)) |
3708 ? arg2 : invert_truthvalue (arg2)); | 3919 ? arg2 : invert_truthvalue_loc (loc2, arg2)); |
3920 break; | |
3709 } | 3921 } |
3710 | 3922 |
3711 case COMPOUND_EXPR: | 3923 case COMPOUND_EXPR: |
3712 return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg, 0), | 3924 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 1)); |
3713 invert_truthvalue (TREE_OPERAND (arg, 1))); | 3925 if (loc1 == UNKNOWN_LOCATION) |
3926 loc1 = loc; | |
3927 t = build2 (COMPOUND_EXPR, type, | |
3928 TREE_OPERAND (arg, 0), | |
3929 invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 1))); | |
3930 break; | |
3714 | 3931 |
3715 case NON_LVALUE_EXPR: | 3932 case NON_LVALUE_EXPR: |
3716 return invert_truthvalue (TREE_OPERAND (arg, 0)); | 3933 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); |
3717 | 3934 if (loc1 == UNKNOWN_LOCATION) |
3718 case NOP_EXPR: | 3935 loc1 = loc; |
3936 return invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)); | |
3937 | |
3938 CASE_CONVERT: | |
3719 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE) | 3939 if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE) |
3720 return build1 (TRUTH_NOT_EXPR, type, arg); | 3940 { |
3721 | 3941 t = build1 (TRUTH_NOT_EXPR, type, arg); |
3722 case CONVERT_EXPR: | 3942 break; |
3943 } | |
3944 | |
3945 /* ... fall through ... */ | |
3946 | |
3723 case FLOAT_EXPR: | 3947 case FLOAT_EXPR: |
3724 return build1 (TREE_CODE (arg), type, | 3948 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); |
3725 invert_truthvalue (TREE_OPERAND (arg, 0))); | 3949 if (loc1 == UNKNOWN_LOCATION) |
3950 loc1 = loc; | |
3951 t = build1 (TREE_CODE (arg), type, | |
3952 invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0))); | |
3953 break; | |
3726 | 3954 |
3727 case BIT_AND_EXPR: | 3955 case BIT_AND_EXPR: |
3728 if (!integer_onep (TREE_OPERAND (arg, 1))) | 3956 if (!integer_onep (TREE_OPERAND (arg, 1))) |
3729 break; | 3957 return NULL_TREE; |
3730 return build2 (EQ_EXPR, type, arg, | 3958 t = build2 (EQ_EXPR, type, arg, build_int_cst (type, 0)); |
3731 build_int_cst (type, 0)); | 3959 break; |
3732 | 3960 |
3733 case SAVE_EXPR: | 3961 case SAVE_EXPR: |
3734 return build1 (TRUTH_NOT_EXPR, type, arg); | 3962 t = build1 (TRUTH_NOT_EXPR, type, arg); |
3963 break; | |
3735 | 3964 |
3736 case CLEANUP_POINT_EXPR: | 3965 case CLEANUP_POINT_EXPR: |
3737 return build1 (CLEANUP_POINT_EXPR, type, | 3966 loc1 = EXPR_LOCATION (TREE_OPERAND (arg, 0)); |
3738 invert_truthvalue (TREE_OPERAND (arg, 0))); | 3967 if (loc1 == UNKNOWN_LOCATION) |
3968 loc1 = loc; | |
3969 t = build1 (CLEANUP_POINT_EXPR, type, | |
3970 invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0))); | |
3971 break; | |
3739 | 3972 |
3740 default: | 3973 default: |
3974 t = NULL_TREE; | |
3741 break; | 3975 break; |
3742 } | 3976 } |
3743 | 3977 |
3744 return NULL_TREE; | 3978 if (t) |
3979 SET_EXPR_LOCATION (t, loc); | |
3980 | |
3981 return t; | |
3745 } | 3982 } |
3746 | 3983 |
3747 /* Return a simplified tree node for the truth-negation of ARG. This | 3984 /* Return a simplified tree node for the truth-negation of ARG. This |
3748 never alters ARG itself. We assume that ARG is an operation that | 3985 never alters ARG itself. We assume that ARG is an operation that |
3749 returns a truth value (0 or 1). | 3986 returns a truth value (0 or 1). |
3750 | 3987 |
3751 FIXME: one would think we would fold the result, but it causes | 3988 FIXME: one would think we would fold the result, but it causes |
3752 problems with the dominator optimizer. */ | 3989 problems with the dominator optimizer. */ |
3753 | 3990 |
3754 tree | 3991 tree |
3755 invert_truthvalue (tree arg) | 3992 invert_truthvalue_loc (location_t loc, tree arg) |
3756 { | 3993 { |
3757 tree tem; | 3994 tree tem; |
3758 | 3995 |
3759 if (TREE_CODE (arg) == ERROR_MARK) | 3996 if (TREE_CODE (arg) == ERROR_MARK) |
3760 return arg; | 3997 return arg; |
3761 | 3998 |
3762 tem = fold_truth_not_expr (arg); | 3999 tem = fold_truth_not_expr (loc, arg); |
3763 if (!tem) | 4000 if (!tem) |
3764 tem = build1 (TRUTH_NOT_EXPR, TREE_TYPE (arg), arg); | 4001 { |
4002 tem = build1 (TRUTH_NOT_EXPR, TREE_TYPE (arg), arg); | |
4003 SET_EXPR_LOCATION (tem, loc); | |
4004 } | |
3765 | 4005 |
3766 return tem; | 4006 return tem; |
3767 } | 4007 } |
3768 | 4008 |
3769 /* Given a bit-wise operation CODE applied to ARG0 and ARG1, see if both | 4009 /* Given a bit-wise operation CODE applied to ARG0 and ARG1, see if both |
3774 Further simplification will occur if B and C are constants. | 4014 Further simplification will occur if B and C are constants. |
3775 | 4015 |
3776 If this optimization cannot be done, 0 will be returned. */ | 4016 If this optimization cannot be done, 0 will be returned. */ |
3777 | 4017 |
3778 static tree | 4018 static tree |
3779 distribute_bit_expr (enum tree_code code, tree type, tree arg0, tree arg1) | 4019 distribute_bit_expr (location_t loc, enum tree_code code, tree type, |
4020 tree arg0, tree arg1) | |
3780 { | 4021 { |
3781 tree common; | 4022 tree common; |
3782 tree left, right; | 4023 tree left, right; |
3783 | 4024 |
3784 if (TREE_CODE (arg0) != TREE_CODE (arg1) | 4025 if (TREE_CODE (arg0) != TREE_CODE (arg1) |
3812 right = TREE_OPERAND (arg1, 0); | 4053 right = TREE_OPERAND (arg1, 0); |
3813 } | 4054 } |
3814 else | 4055 else |
3815 return 0; | 4056 return 0; |
3816 | 4057 |
3817 common = fold_convert (type, common); | 4058 common = fold_convert_loc (loc, type, common); |
3818 left = fold_convert (type, left); | 4059 left = fold_convert_loc (loc, type, left); |
3819 right = fold_convert (type, right); | 4060 right = fold_convert_loc (loc, type, right); |
3820 return fold_build2 (TREE_CODE (arg0), type, common, | 4061 return fold_build2_loc (loc, TREE_CODE (arg0), type, common, |
3821 fold_build2 (code, type, left, right)); | 4062 fold_build2_loc (loc, code, type, left, right)); |
3822 } | 4063 } |
3823 | 4064 |
3824 /* Knowing that ARG0 and ARG1 are both RDIV_EXPRs, simplify a binary operation | 4065 /* Knowing that ARG0 and ARG1 are both RDIV_EXPRs, simplify a binary operation |
3825 with code CODE. This optimization is unsafe. */ | 4066 with code CODE. This optimization is unsafe. */ |
3826 static tree | 4067 static tree |
3827 distribute_real_division (enum tree_code code, tree type, tree arg0, tree arg1) | 4068 distribute_real_division (location_t loc, enum tree_code code, tree type, |
4069 tree arg0, tree arg1) | |
3828 { | 4070 { |
3829 bool mul0 = TREE_CODE (arg0) == MULT_EXPR; | 4071 bool mul0 = TREE_CODE (arg0) == MULT_EXPR; |
3830 bool mul1 = TREE_CODE (arg1) == MULT_EXPR; | 4072 bool mul1 = TREE_CODE (arg1) == MULT_EXPR; |
3831 | 4073 |
3832 /* (A / C) +- (B / C) -> (A +- B) / C. */ | 4074 /* (A / C) +- (B / C) -> (A +- B) / C. */ |
3833 if (mul0 == mul1 | 4075 if (mul0 == mul1 |
3834 && operand_equal_p (TREE_OPERAND (arg0, 1), | 4076 && operand_equal_p (TREE_OPERAND (arg0, 1), |
3835 TREE_OPERAND (arg1, 1), 0)) | 4077 TREE_OPERAND (arg1, 1), 0)) |
3836 return fold_build2 (mul0 ? MULT_EXPR : RDIV_EXPR, type, | 4078 return fold_build2_loc (loc, mul0 ? MULT_EXPR : RDIV_EXPR, type, |
3837 fold_build2 (code, type, | 4079 fold_build2_loc (loc, code, type, |
3838 TREE_OPERAND (arg0, 0), | 4080 TREE_OPERAND (arg0, 0), |
3839 TREE_OPERAND (arg1, 0)), | 4081 TREE_OPERAND (arg1, 0)), |
3840 TREE_OPERAND (arg0, 1)); | 4082 TREE_OPERAND (arg0, 1)); |
3841 | 4083 |
3842 /* (A / C1) +- (A / C2) -> A * (1 / C1 +- 1 / C2). */ | 4084 /* (A / C1) +- (A / C2) -> A * (1 / C1 +- 1 / C2). */ |
3851 if (!mul0) | 4093 if (!mul0) |
3852 real_arithmetic (&r0, RDIV_EXPR, &dconst1, &r0); | 4094 real_arithmetic (&r0, RDIV_EXPR, &dconst1, &r0); |
3853 if (!mul1) | 4095 if (!mul1) |
3854 real_arithmetic (&r1, RDIV_EXPR, &dconst1, &r1); | 4096 real_arithmetic (&r1, RDIV_EXPR, &dconst1, &r1); |
3855 real_arithmetic (&r0, code, &r0, &r1); | 4097 real_arithmetic (&r0, code, &r0, &r1); |
3856 return fold_build2 (MULT_EXPR, type, | 4098 return fold_build2_loc (loc, MULT_EXPR, type, |
3857 TREE_OPERAND (arg0, 0), | 4099 TREE_OPERAND (arg0, 0), |
3858 build_real (type, r0)); | 4100 build_real (type, r0)); |
3859 } | 4101 } |
3860 | 4102 |
3861 return NULL_TREE; | 4103 return NULL_TREE; |
3863 | 4105 |
3864 /* Return a BIT_FIELD_REF of type TYPE to refer to BITSIZE bits of INNER | 4106 /* Return a BIT_FIELD_REF of type TYPE to refer to BITSIZE bits of INNER |
3865 starting at BITPOS. The field is unsigned if UNSIGNEDP is nonzero. */ | 4107 starting at BITPOS. The field is unsigned if UNSIGNEDP is nonzero. */ |
3866 | 4108 |
3867 static tree | 4109 static tree |
3868 make_bit_field_ref (tree inner, tree type, HOST_WIDE_INT bitsize, | 4110 make_bit_field_ref (location_t loc, tree inner, tree type, |
3869 HOST_WIDE_INT bitpos, int unsignedp) | 4111 HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos, int unsignedp) |
3870 { | 4112 { |
3871 tree result, bftype; | 4113 tree result, bftype; |
3872 | 4114 |
3873 if (bitpos == 0) | 4115 if (bitpos == 0) |
3874 { | 4116 { |
3875 tree size = TYPE_SIZE (TREE_TYPE (inner)); | 4117 tree size = TYPE_SIZE (TREE_TYPE (inner)); |
3876 if ((INTEGRAL_TYPE_P (TREE_TYPE (inner)) | 4118 if ((INTEGRAL_TYPE_P (TREE_TYPE (inner)) |
3877 || POINTER_TYPE_P (TREE_TYPE (inner))) | 4119 || POINTER_TYPE_P (TREE_TYPE (inner))) |
3878 && host_integerp (size, 0) | 4120 && host_integerp (size, 0) |
3879 && tree_low_cst (size, 0) == bitsize) | 4121 && tree_low_cst (size, 0) == bitsize) |
3880 return fold_convert (type, inner); | 4122 return fold_convert_loc (loc, type, inner); |
3881 } | 4123 } |
3882 | 4124 |
3883 bftype = type; | 4125 bftype = type; |
3884 if (TYPE_PRECISION (bftype) != bitsize | 4126 if (TYPE_PRECISION (bftype) != bitsize |
3885 || TYPE_UNSIGNED (bftype) == !unsignedp) | 4127 || TYPE_UNSIGNED (bftype) == !unsignedp) |
3886 bftype = build_nonstandard_integer_type (bitsize, 0); | 4128 bftype = build_nonstandard_integer_type (bitsize, 0); |
3887 | 4129 |
3888 result = build3 (BIT_FIELD_REF, bftype, inner, | 4130 result = build3 (BIT_FIELD_REF, bftype, inner, |
3889 size_int (bitsize), bitsize_int (bitpos)); | 4131 size_int (bitsize), bitsize_int (bitpos)); |
4132 SET_EXPR_LOCATION (result, loc); | |
3890 | 4133 |
3891 if (bftype != type) | 4134 if (bftype != type) |
3892 result = fold_convert (type, result); | 4135 result = fold_convert_loc (loc, type, result); |
3893 | 4136 |
3894 return result; | 4137 return result; |
3895 } | 4138 } |
3896 | 4139 |
3897 /* Optimize a bit-field compare. | 4140 /* Optimize a bit-field compare. |
3913 | 4156 |
3914 If the optimization described above can be done, we return the resulting | 4157 If the optimization described above can be done, we return the resulting |
3915 tree. Otherwise we return zero. */ | 4158 tree. Otherwise we return zero. */ |
3916 | 4159 |
3917 static tree | 4160 static tree |
3918 optimize_bit_field_compare (enum tree_code code, tree compare_type, | 4161 optimize_bit_field_compare (location_t loc, enum tree_code code, |
3919 tree lhs, tree rhs) | 4162 tree compare_type, tree lhs, tree rhs) |
3920 { | 4163 { |
3921 HOST_WIDE_INT lbitpos, lbitsize, rbitpos, rbitsize, nbitpos, nbitsize; | 4164 HOST_WIDE_INT lbitpos, lbitsize, rbitpos, rbitsize, nbitpos, nbitsize; |
3922 tree type = TREE_TYPE (lhs); | 4165 tree type = TREE_TYPE (lhs); |
3923 tree signed_type, unsigned_type; | 4166 tree signed_type, unsigned_type; |
3924 int const_p = TREE_CODE (rhs) == INTEGER_CST; | 4167 int const_p = TREE_CODE (rhs) == INTEGER_CST; |
3987 size_int (nbitsize - lbitsize - lbitpos), 0); | 4230 size_int (nbitsize - lbitsize - lbitpos), 0); |
3988 | 4231 |
3989 if (! const_p) | 4232 if (! const_p) |
3990 /* If not comparing with constant, just rework the comparison | 4233 /* If not comparing with constant, just rework the comparison |
3991 and return. */ | 4234 and return. */ |
3992 return fold_build2 (code, compare_type, | 4235 return fold_build2_loc (loc, code, compare_type, |
3993 fold_build2 (BIT_AND_EXPR, unsigned_type, | 4236 fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, |
3994 make_bit_field_ref (linner, | 4237 make_bit_field_ref (loc, linner, |
3995 unsigned_type, | 4238 unsigned_type, |
3996 nbitsize, nbitpos, | 4239 nbitsize, nbitpos, |
3997 1), | 4240 1), |
3998 mask), | 4241 mask), |
3999 fold_build2 (BIT_AND_EXPR, unsigned_type, | 4242 fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, |
4000 make_bit_field_ref (rinner, | 4243 make_bit_field_ref (loc, rinner, |
4001 unsigned_type, | 4244 unsigned_type, |
4002 nbitsize, nbitpos, | 4245 nbitsize, nbitpos, |
4003 1), | 4246 1), |
4004 mask)); | 4247 mask)); |
4005 | 4248 |
4013 the sign bit. */ | 4256 the sign bit. */ |
4014 | 4257 |
4015 if (lunsignedp) | 4258 if (lunsignedp) |
4016 { | 4259 { |
4017 if (! integer_zerop (const_binop (RSHIFT_EXPR, | 4260 if (! integer_zerop (const_binop (RSHIFT_EXPR, |
4018 fold_convert (unsigned_type, rhs), | 4261 fold_convert_loc (loc, |
4262 unsigned_type, rhs), | |
4019 size_int (lbitsize), 0))) | 4263 size_int (lbitsize), 0))) |
4020 { | 4264 { |
4021 warning (0, "comparison is always %d due to width of bit-field", | 4265 warning (0, "comparison is always %d due to width of bit-field", |
4022 code == NE_EXPR); | 4266 code == NE_EXPR); |
4023 return constant_boolean_node (code == NE_EXPR, compare_type); | 4267 return constant_boolean_node (code == NE_EXPR, compare_type); |
4024 } | 4268 } |
4025 } | 4269 } |
4026 else | 4270 else |
4027 { | 4271 { |
4028 tree tem = const_binop (RSHIFT_EXPR, fold_convert (signed_type, rhs), | 4272 tree tem = const_binop (RSHIFT_EXPR, |
4273 fold_convert_loc (loc, signed_type, rhs), | |
4029 size_int (lbitsize - 1), 0); | 4274 size_int (lbitsize - 1), 0); |
4030 if (! integer_zerop (tem) && ! integer_all_onesp (tem)) | 4275 if (! integer_zerop (tem) && ! integer_all_onesp (tem)) |
4031 { | 4276 { |
4032 warning (0, "comparison is always %d due to width of bit-field", | 4277 warning (0, "comparison is always %d due to width of bit-field", |
4033 code == NE_EXPR); | 4278 code == NE_EXPR); |
4043 } | 4288 } |
4044 | 4289 |
4045 /* Make a new bitfield reference, shift the constant over the | 4290 /* Make a new bitfield reference, shift the constant over the |
4046 appropriate number of bits and mask it with the computed mask | 4291 appropriate number of bits and mask it with the computed mask |
4047 (in case this was a signed field). If we changed it, make a new one. */ | 4292 (in case this was a signed field). If we changed it, make a new one. */ |
4048 lhs = make_bit_field_ref (linner, unsigned_type, nbitsize, nbitpos, 1); | 4293 lhs = make_bit_field_ref (loc, linner, unsigned_type, nbitsize, nbitpos, 1); |
4049 if (lvolatilep) | 4294 if (lvolatilep) |
4050 { | 4295 { |
4051 TREE_SIDE_EFFECTS (lhs) = 1; | 4296 TREE_SIDE_EFFECTS (lhs) = 1; |
4052 TREE_THIS_VOLATILE (lhs) = 1; | 4297 TREE_THIS_VOLATILE (lhs) = 1; |
4053 } | 4298 } |
4054 | 4299 |
4055 rhs = const_binop (BIT_AND_EXPR, | 4300 rhs = const_binop (BIT_AND_EXPR, |
4056 const_binop (LSHIFT_EXPR, | 4301 const_binop (LSHIFT_EXPR, |
4057 fold_convert (unsigned_type, rhs), | 4302 fold_convert_loc (loc, unsigned_type, rhs), |
4058 size_int (lbitpos), 0), | 4303 size_int (lbitpos), 0), |
4059 mask, 0); | 4304 mask, 0); |
4060 | 4305 |
4061 return build2 (code, compare_type, | 4306 lhs = build2 (code, compare_type, |
4062 build2 (BIT_AND_EXPR, unsigned_type, lhs, mask), | 4307 build2 (BIT_AND_EXPR, unsigned_type, lhs, mask), |
4063 rhs); | 4308 rhs); |
4309 SET_EXPR_LOCATION (lhs, loc); | |
4310 return lhs; | |
4064 } | 4311 } |
4065 | 4312 |
4066 /* Subroutine for fold_truthop: decode a field reference. | 4313 /* Subroutine for fold_truthop: decode a field reference. |
4067 | 4314 |
4068 If EXP is a comparison reference, we return the innermost reference. | 4315 If EXP is a comparison reference, we return the innermost reference. |
4085 | 4332 |
4086 Return 0 if this is not a component reference or is one that we can't | 4333 Return 0 if this is not a component reference or is one that we can't |
4087 do anything with. */ | 4334 do anything with. */ |
4088 | 4335 |
4089 static tree | 4336 static tree |
4090 decode_field_reference (tree exp, HOST_WIDE_INT *pbitsize, | 4337 decode_field_reference (location_t loc, tree exp, HOST_WIDE_INT *pbitsize, |
4091 HOST_WIDE_INT *pbitpos, enum machine_mode *pmode, | 4338 HOST_WIDE_INT *pbitpos, enum machine_mode *pmode, |
4092 int *punsignedp, int *pvolatilep, | 4339 int *punsignedp, int *pvolatilep, |
4093 tree *pmask, tree *pand_mask) | 4340 tree *pmask, tree *pand_mask) |
4094 { | 4341 { |
4095 tree outer_type = 0; | 4342 tree outer_type = 0; |
4143 mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0); | 4390 mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0); |
4144 mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0); | 4391 mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0); |
4145 | 4392 |
4146 /* Merge it with the mask we found in the BIT_AND_EXPR, if any. */ | 4393 /* Merge it with the mask we found in the BIT_AND_EXPR, if any. */ |
4147 if (and_mask != 0) | 4394 if (and_mask != 0) |
4148 mask = fold_build2 (BIT_AND_EXPR, unsigned_type, | 4395 mask = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, |
4149 fold_convert (unsigned_type, and_mask), mask); | 4396 fold_convert_loc (loc, unsigned_type, and_mask), mask); |
4150 | 4397 |
4151 *pmask = mask; | 4398 *pmask = mask; |
4152 *pand_mask = and_mask; | 4399 *pand_mask = and_mask; |
4153 return inner; | 4400 return inner; |
4154 } | 4401 } |
4358 will most likely not be returning a useful value and range. Set | 4605 will most likely not be returning a useful value and range. Set |
4359 *STRICT_OVERFLOW_P to true if the return value is only valid | 4606 *STRICT_OVERFLOW_P to true if the return value is only valid |
4360 because signed overflow is undefined; otherwise, do not change | 4607 because signed overflow is undefined; otherwise, do not change |
4361 *STRICT_OVERFLOW_P. */ | 4608 *STRICT_OVERFLOW_P. */ |
4362 | 4609 |
4363 static tree | 4610 tree |
4364 make_range (tree exp, int *pin_p, tree *plow, tree *phigh, | 4611 make_range (tree exp, int *pin_p, tree *plow, tree *phigh, |
4365 bool *strict_overflow_p) | 4612 bool *strict_overflow_p) |
4366 { | 4613 { |
4367 enum tree_code code; | 4614 enum tree_code code; |
4368 tree arg0 = NULL_TREE, arg1 = NULL_TREE; | 4615 tree arg0 = NULL_TREE, arg1 = NULL_TREE; |
4369 tree exp_type = NULL_TREE, arg0_type = NULL_TREE; | 4616 tree exp_type = NULL_TREE, arg0_type = NULL_TREE; |
4370 int in_p, n_in_p; | 4617 int in_p, n_in_p; |
4371 tree low, high, n_low, n_high; | 4618 tree low, high, n_low, n_high; |
4619 location_t loc = EXPR_LOCATION (exp); | |
4372 | 4620 |
4373 /* Start with simply saying "EXP != 0" and then look at the code of EXP | 4621 /* Start with simply saying "EXP != 0" and then look at the code of EXP |
4374 and see if we can refine the range. Some of the cases below may not | 4622 and see if we can refine the range. Some of the cases below may not |
4375 happen, but it doesn't seem worth worrying about this. We "continue" | 4623 happen, but it doesn't seem worth worrying about this. We "continue" |
4376 the outer loop when we've changed something; otherwise we "break" | 4624 the outer loop when we've changed something; otherwise we "break" |
4485 | 4733 |
4486 case BIT_NOT_EXPR: | 4734 case BIT_NOT_EXPR: |
4487 /* ~ X -> -X - 1 */ | 4735 /* ~ X -> -X - 1 */ |
4488 exp = build2 (MINUS_EXPR, exp_type, negate_expr (arg0), | 4736 exp = build2 (MINUS_EXPR, exp_type, negate_expr (arg0), |
4489 build_int_cst (exp_type, 1)); | 4737 build_int_cst (exp_type, 1)); |
4738 SET_EXPR_LOCATION (exp, loc); | |
4490 continue; | 4739 continue; |
4491 | 4740 |
4492 case PLUS_EXPR: case MINUS_EXPR: | 4741 case PLUS_EXPR: case MINUS_EXPR: |
4493 if (TREE_CODE (arg1) != INTEGER_CST) | 4742 if (TREE_CODE (arg1) != INTEGER_CST) |
4494 break; | 4743 break; |
4549 break; | 4798 break; |
4550 | 4799 |
4551 n_low = low, n_high = high; | 4800 n_low = low, n_high = high; |
4552 | 4801 |
4553 if (n_low != 0) | 4802 if (n_low != 0) |
4554 n_low = fold_convert (arg0_type, n_low); | 4803 n_low = fold_convert_loc (loc, arg0_type, n_low); |
4555 | 4804 |
4556 if (n_high != 0) | 4805 if (n_high != 0) |
4557 n_high = fold_convert (arg0_type, n_high); | 4806 n_high = fold_convert_loc (loc, arg0_type, n_high); |
4558 | 4807 |
4559 | 4808 |
4560 /* If we're converting arg0 from an unsigned type, to exp, | 4809 /* If we're converting arg0 from an unsigned type, to exp, |
4561 a signed type, we will be doing the comparison as unsigned. | 4810 a signed type, we will be doing the comparison as unsigned. |
4562 The tests above have already verified that LOW and HIGH | 4811 The tests above have already verified that LOW and HIGH |
4586 high_positive | 4835 high_positive |
4587 = TYPE_MAX_VALUE (equiv_type) ? TYPE_MAX_VALUE (equiv_type) | 4836 = TYPE_MAX_VALUE (equiv_type) ? TYPE_MAX_VALUE (equiv_type) |
4588 : TYPE_MAX_VALUE (arg0_type); | 4837 : TYPE_MAX_VALUE (arg0_type); |
4589 | 4838 |
4590 if (TYPE_PRECISION (exp_type) == TYPE_PRECISION (arg0_type)) | 4839 if (TYPE_PRECISION (exp_type) == TYPE_PRECISION (arg0_type)) |
4591 high_positive = fold_build2 (RSHIFT_EXPR, arg0_type, | 4840 high_positive = fold_build2_loc (loc, RSHIFT_EXPR, arg0_type, |
4592 fold_convert (arg0_type, | 4841 fold_convert_loc (loc, arg0_type, |
4593 high_positive), | 4842 high_positive), |
4594 build_int_cst (arg0_type, 1)); | 4843 build_int_cst (arg0_type, 1)); |
4595 | 4844 |
4596 /* If the low bound is specified, "and" the range with the | 4845 /* If the low bound is specified, "and" the range with the |
4597 range for which the original unsigned value will be | 4846 range for which the original unsigned value will be |
4598 positive. */ | 4847 positive. */ |
4599 if (low != 0) | 4848 if (low != 0) |
4600 { | 4849 { |
4601 if (! merge_ranges (&n_in_p, &n_low, &n_high, | 4850 if (! merge_ranges (&n_in_p, &n_low, &n_high, |
4602 1, n_low, n_high, 1, | 4851 1, n_low, n_high, 1, |
4603 fold_convert (arg0_type, | 4852 fold_convert_loc (loc, arg0_type, |
4604 integer_zero_node), | 4853 integer_zero_node), |
4605 high_positive)) | 4854 high_positive)) |
4606 break; | 4855 break; |
4607 | 4856 |
4608 in_p = (n_in_p == in_p); | 4857 in_p = (n_in_p == in_p); |
4609 } | 4858 } |
4611 { | 4860 { |
4612 /* Otherwise, "or" the range with the range of the input | 4861 /* Otherwise, "or" the range with the range of the input |
4613 that will be interpreted as negative. */ | 4862 that will be interpreted as negative. */ |
4614 if (! merge_ranges (&n_in_p, &n_low, &n_high, | 4863 if (! merge_ranges (&n_in_p, &n_low, &n_high, |
4615 0, n_low, n_high, 1, | 4864 0, n_low, n_high, 1, |
4616 fold_convert (arg0_type, | 4865 fold_convert_loc (loc, arg0_type, |
4617 integer_zero_node), | 4866 integer_zero_node), |
4618 high_positive)) | 4867 high_positive)) |
4619 break; | 4868 break; |
4620 | 4869 |
4621 in_p = (in_p != n_in_p); | 4870 in_p = (in_p != n_in_p); |
4622 } | 4871 } |
4650 | 4899 |
4651 /* Given a range, LOW, HIGH, and IN_P, an expression, EXP, and a result | 4900 /* Given a range, LOW, HIGH, and IN_P, an expression, EXP, and a result |
4652 type, TYPE, return an expression to test if EXP is in (or out of, depending | 4901 type, TYPE, return an expression to test if EXP is in (or out of, depending |
4653 on IN_P) the range. Return 0 if the test couldn't be created. */ | 4902 on IN_P) the range. Return 0 if the test couldn't be created. */ |
4654 | 4903 |
4655 static tree | 4904 tree |
4656 build_range_check (tree type, tree exp, int in_p, tree low, tree high) | 4905 build_range_check (location_t loc, tree type, tree exp, int in_p, |
4657 { | 4906 tree low, tree high) |
4658 tree etype = TREE_TYPE (exp); | 4907 { |
4659 tree value; | 4908 tree etype = TREE_TYPE (exp), value; |
4660 | 4909 |
4661 #ifdef HAVE_canonicalize_funcptr_for_compare | 4910 #ifdef HAVE_canonicalize_funcptr_for_compare |
4662 /* Disable this optimization for function pointer expressions | 4911 /* Disable this optimization for function pointer expressions |
4663 on targets that require function pointer canonicalization. */ | 4912 on targets that require function pointer canonicalization. */ |
4664 if (HAVE_canonicalize_funcptr_for_compare | 4913 if (HAVE_canonicalize_funcptr_for_compare |
4667 return NULL_TREE; | 4916 return NULL_TREE; |
4668 #endif | 4917 #endif |
4669 | 4918 |
4670 if (! in_p) | 4919 if (! in_p) |
4671 { | 4920 { |
4672 value = build_range_check (type, exp, 1, low, high); | 4921 value = build_range_check (loc, type, exp, 1, low, high); |
4673 if (value != 0) | 4922 if (value != 0) |
4674 return invert_truthvalue (value); | 4923 return invert_truthvalue_loc (loc, value); |
4675 | 4924 |
4676 return 0; | 4925 return 0; |
4677 } | 4926 } |
4678 | 4927 |
4679 if (low == 0 && high == 0) | 4928 if (low == 0 && high == 0) |
4680 return build_int_cst (type, 1); | 4929 return build_int_cst (type, 1); |
4681 | 4930 |
4682 if (low == 0) | 4931 if (low == 0) |
4683 return fold_build2 (LE_EXPR, type, exp, | 4932 return fold_build2_loc (loc, LE_EXPR, type, exp, |
4684 fold_convert (etype, high)); | 4933 fold_convert_loc (loc, etype, high)); |
4685 | 4934 |
4686 if (high == 0) | 4935 if (high == 0) |
4687 return fold_build2 (GE_EXPR, type, exp, | 4936 return fold_build2_loc (loc, GE_EXPR, type, exp, |
4688 fold_convert (etype, low)); | 4937 fold_convert_loc (loc, etype, low)); |
4689 | 4938 |
4690 if (operand_equal_p (low, high, 0)) | 4939 if (operand_equal_p (low, high, 0)) |
4691 return fold_build2 (EQ_EXPR, type, exp, | 4940 return fold_build2_loc (loc, EQ_EXPR, type, exp, |
4692 fold_convert (etype, low)); | 4941 fold_convert_loc (loc, etype, low)); |
4693 | 4942 |
4694 if (integer_zerop (low)) | 4943 if (integer_zerop (low)) |
4695 { | 4944 { |
4696 if (! TYPE_UNSIGNED (etype)) | 4945 if (! TYPE_UNSIGNED (etype)) |
4697 { | 4946 { |
4698 etype = unsigned_type_for (etype); | 4947 etype = unsigned_type_for (etype); |
4699 high = fold_convert (etype, high); | 4948 high = fold_convert_loc (loc, etype, high); |
4700 exp = fold_convert (etype, exp); | 4949 exp = fold_convert_loc (loc, etype, exp); |
4701 } | 4950 } |
4702 return build_range_check (type, exp, 1, 0, high); | 4951 return build_range_check (loc, type, exp, 1, 0, high); |
4703 } | 4952 } |
4704 | 4953 |
4705 /* Optimize (c>=1) && (c<=127) into (signed char)c > 0. */ | 4954 /* Optimize (c>=1) && (c<=127) into (signed char)c > 0. */ |
4706 if (integer_onep (low) && TREE_CODE (high) == INTEGER_CST) | 4955 if (integer_onep (low) && TREE_CODE (high) == INTEGER_CST) |
4707 { | 4956 { |
4729 if (TYPE_PRECISION (signed_etype) != TYPE_PRECISION (etype)) | 4978 if (TYPE_PRECISION (signed_etype) != TYPE_PRECISION (etype)) |
4730 etype | 4979 etype |
4731 = build_nonstandard_integer_type (TYPE_PRECISION (etype), 0); | 4980 = build_nonstandard_integer_type (TYPE_PRECISION (etype), 0); |
4732 else | 4981 else |
4733 etype = signed_etype; | 4982 etype = signed_etype; |
4734 exp = fold_convert (etype, exp); | 4983 exp = fold_convert_loc (loc, etype, exp); |
4735 } | 4984 } |
4736 return fold_build2 (GT_EXPR, type, exp, | 4985 return fold_build2_loc (loc, GT_EXPR, type, exp, |
4737 build_int_cst (etype, 0)); | 4986 build_int_cst (etype, 0)); |
4738 } | 4987 } |
4739 } | 4988 } |
4740 | 4989 |
4741 /* Optimize (c>=low) && (c<=high) into (c-low>=0) && (c-low<=high-low). | 4990 /* Optimize (c>=low) && (c<=high) into (c-low>=0) && (c-low<=high-low). |
4742 This requires wrap-around arithmetics for the type of the expression. */ | 4991 This requires wrap-around arithmetics for the type of the expression. |
4743 switch (TREE_CODE (etype)) | 4992 First make sure that arithmetics in this type is valid, then make sure |
4744 { | 4993 that it wraps around. */ |
4745 case INTEGER_TYPE: | 4994 if (TREE_CODE (etype) == ENUMERAL_TYPE || TREE_CODE (etype) == BOOLEAN_TYPE) |
4746 /* There is no requirement that LOW be within the range of ETYPE | 4995 etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype), |
4747 if the latter is a subtype. It must, however, be within the base | 4996 TYPE_UNSIGNED (etype)); |
4748 type of ETYPE. So be sure we do the subtraction in that type. */ | 4997 |
4749 if (TREE_TYPE (etype)) | 4998 if (TREE_CODE (etype) == INTEGER_TYPE && !TYPE_OVERFLOW_WRAPS (etype)) |
4750 etype = TREE_TYPE (etype); | |
4751 break; | |
4752 | |
4753 case ENUMERAL_TYPE: | |
4754 case BOOLEAN_TYPE: | |
4755 etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype), | |
4756 TYPE_UNSIGNED (etype)); | |
4757 break; | |
4758 | |
4759 default: | |
4760 break; | |
4761 } | |
4762 | |
4763 /* If we don't have wrap-around arithmetics upfront, try to force it. */ | |
4764 if (TREE_CODE (etype) == INTEGER_TYPE | |
4765 && !TYPE_OVERFLOW_WRAPS (etype)) | |
4766 { | 4999 { |
4767 tree utype, minv, maxv; | 5000 tree utype, minv, maxv; |
4768 | 5001 |
4769 /* Check if (unsigned) INT_MAX + 1 == (unsigned) INT_MIN | 5002 /* Check if (unsigned) INT_MAX + 1 == (unsigned) INT_MIN |
4770 for the type in question, as we rely on this here. */ | 5003 for the type in question, as we rely on this here. */ |
4771 utype = unsigned_type_for (etype); | 5004 utype = unsigned_type_for (etype); |
4772 maxv = fold_convert (utype, TYPE_MAX_VALUE (etype)); | 5005 maxv = fold_convert_loc (loc, utype, TYPE_MAX_VALUE (etype)); |
4773 maxv = range_binop (PLUS_EXPR, NULL_TREE, maxv, 1, | 5006 maxv = range_binop (PLUS_EXPR, NULL_TREE, maxv, 1, |
4774 integer_one_node, 1); | 5007 integer_one_node, 1); |
4775 minv = fold_convert (utype, TYPE_MIN_VALUE (etype)); | 5008 minv = fold_convert_loc (loc, utype, TYPE_MIN_VALUE (etype)); |
4776 | 5009 |
4777 if (integer_zerop (range_binop (NE_EXPR, integer_type_node, | 5010 if (integer_zerop (range_binop (NE_EXPR, integer_type_node, |
4778 minv, 1, maxv, 1))) | 5011 minv, 1, maxv, 1))) |
4779 etype = utype; | 5012 etype = utype; |
4780 else | 5013 else |
4781 return 0; | 5014 return 0; |
4782 } | 5015 } |
4783 | 5016 |
4784 high = fold_convert (etype, high); | 5017 high = fold_convert_loc (loc, etype, high); |
4785 low = fold_convert (etype, low); | 5018 low = fold_convert_loc (loc, etype, low); |
4786 exp = fold_convert (etype, exp); | 5019 exp = fold_convert_loc (loc, etype, exp); |
4787 | 5020 |
4788 value = const_binop (MINUS_EXPR, high, low, 0); | 5021 value = const_binop (MINUS_EXPR, high, low, 0); |
4789 | 5022 |
4790 | 5023 |
4791 if (POINTER_TYPE_P (etype)) | 5024 if (POINTER_TYPE_P (etype)) |
4792 { | 5025 { |
4793 if (value != 0 && !TREE_OVERFLOW (value)) | 5026 if (value != 0 && !TREE_OVERFLOW (value)) |
4794 { | 5027 { |
4795 low = fold_convert (sizetype, low); | 5028 low = fold_convert_loc (loc, sizetype, low); |
4796 low = fold_build1 (NEGATE_EXPR, sizetype, low); | 5029 low = fold_build1_loc (loc, NEGATE_EXPR, sizetype, low); |
4797 return build_range_check (type, | 5030 return build_range_check (loc, type, |
4798 fold_build2 (POINTER_PLUS_EXPR, etype, exp, low), | 5031 fold_build2_loc (loc, POINTER_PLUS_EXPR, |
5032 etype, exp, low), | |
4799 1, build_int_cst (etype, 0), value); | 5033 1, build_int_cst (etype, 0), value); |
4800 } | 5034 } |
4801 return 0; | 5035 return 0; |
4802 } | 5036 } |
4803 | 5037 |
4804 if (value != 0 && !TREE_OVERFLOW (value)) | 5038 if (value != 0 && !TREE_OVERFLOW (value)) |
4805 return build_range_check (type, | 5039 return build_range_check (loc, type, |
4806 fold_build2 (MINUS_EXPR, etype, exp, low), | 5040 fold_build2_loc (loc, MINUS_EXPR, etype, exp, low), |
4807 1, build_int_cst (etype, 0), value); | 5041 1, build_int_cst (etype, 0), value); |
4808 | 5042 |
4809 return 0; | 5043 return 0; |
4810 } | 5044 } |
4811 | 5045 |
4838 } | 5072 } |
4839 | 5073 |
4840 /* Given two ranges, see if we can merge them into one. Return 1 if we | 5074 /* Given two ranges, see if we can merge them into one. Return 1 if we |
4841 can, 0 if we can't. Set the output range into the specified parameters. */ | 5075 can, 0 if we can't. Set the output range into the specified parameters. */ |
4842 | 5076 |
4843 static int | 5077 bool |
4844 merge_ranges (int *pin_p, tree *plow, tree *phigh, int in0_p, tree low0, | 5078 merge_ranges (int *pin_p, tree *plow, tree *phigh, int in0_p, tree low0, |
4845 tree high0, int in1_p, tree low1, tree high1) | 5079 tree high0, int in1_p, tree low1, tree high1) |
4846 { | 5080 { |
4847 int no_overlap; | 5081 int no_overlap; |
4848 int subset; | 5082 int subset; |
5056 | 5290 |
5057 Return a folded expression whose code is not a COND_EXPR | 5291 Return a folded expression whose code is not a COND_EXPR |
5058 anymore, or NULL_TREE if no folding opportunity is found. */ | 5292 anymore, or NULL_TREE if no folding opportunity is found. */ |
5059 | 5293 |
5060 static tree | 5294 static tree |
5061 fold_cond_expr_with_comparison (tree type, tree arg0, tree arg1, tree arg2) | 5295 fold_cond_expr_with_comparison (location_t loc, tree type, |
5296 tree arg0, tree arg1, tree arg2) | |
5062 { | 5297 { |
5063 enum tree_code comp_code = TREE_CODE (arg0); | 5298 enum tree_code comp_code = TREE_CODE (arg0); |
5064 tree arg00 = TREE_OPERAND (arg0, 0); | 5299 tree arg00 = TREE_OPERAND (arg0, 0); |
5065 tree arg01 = TREE_OPERAND (arg0, 1); | 5300 tree arg01 = TREE_OPERAND (arg0, 1); |
5066 tree arg1_type = TREE_TYPE (arg1); | 5301 tree arg1_type = TREE_TYPE (arg1); |
5104 TREE_OPERAND (arg2, 0), 0)))) | 5339 TREE_OPERAND (arg2, 0), 0)))) |
5105 switch (comp_code) | 5340 switch (comp_code) |
5106 { | 5341 { |
5107 case EQ_EXPR: | 5342 case EQ_EXPR: |
5108 case UNEQ_EXPR: | 5343 case UNEQ_EXPR: |
5109 tem = fold_convert (arg1_type, arg1); | 5344 tem = fold_convert_loc (loc, arg1_type, arg1); |
5110 return pedantic_non_lvalue (fold_convert (type, negate_expr (tem))); | 5345 return pedantic_non_lvalue_loc (loc, |
5346 fold_convert_loc (loc, type, | |
5347 negate_expr (tem))); | |
5111 case NE_EXPR: | 5348 case NE_EXPR: |
5112 case LTGT_EXPR: | 5349 case LTGT_EXPR: |
5113 return pedantic_non_lvalue (fold_convert (type, arg1)); | 5350 return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1)); |
5114 case UNGE_EXPR: | 5351 case UNGE_EXPR: |
5115 case UNGT_EXPR: | 5352 case UNGT_EXPR: |
5116 if (flag_trapping_math) | 5353 if (flag_trapping_math) |
5117 break; | 5354 break; |
5118 /* Fall through. */ | 5355 /* Fall through. */ |
5119 case GE_EXPR: | 5356 case GE_EXPR: |
5120 case GT_EXPR: | 5357 case GT_EXPR: |
5121 if (TYPE_UNSIGNED (TREE_TYPE (arg1))) | 5358 if (TYPE_UNSIGNED (TREE_TYPE (arg1))) |
5122 arg1 = fold_convert (signed_type_for | 5359 arg1 = fold_convert_loc (loc, signed_type_for |
5123 (TREE_TYPE (arg1)), arg1); | 5360 (TREE_TYPE (arg1)), arg1); |
5124 tem = fold_build1 (ABS_EXPR, TREE_TYPE (arg1), arg1); | 5361 tem = fold_build1_loc (loc, ABS_EXPR, TREE_TYPE (arg1), arg1); |
5125 return pedantic_non_lvalue (fold_convert (type, tem)); | 5362 return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, tem)); |
5126 case UNLE_EXPR: | 5363 case UNLE_EXPR: |
5127 case UNLT_EXPR: | 5364 case UNLT_EXPR: |
5128 if (flag_trapping_math) | 5365 if (flag_trapping_math) |
5129 break; | 5366 break; |
5130 case LE_EXPR: | 5367 case LE_EXPR: |
5131 case LT_EXPR: | 5368 case LT_EXPR: |
5132 if (TYPE_UNSIGNED (TREE_TYPE (arg1))) | 5369 if (TYPE_UNSIGNED (TREE_TYPE (arg1))) |
5133 arg1 = fold_convert (signed_type_for | 5370 arg1 = fold_convert_loc (loc, signed_type_for |
5134 (TREE_TYPE (arg1)), arg1); | 5371 (TREE_TYPE (arg1)), arg1); |
5135 tem = fold_build1 (ABS_EXPR, TREE_TYPE (arg1), arg1); | 5372 tem = fold_build1_loc (loc, ABS_EXPR, TREE_TYPE (arg1), arg1); |
5136 return negate_expr (fold_convert (type, tem)); | 5373 return negate_expr (fold_convert_loc (loc, type, tem)); |
5137 default: | 5374 default: |
5138 gcc_assert (TREE_CODE_CLASS (comp_code) == tcc_comparison); | 5375 gcc_assert (TREE_CODE_CLASS (comp_code) == tcc_comparison); |
5139 break; | 5376 break; |
5140 } | 5377 } |
5141 | 5378 |
5146 | 5383 |
5147 if (!HONOR_SIGNED_ZEROS (TYPE_MODE (type)) | 5384 if (!HONOR_SIGNED_ZEROS (TYPE_MODE (type)) |
5148 && integer_zerop (arg01) && integer_zerop (arg2)) | 5385 && integer_zerop (arg01) && integer_zerop (arg2)) |
5149 { | 5386 { |
5150 if (comp_code == NE_EXPR) | 5387 if (comp_code == NE_EXPR) |
5151 return pedantic_non_lvalue (fold_convert (type, arg1)); | 5388 return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1)); |
5152 else if (comp_code == EQ_EXPR) | 5389 else if (comp_code == EQ_EXPR) |
5153 return build_int_cst (type, 0); | 5390 return build_int_cst (type, 0); |
5154 } | 5391 } |
5155 | 5392 |
5156 /* Try some transformations of A op B ? A : B. | 5393 /* Try some transformations of A op B ? A : B. |
5202 } | 5439 } |
5203 | 5440 |
5204 switch (comp_code) | 5441 switch (comp_code) |
5205 { | 5442 { |
5206 case EQ_EXPR: | 5443 case EQ_EXPR: |
5207 return pedantic_non_lvalue (fold_convert (type, arg2)); | 5444 return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg2)); |
5208 case NE_EXPR: | 5445 case NE_EXPR: |
5209 return pedantic_non_lvalue (fold_convert (type, arg1)); | 5446 return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1)); |
5210 case LE_EXPR: | 5447 case LE_EXPR: |
5211 case LT_EXPR: | 5448 case LT_EXPR: |
5212 case UNLE_EXPR: | 5449 case UNLE_EXPR: |
5213 case UNLT_EXPR: | 5450 case UNLT_EXPR: |
5214 /* In C++ a ?: expression can be an lvalue, so put the | 5451 /* In C++ a ?: expression can be an lvalue, so put the |
5215 operand which will be used if they are equal first | 5452 operand which will be used if they are equal first |
5216 so that we can convert this back to the | 5453 so that we can convert this back to the |
5217 corresponding COND_EXPR. */ | 5454 corresponding COND_EXPR. */ |
5218 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))) | 5455 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))) |
5219 { | 5456 { |
5220 comp_op0 = fold_convert (comp_type, comp_op0); | 5457 comp_op0 = fold_convert_loc (loc, comp_type, comp_op0); |
5221 comp_op1 = fold_convert (comp_type, comp_op1); | 5458 comp_op1 = fold_convert_loc (loc, comp_type, comp_op1); |
5222 tem = (comp_code == LE_EXPR || comp_code == UNLE_EXPR) | 5459 tem = (comp_code == LE_EXPR || comp_code == UNLE_EXPR) |
5223 ? fold_build2 (MIN_EXPR, comp_type, comp_op0, comp_op1) | 5460 ? fold_build2_loc (loc, MIN_EXPR, comp_type, comp_op0, comp_op1) |
5224 : fold_build2 (MIN_EXPR, comp_type, comp_op1, comp_op0); | 5461 : fold_build2_loc (loc, MIN_EXPR, comp_type, |
5225 return pedantic_non_lvalue (fold_convert (type, tem)); | 5462 comp_op1, comp_op0); |
5463 return pedantic_non_lvalue_loc (loc, | |
5464 fold_convert_loc (loc, type, tem)); | |
5226 } | 5465 } |
5227 break; | 5466 break; |
5228 case GE_EXPR: | 5467 case GE_EXPR: |
5229 case GT_EXPR: | 5468 case GT_EXPR: |
5230 case UNGE_EXPR: | 5469 case UNGE_EXPR: |
5231 case UNGT_EXPR: | 5470 case UNGT_EXPR: |
5232 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))) | 5471 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))) |
5233 { | 5472 { |
5234 comp_op0 = fold_convert (comp_type, comp_op0); | 5473 comp_op0 = fold_convert_loc (loc, comp_type, comp_op0); |
5235 comp_op1 = fold_convert (comp_type, comp_op1); | 5474 comp_op1 = fold_convert_loc (loc, comp_type, comp_op1); |
5236 tem = (comp_code == GE_EXPR || comp_code == UNGE_EXPR) | 5475 tem = (comp_code == GE_EXPR || comp_code == UNGE_EXPR) |
5237 ? fold_build2 (MAX_EXPR, comp_type, comp_op0, comp_op1) | 5476 ? fold_build2_loc (loc, MAX_EXPR, comp_type, comp_op0, comp_op1) |
5238 : fold_build2 (MAX_EXPR, comp_type, comp_op1, comp_op0); | 5477 : fold_build2_loc (loc, MAX_EXPR, comp_type, |
5239 return pedantic_non_lvalue (fold_convert (type, tem)); | 5478 comp_op1, comp_op0); |
5479 return pedantic_non_lvalue_loc (loc, | |
5480 fold_convert_loc (loc, type, tem)); | |
5240 } | 5481 } |
5241 break; | 5482 break; |
5242 case UNEQ_EXPR: | 5483 case UNEQ_EXPR: |
5243 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))) | 5484 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))) |
5244 return pedantic_non_lvalue (fold_convert (type, arg2)); | 5485 return pedantic_non_lvalue_loc (loc, |
5486 fold_convert_loc (loc, type, arg2)); | |
5245 break; | 5487 break; |
5246 case LTGT_EXPR: | 5488 case LTGT_EXPR: |
5247 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))) | 5489 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))) |
5248 return pedantic_non_lvalue (fold_convert (type, arg1)); | 5490 return pedantic_non_lvalue_loc (loc, |
5491 fold_convert_loc (loc, type, arg1)); | |
5249 break; | 5492 break; |
5250 default: | 5493 default: |
5251 gcc_assert (TREE_CODE_CLASS (comp_code) == tcc_comparison); | 5494 gcc_assert (TREE_CODE_CLASS (comp_code) == tcc_comparison); |
5252 break; | 5495 break; |
5253 } | 5496 } |
5263 && TREE_CODE (arg01) == INTEGER_CST | 5506 && TREE_CODE (arg01) == INTEGER_CST |
5264 && TREE_CODE (arg2) == INTEGER_CST) | 5507 && TREE_CODE (arg2) == INTEGER_CST) |
5265 switch (comp_code) | 5508 switch (comp_code) |
5266 { | 5509 { |
5267 case EQ_EXPR: | 5510 case EQ_EXPR: |
5511 if (TREE_CODE (arg1) == INTEGER_CST) | |
5512 break; | |
5268 /* We can replace A with C1 in this case. */ | 5513 /* We can replace A with C1 in this case. */ |
5269 arg1 = fold_convert (type, arg01); | 5514 arg1 = fold_convert_loc (loc, type, arg01); |
5270 return fold_build3 (COND_EXPR, type, arg0, arg1, arg2); | 5515 return fold_build3_loc (loc, COND_EXPR, type, arg0, arg1, arg2); |
5271 | 5516 |
5272 case LT_EXPR: | 5517 case LT_EXPR: |
5273 /* If C1 is C2 + 1, this is min(A, C2), but use ARG00's type for | 5518 /* If C1 is C2 + 1, this is min(A, C2), but use ARG00's type for |
5274 MIN_EXPR, to preserve the signedness of the comparison. */ | 5519 MIN_EXPR, to preserve the signedness of the comparison. */ |
5275 if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type), | 5520 if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type), |
5277 && operand_equal_p (arg01, | 5522 && operand_equal_p (arg01, |
5278 const_binop (PLUS_EXPR, arg2, | 5523 const_binop (PLUS_EXPR, arg2, |
5279 build_int_cst (type, 1), 0), | 5524 build_int_cst (type, 1), 0), |
5280 OEP_ONLY_CONST)) | 5525 OEP_ONLY_CONST)) |
5281 { | 5526 { |
5282 tem = fold_build2 (MIN_EXPR, TREE_TYPE (arg00), arg00, | 5527 tem = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (arg00), arg00, |
5283 fold_convert (TREE_TYPE (arg00), arg2)); | 5528 fold_convert_loc (loc, TREE_TYPE (arg00), |
5284 return pedantic_non_lvalue (fold_convert (type, tem)); | 5529 arg2)); |
5530 return pedantic_non_lvalue_loc (loc, | |
5531 fold_convert_loc (loc, type, tem)); | |
5285 } | 5532 } |
5286 break; | 5533 break; |
5287 | 5534 |
5288 case LE_EXPR: | 5535 case LE_EXPR: |
5289 /* If C1 is C2 - 1, this is min(A, C2), with the same care | 5536 /* If C1 is C2 - 1, this is min(A, C2), with the same care |
5293 && operand_equal_p (arg01, | 5540 && operand_equal_p (arg01, |
5294 const_binop (MINUS_EXPR, arg2, | 5541 const_binop (MINUS_EXPR, arg2, |
5295 build_int_cst (type, 1), 0), | 5542 build_int_cst (type, 1), 0), |
5296 OEP_ONLY_CONST)) | 5543 OEP_ONLY_CONST)) |
5297 { | 5544 { |
5298 tem = fold_build2 (MIN_EXPR, TREE_TYPE (arg00), arg00, | 5545 tem = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (arg00), arg00, |
5299 fold_convert (TREE_TYPE (arg00), arg2)); | 5546 fold_convert_loc (loc, TREE_TYPE (arg00), |
5300 return pedantic_non_lvalue (fold_convert (type, tem)); | 5547 arg2)); |
5548 return pedantic_non_lvalue_loc (loc, | |
5549 fold_convert_loc (loc, type, tem)); | |
5301 } | 5550 } |
5302 break; | 5551 break; |
5303 | 5552 |
5304 case GT_EXPR: | 5553 case GT_EXPR: |
5305 /* If C1 is C2 - 1, this is max(A, C2), but use ARG00's type for | 5554 /* If C1 is C2 - 1, this is max(A, C2), but use ARG00's type for |
5309 && operand_equal_p (arg01, | 5558 && operand_equal_p (arg01, |
5310 const_binop (MINUS_EXPR, arg2, | 5559 const_binop (MINUS_EXPR, arg2, |
5311 build_int_cst (type, 1), 0), | 5560 build_int_cst (type, 1), 0), |
5312 OEP_ONLY_CONST)) | 5561 OEP_ONLY_CONST)) |
5313 { | 5562 { |
5314 tem = fold_build2 (MAX_EXPR, TREE_TYPE (arg00), arg00, | 5563 tem = fold_build2_loc (loc, MAX_EXPR, TREE_TYPE (arg00), arg00, |
5315 fold_convert (TREE_TYPE (arg00), arg2)); | 5564 fold_convert_loc (loc, TREE_TYPE (arg00), |
5316 return pedantic_non_lvalue (fold_convert (type, tem)); | 5565 arg2)); |
5566 return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, tem)); | |
5317 } | 5567 } |
5318 break; | 5568 break; |
5319 | 5569 |
5320 case GE_EXPR: | 5570 case GE_EXPR: |
5321 /* If C1 is C2 + 1, this is max(A, C2), with the same care as above. */ | 5571 /* If C1 is C2 + 1, this is max(A, C2), with the same care as above. */ |
5324 && operand_equal_p (arg01, | 5574 && operand_equal_p (arg01, |
5325 const_binop (PLUS_EXPR, arg2, | 5575 const_binop (PLUS_EXPR, arg2, |
5326 build_int_cst (type, 1), 0), | 5576 build_int_cst (type, 1), 0), |
5327 OEP_ONLY_CONST)) | 5577 OEP_ONLY_CONST)) |
5328 { | 5578 { |
5329 tem = fold_build2 (MAX_EXPR, TREE_TYPE (arg00), arg00, | 5579 tem = fold_build2_loc (loc, MAX_EXPR, TREE_TYPE (arg00), arg00, |
5330 fold_convert (TREE_TYPE (arg00), arg2)); | 5580 fold_convert_loc (loc, TREE_TYPE (arg00), |
5331 return pedantic_non_lvalue (fold_convert (type, tem)); | 5581 arg2)); |
5582 return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, tem)); | |
5332 } | 5583 } |
5333 break; | 5584 break; |
5334 case NE_EXPR: | 5585 case NE_EXPR: |
5335 break; | 5586 break; |
5336 default: | 5587 default: |
5350 | 5601 |
5351 /* EXP is some logical combination of boolean tests. See if we can | 5602 /* EXP is some logical combination of boolean tests. See if we can |
5352 merge it into some range test. Return the new tree if so. */ | 5603 merge it into some range test. Return the new tree if so. */ |
5353 | 5604 |
5354 static tree | 5605 static tree |
5355 fold_range_test (enum tree_code code, tree type, tree op0, tree op1) | 5606 fold_range_test (location_t loc, enum tree_code code, tree type, |
5607 tree op0, tree op1) | |
5356 { | 5608 { |
5357 int or_op = (code == TRUTH_ORIF_EXPR | 5609 int or_op = (code == TRUTH_ORIF_EXPR |
5358 || code == TRUTH_OR_EXPR); | 5610 || code == TRUTH_OR_EXPR); |
5359 int in0_p, in1_p, in_p; | 5611 int in0_p, in1_p, in_p; |
5360 tree low0, low1, low, high0, high1, high; | 5612 tree low0, low1, low, high0, high1, high; |
5375 ranges is always true or always false, consider it to be the same | 5627 ranges is always true or always false, consider it to be the same |
5376 expression as the other. */ | 5628 expression as the other. */ |
5377 if ((lhs == 0 || rhs == 0 || operand_equal_p (lhs, rhs, 0)) | 5629 if ((lhs == 0 || rhs == 0 || operand_equal_p (lhs, rhs, 0)) |
5378 && merge_ranges (&in_p, &low, &high, in0_p, low0, high0, | 5630 && merge_ranges (&in_p, &low, &high, in0_p, low0, high0, |
5379 in1_p, low1, high1) | 5631 in1_p, low1, high1) |
5380 && 0 != (tem = (build_range_check (type, | 5632 && 0 != (tem = (build_range_check (UNKNOWN_LOCATION, type, |
5381 lhs != 0 ? lhs | 5633 lhs != 0 ? lhs |
5382 : rhs != 0 ? rhs : integer_zero_node, | 5634 : rhs != 0 ? rhs : integer_zero_node, |
5383 in_p, low, high)))) | 5635 in_p, low, high)))) |
5384 { | 5636 { |
5385 if (strict_overflow_p) | 5637 if (strict_overflow_p) |
5386 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); | 5638 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); |
5387 return or_op ? invert_truthvalue (tem) : tem; | 5639 return or_op ? invert_truthvalue_loc (loc, tem) : tem; |
5388 } | 5640 } |
5389 | 5641 |
5390 /* On machines where the branch cost is expensive, if this is a | 5642 /* On machines where the branch cost is expensive, if this is a |
5391 short-circuited branch and the underlying object on both sides | 5643 short-circuited branch and the underlying object on both sides |
5392 is the same, make a non-short-circuit operation. */ | 5644 is the same, make a non-short-circuit operation. */ |
5398 { | 5650 { |
5399 /* If simple enough, just rewrite. Otherwise, make a SAVE_EXPR | 5651 /* If simple enough, just rewrite. Otherwise, make a SAVE_EXPR |
5400 unless we are at top level or LHS contains a PLACEHOLDER_EXPR, in | 5652 unless we are at top level or LHS contains a PLACEHOLDER_EXPR, in |
5401 which cases we can't do this. */ | 5653 which cases we can't do this. */ |
5402 if (simple_operand_p (lhs)) | 5654 if (simple_operand_p (lhs)) |
5403 return build2 (code == TRUTH_ANDIF_EXPR | 5655 { |
5404 ? TRUTH_AND_EXPR : TRUTH_OR_EXPR, | 5656 tem = build2 (code == TRUTH_ANDIF_EXPR |
5405 type, op0, op1); | 5657 ? TRUTH_AND_EXPR : TRUTH_OR_EXPR, |
5658 type, op0, op1); | |
5659 SET_EXPR_LOCATION (tem, loc); | |
5660 return tem; | |
5661 } | |
5406 | 5662 |
5407 else if (lang_hooks.decls.global_bindings_p () == 0 | 5663 else if (lang_hooks.decls.global_bindings_p () == 0 |
5408 && ! CONTAINS_PLACEHOLDER_P (lhs)) | 5664 && ! CONTAINS_PLACEHOLDER_P (lhs)) |
5409 { | 5665 { |
5410 tree common = save_expr (lhs); | 5666 tree common = save_expr (lhs); |
5411 | 5667 |
5412 if (0 != (lhs = build_range_check (type, common, | 5668 if (0 != (lhs = build_range_check (loc, type, common, |
5413 or_op ? ! in0_p : in0_p, | 5669 or_op ? ! in0_p : in0_p, |
5414 low0, high0)) | 5670 low0, high0)) |
5415 && (0 != (rhs = build_range_check (type, common, | 5671 && (0 != (rhs = build_range_check (loc, type, common, |
5416 or_op ? ! in1_p : in1_p, | 5672 or_op ? ! in1_p : in1_p, |
5417 low1, high1)))) | 5673 low1, high1)))) |
5418 { | 5674 { |
5419 if (strict_overflow_p) | 5675 if (strict_overflow_p) |
5420 fold_overflow_warning (warnmsg, | 5676 fold_overflow_warning (warnmsg, |
5421 WARN_STRICT_OVERFLOW_COMPARISON); | 5677 WARN_STRICT_OVERFLOW_COMPARISON); |
5422 return build2 (code == TRUTH_ANDIF_EXPR | 5678 tem = build2 (code == TRUTH_ANDIF_EXPR |
5423 ? TRUTH_AND_EXPR : TRUTH_OR_EXPR, | 5679 ? TRUTH_AND_EXPR : TRUTH_OR_EXPR, |
5424 type, lhs, rhs); | 5680 type, lhs, rhs); |
5681 SET_EXPR_LOCATION (tem, loc); | |
5682 return tem; | |
5425 } | 5683 } |
5426 } | 5684 } |
5427 } | 5685 } |
5428 | 5686 |
5429 return 0; | 5687 return 0; |
5461 | 5719 |
5462 temp = const_binop (LSHIFT_EXPR, temp, size_int (modesize - 1), 0); | 5720 temp = const_binop (LSHIFT_EXPR, temp, size_int (modesize - 1), 0); |
5463 temp = const_binop (RSHIFT_EXPR, temp, size_int (modesize - p - 1), 0); | 5721 temp = const_binop (RSHIFT_EXPR, temp, size_int (modesize - p - 1), 0); |
5464 if (mask != 0) | 5722 if (mask != 0) |
5465 temp = const_binop (BIT_AND_EXPR, temp, | 5723 temp = const_binop (BIT_AND_EXPR, temp, |
5466 fold_convert (TREE_TYPE (c), mask), 0); | 5724 fold_convert (TREE_TYPE (c), mask), |
5725 0); | |
5467 /* If necessary, convert the type back to match the type of C. */ | 5726 /* If necessary, convert the type back to match the type of C. */ |
5468 if (TYPE_UNSIGNED (type)) | 5727 if (TYPE_UNSIGNED (type)) |
5469 temp = fold_convert (type, temp); | 5728 temp = fold_convert (type, temp); |
5470 | 5729 |
5471 return fold_convert (type, const_binop (BIT_XOR_EXPR, c, temp, 0)); | 5730 return fold_convert (type, |
5731 const_binop (BIT_XOR_EXPR, c, temp, 0)); | |
5472 } | 5732 } |
5473 | 5733 |
5474 /* Find ways of folding logical expressions of LHS and RHS: | 5734 /* Find ways of folding logical expressions of LHS and RHS: |
5475 Try to merge two comparisons to the same innermost item. | 5735 Try to merge two comparisons to the same innermost item. |
5476 Look for range tests like "ch >= '0' && ch <= '9'". | 5736 Look for range tests like "ch >= '0' && ch <= '9'". |
5494 two operands. | 5754 two operands. |
5495 | 5755 |
5496 We return the simplified tree or 0 if no optimization is possible. */ | 5756 We return the simplified tree or 0 if no optimization is possible. */ |
5497 | 5757 |
5498 static tree | 5758 static tree |
5499 fold_truthop (enum tree_code code, tree truth_type, tree lhs, tree rhs) | 5759 fold_truthop (location_t loc, enum tree_code code, tree truth_type, |
5760 tree lhs, tree rhs) | |
5500 { | 5761 { |
5501 /* If this is the "or" of two comparisons, we can do something if | 5762 /* If this is the "or" of two comparisons, we can do something if |
5502 the comparisons are NE_EXPR. If this is the "and", we can do something | 5763 the comparisons are NE_EXPR. If this is the "and", we can do something |
5503 if the comparisons are EQ_EXPR. I.e., | 5764 if the comparisons are EQ_EXPR. I.e., |
5504 (a->b == 2 && a->c == 4) can become (a->new == NEW). | 5765 (a->b == 2 && a->c == 4) can become (a->new == NEW). |
5566 { | 5827 { |
5567 tree result; | 5828 tree result; |
5568 if (operand_equal_p (ll_arg, rl_arg, 0) | 5829 if (operand_equal_p (ll_arg, rl_arg, 0) |
5569 && operand_equal_p (lr_arg, rr_arg, 0)) | 5830 && operand_equal_p (lr_arg, rr_arg, 0)) |
5570 { | 5831 { |
5571 result = combine_comparisons (code, lcode, rcode, | 5832 result = combine_comparisons (loc, code, lcode, rcode, |
5572 truth_type, ll_arg, lr_arg); | 5833 truth_type, ll_arg, lr_arg); |
5573 if (result) | 5834 if (result) |
5574 return result; | 5835 return result; |
5575 } | 5836 } |
5576 else if (operand_equal_p (ll_arg, rr_arg, 0) | 5837 else if (operand_equal_p (ll_arg, rr_arg, 0) |
5577 && operand_equal_p (lr_arg, rl_arg, 0)) | 5838 && operand_equal_p (lr_arg, rl_arg, 0)) |
5578 { | 5839 { |
5579 result = combine_comparisons (code, lcode, | 5840 result = combine_comparisons (loc, code, lcode, |
5580 swap_tree_comparison (rcode), | 5841 swap_tree_comparison (rcode), |
5581 truth_type, ll_arg, lr_arg); | 5842 truth_type, ll_arg, lr_arg); |
5582 if (result) | 5843 if (result) |
5583 return result; | 5844 return result; |
5584 } | 5845 } |
5603 if (code == TRUTH_OR_EXPR | 5864 if (code == TRUTH_OR_EXPR |
5604 && lcode == NE_EXPR && integer_zerop (lr_arg) | 5865 && lcode == NE_EXPR && integer_zerop (lr_arg) |
5605 && rcode == NE_EXPR && integer_zerop (rr_arg) | 5866 && rcode == NE_EXPR && integer_zerop (rr_arg) |
5606 && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg) | 5867 && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg) |
5607 && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))) | 5868 && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))) |
5608 return build2 (NE_EXPR, truth_type, | 5869 { |
5609 build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg), | 5870 result = build2 (NE_EXPR, truth_type, |
5610 ll_arg, rl_arg), | 5871 build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg), |
5611 build_int_cst (TREE_TYPE (ll_arg), 0)); | 5872 ll_arg, rl_arg), |
5873 build_int_cst (TREE_TYPE (ll_arg), 0)); | |
5874 goto fold_truthop_exit; | |
5875 } | |
5612 | 5876 |
5613 /* Convert (a == 0) && (b == 0) into (a | b) == 0. */ | 5877 /* Convert (a == 0) && (b == 0) into (a | b) == 0. */ |
5614 if (code == TRUTH_AND_EXPR | 5878 if (code == TRUTH_AND_EXPR |
5615 && lcode == EQ_EXPR && integer_zerop (lr_arg) | 5879 && lcode == EQ_EXPR && integer_zerop (lr_arg) |
5616 && rcode == EQ_EXPR && integer_zerop (rr_arg) | 5880 && rcode == EQ_EXPR && integer_zerop (rr_arg) |
5617 && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg) | 5881 && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg) |
5618 && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))) | 5882 && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))) |
5619 return build2 (EQ_EXPR, truth_type, | 5883 { |
5620 build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg), | 5884 result = build2 (EQ_EXPR, truth_type, |
5621 ll_arg, rl_arg), | 5885 build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg), |
5622 build_int_cst (TREE_TYPE (ll_arg), 0)); | 5886 ll_arg, rl_arg), |
5887 build_int_cst (TREE_TYPE (ll_arg), 0)); | |
5888 goto fold_truthop_exit; | |
5889 } | |
5623 | 5890 |
5624 if (LOGICAL_OP_NON_SHORT_CIRCUIT) | 5891 if (LOGICAL_OP_NON_SHORT_CIRCUIT) |
5625 { | 5892 { |
5626 if (code != orig_code || lhs != orig_lhs || rhs != orig_rhs) | 5893 if (code != orig_code || lhs != orig_lhs || rhs != orig_rhs) |
5627 return build2 (code, truth_type, lhs, rhs); | 5894 { |
5895 result = build2 (code, truth_type, lhs, rhs); | |
5896 goto fold_truthop_exit; | |
5897 } | |
5628 return NULL_TREE; | 5898 return NULL_TREE; |
5629 } | 5899 } |
5630 } | 5900 } |
5631 | 5901 |
5632 /* See if the comparisons can be merged. Then get all the parameters for | 5902 /* See if the comparisons can be merged. Then get all the parameters for |
5635 if ((lcode != EQ_EXPR && lcode != NE_EXPR) | 5905 if ((lcode != EQ_EXPR && lcode != NE_EXPR) |
5636 || (rcode != EQ_EXPR && rcode != NE_EXPR)) | 5906 || (rcode != EQ_EXPR && rcode != NE_EXPR)) |
5637 return 0; | 5907 return 0; |
5638 | 5908 |
5639 volatilep = 0; | 5909 volatilep = 0; |
5640 ll_inner = decode_field_reference (ll_arg, | 5910 ll_inner = decode_field_reference (loc, ll_arg, |
5641 &ll_bitsize, &ll_bitpos, &ll_mode, | 5911 &ll_bitsize, &ll_bitpos, &ll_mode, |
5642 &ll_unsignedp, &volatilep, &ll_mask, | 5912 &ll_unsignedp, &volatilep, &ll_mask, |
5643 &ll_and_mask); | 5913 &ll_and_mask); |
5644 lr_inner = decode_field_reference (lr_arg, | 5914 lr_inner = decode_field_reference (loc, lr_arg, |
5645 &lr_bitsize, &lr_bitpos, &lr_mode, | 5915 &lr_bitsize, &lr_bitpos, &lr_mode, |
5646 &lr_unsignedp, &volatilep, &lr_mask, | 5916 &lr_unsignedp, &volatilep, &lr_mask, |
5647 &lr_and_mask); | 5917 &lr_and_mask); |
5648 rl_inner = decode_field_reference (rl_arg, | 5918 rl_inner = decode_field_reference (loc, rl_arg, |
5649 &rl_bitsize, &rl_bitpos, &rl_mode, | 5919 &rl_bitsize, &rl_bitpos, &rl_mode, |
5650 &rl_unsignedp, &volatilep, &rl_mask, | 5920 &rl_unsignedp, &volatilep, &rl_mask, |
5651 &rl_and_mask); | 5921 &rl_and_mask); |
5652 rr_inner = decode_field_reference (rr_arg, | 5922 rr_inner = decode_field_reference (loc, rr_arg, |
5653 &rr_bitsize, &rr_bitpos, &rr_mode, | 5923 &rr_bitsize, &rr_bitpos, &rr_mode, |
5654 &rr_unsignedp, &volatilep, &rr_mask, | 5924 &rr_unsignedp, &volatilep, &rr_mask, |
5655 &rr_and_mask); | 5925 &rr_and_mask); |
5656 | 5926 |
5657 /* It must be true that the inner operation on the lhs of each | 5927 /* It must be true that the inner operation on the lhs of each |
5722 { | 5992 { |
5723 xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize; | 5993 xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize; |
5724 xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize; | 5994 xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize; |
5725 } | 5995 } |
5726 | 5996 |
5727 ll_mask = const_binop (LSHIFT_EXPR, fold_convert (lntype, ll_mask), | 5997 ll_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, lntype, ll_mask), |
5728 size_int (xll_bitpos), 0); | 5998 size_int (xll_bitpos), 0); |
5729 rl_mask = const_binop (LSHIFT_EXPR, fold_convert (lntype, rl_mask), | 5999 rl_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, lntype, rl_mask), |
5730 size_int (xrl_bitpos), 0); | 6000 size_int (xrl_bitpos), 0); |
5731 | 6001 |
5732 if (l_const) | 6002 if (l_const) |
5733 { | 6003 { |
5734 l_const = fold_convert (lntype, l_const); | 6004 l_const = fold_convert_loc (loc, lntype, l_const); |
5735 l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask); | 6005 l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask); |
5736 l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos), 0); | 6006 l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos), 0); |
5737 if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const, | 6007 if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const, |
5738 fold_build1 (BIT_NOT_EXPR, | 6008 fold_build1_loc (loc, BIT_NOT_EXPR, |
5739 lntype, ll_mask), | 6009 lntype, ll_mask), |
5740 0))) | 6010 0))) |
5741 { | 6011 { |
5742 warning (0, "comparison is always %d", wanted_code == NE_EXPR); | 6012 warning (0, "comparison is always %d", wanted_code == NE_EXPR); |
5743 | 6013 |
5744 return constant_boolean_node (wanted_code == NE_EXPR, truth_type); | 6014 return constant_boolean_node (wanted_code == NE_EXPR, truth_type); |
5745 } | 6015 } |
5746 } | 6016 } |
5747 if (r_const) | 6017 if (r_const) |
5748 { | 6018 { |
5749 r_const = fold_convert (lntype, r_const); | 6019 r_const = fold_convert_loc (loc, lntype, r_const); |
5750 r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask); | 6020 r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask); |
5751 r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos), 0); | 6021 r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos), 0); |
5752 if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const, | 6022 if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const, |
5753 fold_build1 (BIT_NOT_EXPR, | 6023 fold_build1_loc (loc, BIT_NOT_EXPR, |
5754 lntype, rl_mask), | 6024 lntype, rl_mask), |
5755 0))) | 6025 0))) |
5756 { | 6026 { |
5757 warning (0, "comparison is always %d", wanted_code == NE_EXPR); | 6027 warning (0, "comparison is always %d", wanted_code == NE_EXPR); |
5758 | 6028 |
5789 { | 6059 { |
5790 xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize; | 6060 xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize; |
5791 xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize; | 6061 xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize; |
5792 } | 6062 } |
5793 | 6063 |
5794 lr_mask = const_binop (LSHIFT_EXPR, fold_convert (rntype, lr_mask), | 6064 lr_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, |
6065 rntype, lr_mask), | |
5795 size_int (xlr_bitpos), 0); | 6066 size_int (xlr_bitpos), 0); |
5796 rr_mask = const_binop (LSHIFT_EXPR, fold_convert (rntype, rr_mask), | 6067 rr_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, |
6068 rntype, rr_mask), | |
5797 size_int (xrr_bitpos), 0); | 6069 size_int (xrr_bitpos), 0); |
5798 | 6070 |
5799 /* Make a mask that corresponds to both fields being compared. | 6071 /* Make a mask that corresponds to both fields being compared. |
5800 Do this for both items being compared. If the operands are the | 6072 Do this for both items being compared. If the operands are the |
5801 same size and the bits being compared are in the same position | 6073 same size and the bits being compared are in the same position |
5803 results. */ | 6075 results. */ |
5804 ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0); | 6076 ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0); |
5805 lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask, 0); | 6077 lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask, 0); |
5806 if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos) | 6078 if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos) |
5807 { | 6079 { |
5808 lhs = make_bit_field_ref (ll_inner, lntype, lnbitsize, lnbitpos, | 6080 lhs = make_bit_field_ref (loc, ll_inner, lntype, lnbitsize, lnbitpos, |
5809 ll_unsignedp || rl_unsignedp); | 6081 ll_unsignedp || rl_unsignedp); |
5810 if (! all_ones_mask_p (ll_mask, lnbitsize)) | 6082 if (! all_ones_mask_p (ll_mask, lnbitsize)) |
5811 lhs = build2 (BIT_AND_EXPR, lntype, lhs, ll_mask); | 6083 lhs = build2 (BIT_AND_EXPR, lntype, lhs, ll_mask); |
5812 | 6084 |
5813 rhs = make_bit_field_ref (lr_inner, rntype, rnbitsize, rnbitpos, | 6085 rhs = make_bit_field_ref (loc, lr_inner, rntype, rnbitsize, rnbitpos, |
5814 lr_unsignedp || rr_unsignedp); | 6086 lr_unsignedp || rr_unsignedp); |
5815 if (! all_ones_mask_p (lr_mask, rnbitsize)) | 6087 if (! all_ones_mask_p (lr_mask, rnbitsize)) |
5816 rhs = build2 (BIT_AND_EXPR, rntype, rhs, lr_mask); | 6088 rhs = build2 (BIT_AND_EXPR, rntype, rhs, lr_mask); |
5817 | 6089 |
5818 return build2 (wanted_code, truth_type, lhs, rhs); | 6090 result = build2 (wanted_code, truth_type, lhs, rhs); |
6091 goto fold_truthop_exit; | |
5819 } | 6092 } |
5820 | 6093 |
5821 /* There is still another way we can do something: If both pairs of | 6094 /* There is still another way we can do something: If both pairs of |
5822 fields being compared are adjacent, we may be able to make a wider | 6095 fields being compared are adjacent, we may be able to make a wider |
5823 field containing them both. | 6096 field containing them both. |
5830 || (ll_bitpos == rl_bitpos + rl_bitsize | 6103 || (ll_bitpos == rl_bitpos + rl_bitsize |
5831 && lr_bitpos == rr_bitpos + rr_bitsize)) | 6104 && lr_bitpos == rr_bitpos + rr_bitsize)) |
5832 { | 6105 { |
5833 tree type; | 6106 tree type; |
5834 | 6107 |
5835 lhs = make_bit_field_ref (ll_inner, lntype, ll_bitsize + rl_bitsize, | 6108 lhs = make_bit_field_ref (loc, ll_inner, lntype, |
6109 ll_bitsize + rl_bitsize, | |
5836 MIN (ll_bitpos, rl_bitpos), ll_unsignedp); | 6110 MIN (ll_bitpos, rl_bitpos), ll_unsignedp); |
5837 rhs = make_bit_field_ref (lr_inner, rntype, lr_bitsize + rr_bitsize, | 6111 rhs = make_bit_field_ref (loc, lr_inner, rntype, |
6112 lr_bitsize + rr_bitsize, | |
5838 MIN (lr_bitpos, rr_bitpos), lr_unsignedp); | 6113 MIN (lr_bitpos, rr_bitpos), lr_unsignedp); |
5839 | 6114 |
5840 ll_mask = const_binop (RSHIFT_EXPR, ll_mask, | 6115 ll_mask = const_binop (RSHIFT_EXPR, ll_mask, |
5841 size_int (MIN (xll_bitpos, xrl_bitpos)), 0); | 6116 size_int (MIN (xll_bitpos, xrl_bitpos)), 0); |
5842 lr_mask = const_binop (RSHIFT_EXPR, lr_mask, | 6117 lr_mask = const_binop (RSHIFT_EXPR, lr_mask, |
5846 type = lntype; | 6121 type = lntype; |
5847 if (lntype != rntype) | 6122 if (lntype != rntype) |
5848 { | 6123 { |
5849 if (lnbitsize > rnbitsize) | 6124 if (lnbitsize > rnbitsize) |
5850 { | 6125 { |
5851 lhs = fold_convert (rntype, lhs); | 6126 lhs = fold_convert_loc (loc, rntype, lhs); |
5852 ll_mask = fold_convert (rntype, ll_mask); | 6127 ll_mask = fold_convert_loc (loc, rntype, ll_mask); |
5853 type = rntype; | 6128 type = rntype; |
5854 } | 6129 } |
5855 else if (lnbitsize < rnbitsize) | 6130 else if (lnbitsize < rnbitsize) |
5856 { | 6131 { |
5857 rhs = fold_convert (lntype, rhs); | 6132 rhs = fold_convert_loc (loc, lntype, rhs); |
5858 lr_mask = fold_convert (lntype, lr_mask); | 6133 lr_mask = fold_convert_loc (loc, lntype, lr_mask); |
5859 type = lntype; | 6134 type = lntype; |
5860 } | 6135 } |
5861 } | 6136 } |
5862 | 6137 |
5863 if (! all_ones_mask_p (ll_mask, ll_bitsize + rl_bitsize)) | 6138 if (! all_ones_mask_p (ll_mask, ll_bitsize + rl_bitsize)) |
5864 lhs = build2 (BIT_AND_EXPR, type, lhs, ll_mask); | 6139 lhs = build2 (BIT_AND_EXPR, type, lhs, ll_mask); |
5865 | 6140 |
5866 if (! all_ones_mask_p (lr_mask, lr_bitsize + rr_bitsize)) | 6141 if (! all_ones_mask_p (lr_mask, lr_bitsize + rr_bitsize)) |
5867 rhs = build2 (BIT_AND_EXPR, type, rhs, lr_mask); | 6142 rhs = build2 (BIT_AND_EXPR, type, rhs, lr_mask); |
5868 | 6143 |
5869 return build2 (wanted_code, truth_type, lhs, rhs); | 6144 result = build2 (wanted_code, truth_type, lhs, rhs); |
6145 goto fold_truthop_exit; | |
5870 } | 6146 } |
5871 | 6147 |
5872 return 0; | 6148 return 0; |
5873 } | 6149 } |
5874 | 6150 |
5895 | 6171 |
5896 /* Construct the expression we will return. First get the component | 6172 /* Construct the expression we will return. First get the component |
5897 reference we will make. Unless the mask is all ones the width of | 6173 reference we will make. Unless the mask is all ones the width of |
5898 that field, perform the mask operation. Then compare with the | 6174 that field, perform the mask operation. Then compare with the |
5899 merged constant. */ | 6175 merged constant. */ |
5900 result = make_bit_field_ref (ll_inner, lntype, lnbitsize, lnbitpos, | 6176 result = make_bit_field_ref (loc, ll_inner, lntype, lnbitsize, lnbitpos, |
5901 ll_unsignedp || rl_unsignedp); | 6177 ll_unsignedp || rl_unsignedp); |
5902 | 6178 |
5903 ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0); | 6179 ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0); |
5904 if (! all_ones_mask_p (ll_mask, lnbitsize)) | 6180 if (! all_ones_mask_p (ll_mask, lnbitsize)) |
5905 result = build2 (BIT_AND_EXPR, lntype, result, ll_mask); | 6181 { |
5906 | 6182 result = build2 (BIT_AND_EXPR, lntype, result, ll_mask); |
5907 return build2 (wanted_code, truth_type, result, | 6183 SET_EXPR_LOCATION (result, loc); |
5908 const_binop (BIT_IOR_EXPR, l_const, r_const, 0)); | 6184 } |
6185 | |
6186 result = build2 (wanted_code, truth_type, result, | |
6187 const_binop (BIT_IOR_EXPR, l_const, r_const, 0)); | |
6188 | |
6189 fold_truthop_exit: | |
6190 SET_EXPR_LOCATION (result, loc); | |
6191 return result; | |
5909 } | 6192 } |
5910 | 6193 |
5911 /* Optimize T, which is a comparison of a MIN_EXPR or MAX_EXPR with a | 6194 /* Optimize T, which is a comparison of a MIN_EXPR or MAX_EXPR with a |
5912 constant. */ | 6195 constant. */ |
5913 | 6196 |
5914 static tree | 6197 static tree |
5915 optimize_minmax_comparison (enum tree_code code, tree type, tree op0, tree op1) | 6198 optimize_minmax_comparison (location_t loc, enum tree_code code, tree type, |
6199 tree op0, tree op1) | |
5916 { | 6200 { |
5917 tree arg0 = op0; | 6201 tree arg0 = op0; |
5918 enum tree_code op_code; | 6202 enum tree_code op_code; |
5919 tree comp_const; | 6203 tree comp_const; |
5920 tree minmax_const; | 6204 tree minmax_const; |
5923 | 6207 |
5924 STRIP_SIGN_NOPS (arg0); | 6208 STRIP_SIGN_NOPS (arg0); |
5925 | 6209 |
5926 op_code = TREE_CODE (arg0); | 6210 op_code = TREE_CODE (arg0); |
5927 minmax_const = TREE_OPERAND (arg0, 1); | 6211 minmax_const = TREE_OPERAND (arg0, 1); |
5928 comp_const = fold_convert (TREE_TYPE (arg0), op1); | 6212 comp_const = fold_convert_loc (loc, TREE_TYPE (arg0), op1); |
5929 consts_equal = tree_int_cst_equal (minmax_const, comp_const); | 6213 consts_equal = tree_int_cst_equal (minmax_const, comp_const); |
5930 consts_lt = tree_int_cst_lt (minmax_const, comp_const); | 6214 consts_lt = tree_int_cst_lt (minmax_const, comp_const); |
5931 inner = TREE_OPERAND (arg0, 0); | 6215 inner = TREE_OPERAND (arg0, 0); |
5932 | 6216 |
5933 /* If something does not permit us to optimize, return the original tree. */ | 6217 /* If something does not permit us to optimize, return the original tree. */ |
5943 simplifications. */ | 6227 simplifications. */ |
5944 switch (code) | 6228 switch (code) |
5945 { | 6229 { |
5946 case NE_EXPR: case LT_EXPR: case LE_EXPR: | 6230 case NE_EXPR: case LT_EXPR: case LE_EXPR: |
5947 { | 6231 { |
5948 tree tem = optimize_minmax_comparison (invert_tree_comparison (code, false), | 6232 tree tem |
5949 type, op0, op1); | 6233 = optimize_minmax_comparison (loc, |
6234 invert_tree_comparison (code, false), | |
6235 type, op0, op1); | |
5950 if (tem) | 6236 if (tem) |
5951 return invert_truthvalue (tem); | 6237 return invert_truthvalue_loc (loc, tem); |
5952 return NULL_TREE; | 6238 return NULL_TREE; |
5953 } | 6239 } |
5954 | 6240 |
5955 case GE_EXPR: | 6241 case GE_EXPR: |
5956 return | 6242 return |
5957 fold_build2 (TRUTH_ORIF_EXPR, type, | 6243 fold_build2_loc (loc, TRUTH_ORIF_EXPR, type, |
5958 optimize_minmax_comparison | 6244 optimize_minmax_comparison |
5959 (EQ_EXPR, type, arg0, comp_const), | 6245 (loc, EQ_EXPR, type, arg0, comp_const), |
5960 optimize_minmax_comparison | 6246 optimize_minmax_comparison |
5961 (GT_EXPR, type, arg0, comp_const)); | 6247 (loc, GT_EXPR, type, arg0, comp_const)); |
5962 | 6248 |
5963 case EQ_EXPR: | 6249 case EQ_EXPR: |
5964 if (op_code == MAX_EXPR && consts_equal) | 6250 if (op_code == MAX_EXPR && consts_equal) |
5965 /* MAX (X, 0) == 0 -> X <= 0 */ | 6251 /* MAX (X, 0) == 0 -> X <= 0 */ |
5966 return fold_build2 (LE_EXPR, type, inner, comp_const); | 6252 return fold_build2_loc (loc, LE_EXPR, type, inner, comp_const); |
5967 | 6253 |
5968 else if (op_code == MAX_EXPR && consts_lt) | 6254 else if (op_code == MAX_EXPR && consts_lt) |
5969 /* MAX (X, 0) == 5 -> X == 5 */ | 6255 /* MAX (X, 0) == 5 -> X == 5 */ |
5970 return fold_build2 (EQ_EXPR, type, inner, comp_const); | 6256 return fold_build2_loc (loc, EQ_EXPR, type, inner, comp_const); |
5971 | 6257 |
5972 else if (op_code == MAX_EXPR) | 6258 else if (op_code == MAX_EXPR) |
5973 /* MAX (X, 0) == -1 -> false */ | 6259 /* MAX (X, 0) == -1 -> false */ |
5974 return omit_one_operand (type, integer_zero_node, inner); | 6260 return omit_one_operand_loc (loc, type, integer_zero_node, inner); |
5975 | 6261 |
5976 else if (consts_equal) | 6262 else if (consts_equal) |
5977 /* MIN (X, 0) == 0 -> X >= 0 */ | 6263 /* MIN (X, 0) == 0 -> X >= 0 */ |
5978 return fold_build2 (GE_EXPR, type, inner, comp_const); | 6264 return fold_build2_loc (loc, GE_EXPR, type, inner, comp_const); |
5979 | 6265 |
5980 else if (consts_lt) | 6266 else if (consts_lt) |
5981 /* MIN (X, 0) == 5 -> false */ | 6267 /* MIN (X, 0) == 5 -> false */ |
5982 return omit_one_operand (type, integer_zero_node, inner); | 6268 return omit_one_operand_loc (loc, type, integer_zero_node, inner); |
5983 | 6269 |
5984 else | 6270 else |
5985 /* MIN (X, 0) == -1 -> X == -1 */ | 6271 /* MIN (X, 0) == -1 -> X == -1 */ |
5986 return fold_build2 (EQ_EXPR, type, inner, comp_const); | 6272 return fold_build2_loc (loc, EQ_EXPR, type, inner, comp_const); |
5987 | 6273 |
5988 case GT_EXPR: | 6274 case GT_EXPR: |
5989 if (op_code == MAX_EXPR && (consts_equal || consts_lt)) | 6275 if (op_code == MAX_EXPR && (consts_equal || consts_lt)) |
5990 /* MAX (X, 0) > 0 -> X > 0 | 6276 /* MAX (X, 0) > 0 -> X > 0 |
5991 MAX (X, 0) > 5 -> X > 5 */ | 6277 MAX (X, 0) > 5 -> X > 5 */ |
5992 return fold_build2 (GT_EXPR, type, inner, comp_const); | 6278 return fold_build2_loc (loc, GT_EXPR, type, inner, comp_const); |
5993 | 6279 |
5994 else if (op_code == MAX_EXPR) | 6280 else if (op_code == MAX_EXPR) |
5995 /* MAX (X, 0) > -1 -> true */ | 6281 /* MAX (X, 0) > -1 -> true */ |
5996 return omit_one_operand (type, integer_one_node, inner); | 6282 return omit_one_operand_loc (loc, type, integer_one_node, inner); |
5997 | 6283 |
5998 else if (op_code == MIN_EXPR && (consts_equal || consts_lt)) | 6284 else if (op_code == MIN_EXPR && (consts_equal || consts_lt)) |
5999 /* MIN (X, 0) > 0 -> false | 6285 /* MIN (X, 0) > 0 -> false |
6000 MIN (X, 0) > 5 -> false */ | 6286 MIN (X, 0) > 5 -> false */ |
6001 return omit_one_operand (type, integer_zero_node, inner); | 6287 return omit_one_operand_loc (loc, type, integer_zero_node, inner); |
6002 | 6288 |
6003 else | 6289 else |
6004 /* MIN (X, 0) > -1 -> X > -1 */ | 6290 /* MIN (X, 0) > -1 -> X > -1 */ |
6005 return fold_build2 (GT_EXPR, type, inner, comp_const); | 6291 return fold_build2_loc (loc, GT_EXPR, type, inner, comp_const); |
6006 | 6292 |
6007 default: | 6293 default: |
6008 return NULL_TREE; | 6294 return NULL_TREE; |
6009 } | 6295 } |
6010 } | 6296 } |
6193 size_one_node, | 6479 size_one_node, |
6194 op1, 0))) | 6480 op1, 0))) |
6195 && !TREE_OVERFLOW (t1)) | 6481 && !TREE_OVERFLOW (t1)) |
6196 return extract_muldiv (build2 (tcode == LSHIFT_EXPR | 6482 return extract_muldiv (build2 (tcode == LSHIFT_EXPR |
6197 ? MULT_EXPR : FLOOR_DIV_EXPR, | 6483 ? MULT_EXPR : FLOOR_DIV_EXPR, |
6198 ctype, fold_convert (ctype, op0), t1), | 6484 ctype, |
6485 fold_convert (ctype, op0), | |
6486 t1), | |
6199 c, code, wide_type, strict_overflow_p); | 6487 c, code, wide_type, strict_overflow_p); |
6200 break; | 6488 break; |
6201 | 6489 |
6202 case PLUS_EXPR: case MINUS_EXPR: | 6490 case PLUS_EXPR: case MINUS_EXPR: |
6203 /* See if we can eliminate the operation on both sides. If we can, we | 6491 /* See if we can eliminate the operation on both sides. If we can, we |
6221 } | 6509 } |
6222 | 6510 |
6223 /* If this was a subtraction, negate OP1 and set it to be an addition. | 6511 /* If this was a subtraction, negate OP1 and set it to be an addition. |
6224 This simplifies the logic below. */ | 6512 This simplifies the logic below. */ |
6225 if (tcode == MINUS_EXPR) | 6513 if (tcode == MINUS_EXPR) |
6226 tcode = PLUS_EXPR, op1 = negate_expr (op1); | 6514 { |
6515 tcode = PLUS_EXPR, op1 = negate_expr (op1); | |
6516 /* If OP1 was not easily negatable, the constant may be OP0. */ | |
6517 if (TREE_CODE (op0) == INTEGER_CST) | |
6518 { | |
6519 tree tem = op0; | |
6520 op0 = op1; | |
6521 op1 = tem; | |
6522 tem = t1; | |
6523 t1 = t2; | |
6524 t2 = tem; | |
6525 } | |
6526 } | |
6227 | 6527 |
6228 if (TREE_CODE (op1) != INTEGER_CST) | 6528 if (TREE_CODE (op1) != INTEGER_CST) |
6229 break; | 6529 break; |
6230 | 6530 |
6231 /* If either OP1 or C are negative, this optimization is not safe for | 6531 /* If either OP1 or C are negative, this optimization is not safe for |
6323 return 0; | 6623 return 0; |
6324 | 6624 |
6325 /* If these are the same operation types, we can associate them | 6625 /* If these are the same operation types, we can associate them |
6326 assuming no overflow. */ | 6626 assuming no overflow. */ |
6327 if (tcode == code | 6627 if (tcode == code |
6328 && 0 != (t1 = int_const_binop (MULT_EXPR, fold_convert (ctype, op1), | 6628 && 0 != (t1 = int_const_binop (MULT_EXPR, |
6629 fold_convert (ctype, op1), | |
6329 fold_convert (ctype, c), 1)) | 6630 fold_convert (ctype, c), 1)) |
6330 && 0 != (t1 = force_fit_type_double (ctype, TREE_INT_CST_LOW (t1), | 6631 && 0 != (t1 = force_fit_type_double (ctype, TREE_INT_CST_LOW (t1), |
6331 TREE_INT_CST_HIGH (t1), | 6632 TREE_INT_CST_HIGH (t1), |
6332 (TYPE_UNSIGNED (ctype) | 6633 (TYPE_UNSIGNED (ctype) |
6333 && tcode != MULT_EXPR) ? -1 : 1, | 6634 && tcode != MULT_EXPR) ? -1 : 1, |
6402 given here), it is the second argument. TYPE is the type of the | 6703 given here), it is the second argument. TYPE is the type of the |
6403 original expression. Return NULL_TREE if no simplification is | 6704 original expression. Return NULL_TREE if no simplification is |
6404 possible. */ | 6705 possible. */ |
6405 | 6706 |
6406 static tree | 6707 static tree |
6407 fold_binary_op_with_conditional_arg (enum tree_code code, | 6708 fold_binary_op_with_conditional_arg (location_t loc, |
6709 enum tree_code code, | |
6408 tree type, tree op0, tree op1, | 6710 tree type, tree op0, tree op1, |
6409 tree cond, tree arg, int cond_first_p) | 6711 tree cond, tree arg, int cond_first_p) |
6410 { | 6712 { |
6411 tree cond_type = cond_first_p ? TREE_TYPE (op0) : TREE_TYPE (op1); | 6713 tree cond_type = cond_first_p ? TREE_TYPE (op0) : TREE_TYPE (op1); |
6412 tree arg_type = cond_first_p ? TREE_TYPE (op1) : TREE_TYPE (op0); | 6714 tree arg_type = cond_first_p ? TREE_TYPE (op1) : TREE_TYPE (op0); |
6439 test = cond; | 6741 test = cond; |
6440 true_value = constant_boolean_node (true, testtype); | 6742 true_value = constant_boolean_node (true, testtype); |
6441 false_value = constant_boolean_node (false, testtype); | 6743 false_value = constant_boolean_node (false, testtype); |
6442 } | 6744 } |
6443 | 6745 |
6444 arg = fold_convert (arg_type, arg); | 6746 arg = fold_convert_loc (loc, arg_type, arg); |
6445 if (lhs == 0) | 6747 if (lhs == 0) |
6446 { | 6748 { |
6447 true_value = fold_convert (cond_type, true_value); | 6749 true_value = fold_convert_loc (loc, cond_type, true_value); |
6448 if (cond_first_p) | 6750 if (cond_first_p) |
6449 lhs = fold_build2 (code, type, true_value, arg); | 6751 lhs = fold_build2_loc (loc, code, type, true_value, arg); |
6450 else | 6752 else |
6451 lhs = fold_build2 (code, type, arg, true_value); | 6753 lhs = fold_build2_loc (loc, code, type, arg, true_value); |
6452 } | 6754 } |
6453 if (rhs == 0) | 6755 if (rhs == 0) |
6454 { | 6756 { |
6455 false_value = fold_convert (cond_type, false_value); | 6757 false_value = fold_convert_loc (loc, cond_type, false_value); |
6456 if (cond_first_p) | 6758 if (cond_first_p) |
6457 rhs = fold_build2 (code, type, false_value, arg); | 6759 rhs = fold_build2_loc (loc, code, type, false_value, arg); |
6458 else | 6760 else |
6459 rhs = fold_build2 (code, type, arg, false_value); | 6761 rhs = fold_build2_loc (loc, code, type, arg, false_value); |
6460 } | 6762 } |
6461 | 6763 |
6462 test = fold_build3 (COND_EXPR, type, test, lhs, rhs); | 6764 test = fold_build3_loc (loc, COND_EXPR, type, test, lhs, rhs); |
6463 return fold_convert (type, test); | 6765 return fold_convert_loc (loc, type, test); |
6464 } | 6766 } |
6465 | 6767 |
6466 | 6768 |
6467 /* Subroutine of fold() that checks for the addition of +/- 0.0. | 6769 /* Subroutine of fold() that checks for the addition of +/- 0.0. |
6468 | 6770 |
6512 | 6814 |
6513 The function returns the constant folded tree if a simplification | 6815 The function returns the constant folded tree if a simplification |
6514 can be made, and NULL_TREE otherwise. */ | 6816 can be made, and NULL_TREE otherwise. */ |
6515 | 6817 |
6516 static tree | 6818 static tree |
6517 fold_mathfn_compare (enum built_in_function fcode, enum tree_code code, | 6819 fold_mathfn_compare (location_t loc, |
6820 enum built_in_function fcode, enum tree_code code, | |
6518 tree type, tree arg0, tree arg1) | 6821 tree type, tree arg0, tree arg1) |
6519 { | 6822 { |
6520 REAL_VALUE_TYPE c; | 6823 REAL_VALUE_TYPE c; |
6521 | 6824 |
6522 if (BUILTIN_SQRT_P (fcode)) | 6825 if (BUILTIN_SQRT_P (fcode)) |
6527 c = TREE_REAL_CST (arg1); | 6830 c = TREE_REAL_CST (arg1); |
6528 if (REAL_VALUE_NEGATIVE (c)) | 6831 if (REAL_VALUE_NEGATIVE (c)) |
6529 { | 6832 { |
6530 /* sqrt(x) < y is always false, if y is negative. */ | 6833 /* sqrt(x) < y is always false, if y is negative. */ |
6531 if (code == EQ_EXPR || code == LT_EXPR || code == LE_EXPR) | 6834 if (code == EQ_EXPR || code == LT_EXPR || code == LE_EXPR) |
6532 return omit_one_operand (type, integer_zero_node, arg); | 6835 return omit_one_operand_loc (loc, type, integer_zero_node, arg); |
6533 | 6836 |
6534 /* sqrt(x) > y is always true, if y is negative and we | 6837 /* sqrt(x) > y is always true, if y is negative and we |
6535 don't care about NaNs, i.e. negative values of x. */ | 6838 don't care about NaNs, i.e. negative values of x. */ |
6536 if (code == NE_EXPR || !HONOR_NANS (mode)) | 6839 if (code == NE_EXPR || !HONOR_NANS (mode)) |
6537 return omit_one_operand (type, integer_one_node, arg); | 6840 return omit_one_operand_loc (loc, type, integer_one_node, arg); |
6538 | 6841 |
6539 /* sqrt(x) > y is the same as x >= 0, if y is negative. */ | 6842 /* sqrt(x) > y is the same as x >= 0, if y is negative. */ |
6540 return fold_build2 (GE_EXPR, type, arg, | 6843 return fold_build2_loc (loc, GE_EXPR, type, arg, |
6541 build_real (TREE_TYPE (arg), dconst0)); | 6844 build_real (TREE_TYPE (arg), dconst0)); |
6542 } | 6845 } |
6543 else if (code == GT_EXPR || code == GE_EXPR) | 6846 else if (code == GT_EXPR || code == GE_EXPR) |
6544 { | 6847 { |
6545 REAL_VALUE_TYPE c2; | 6848 REAL_VALUE_TYPE c2; |
6549 | 6852 |
6550 if (REAL_VALUE_ISINF (c2)) | 6853 if (REAL_VALUE_ISINF (c2)) |
6551 { | 6854 { |
6552 /* sqrt(x) > y is x == +Inf, when y is very large. */ | 6855 /* sqrt(x) > y is x == +Inf, when y is very large. */ |
6553 if (HONOR_INFINITIES (mode)) | 6856 if (HONOR_INFINITIES (mode)) |
6554 return fold_build2 (EQ_EXPR, type, arg, | 6857 return fold_build2_loc (loc, EQ_EXPR, type, arg, |
6555 build_real (TREE_TYPE (arg), c2)); | 6858 build_real (TREE_TYPE (arg), c2)); |
6556 | 6859 |
6557 /* sqrt(x) > y is always false, when y is very large | 6860 /* sqrt(x) > y is always false, when y is very large |
6558 and we don't care about infinities. */ | 6861 and we don't care about infinities. */ |
6559 return omit_one_operand (type, integer_zero_node, arg); | 6862 return omit_one_operand_loc (loc, type, integer_zero_node, arg); |
6560 } | 6863 } |
6561 | 6864 |
6562 /* sqrt(x) > c is the same as x > c*c. */ | 6865 /* sqrt(x) > c is the same as x > c*c. */ |
6563 return fold_build2 (code, type, arg, | 6866 return fold_build2_loc (loc, code, type, arg, |
6564 build_real (TREE_TYPE (arg), c2)); | 6867 build_real (TREE_TYPE (arg), c2)); |
6565 } | 6868 } |
6566 else if (code == LT_EXPR || code == LE_EXPR) | 6869 else if (code == LT_EXPR || code == LE_EXPR) |
6567 { | 6870 { |
6568 REAL_VALUE_TYPE c2; | 6871 REAL_VALUE_TYPE c2; |
6573 if (REAL_VALUE_ISINF (c2)) | 6876 if (REAL_VALUE_ISINF (c2)) |
6574 { | 6877 { |
6575 /* sqrt(x) < y is always true, when y is a very large | 6878 /* sqrt(x) < y is always true, when y is a very large |
6576 value and we don't care about NaNs or Infinities. */ | 6879 value and we don't care about NaNs or Infinities. */ |
6577 if (! HONOR_NANS (mode) && ! HONOR_INFINITIES (mode)) | 6880 if (! HONOR_NANS (mode) && ! HONOR_INFINITIES (mode)) |
6578 return omit_one_operand (type, integer_one_node, arg); | 6881 return omit_one_operand_loc (loc, type, integer_one_node, arg); |
6579 | 6882 |
6580 /* sqrt(x) < y is x != +Inf when y is very large and we | 6883 /* sqrt(x) < y is x != +Inf when y is very large and we |
6581 don't care about NaNs. */ | 6884 don't care about NaNs. */ |
6582 if (! HONOR_NANS (mode)) | 6885 if (! HONOR_NANS (mode)) |
6583 return fold_build2 (NE_EXPR, type, arg, | 6886 return fold_build2_loc (loc, NE_EXPR, type, arg, |
6584 build_real (TREE_TYPE (arg), c2)); | 6887 build_real (TREE_TYPE (arg), c2)); |
6585 | 6888 |
6586 /* sqrt(x) < y is x >= 0 when y is very large and we | 6889 /* sqrt(x) < y is x >= 0 when y is very large and we |
6587 don't care about Infinities. */ | 6890 don't care about Infinities. */ |
6588 if (! HONOR_INFINITIES (mode)) | 6891 if (! HONOR_INFINITIES (mode)) |
6589 return fold_build2 (GE_EXPR, type, arg, | 6892 return fold_build2_loc (loc, GE_EXPR, type, arg, |
6590 build_real (TREE_TYPE (arg), dconst0)); | 6893 build_real (TREE_TYPE (arg), dconst0)); |
6591 | 6894 |
6592 /* sqrt(x) < y is x >= 0 && x != +Inf, when y is large. */ | 6895 /* sqrt(x) < y is x >= 0 && x != +Inf, when y is large. */ |
6593 if (lang_hooks.decls.global_bindings_p () != 0 | 6896 if (lang_hooks.decls.global_bindings_p () != 0 |
6594 || CONTAINS_PLACEHOLDER_P (arg)) | 6897 || CONTAINS_PLACEHOLDER_P (arg)) |
6595 return NULL_TREE; | 6898 return NULL_TREE; |
6596 | 6899 |
6597 arg = save_expr (arg); | 6900 arg = save_expr (arg); |
6598 return fold_build2 (TRUTH_ANDIF_EXPR, type, | 6901 return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type, |
6599 fold_build2 (GE_EXPR, type, arg, | 6902 fold_build2_loc (loc, GE_EXPR, type, arg, |
6600 build_real (TREE_TYPE (arg), | 6903 build_real (TREE_TYPE (arg), |
6601 dconst0)), | 6904 dconst0)), |
6602 fold_build2 (NE_EXPR, type, arg, | 6905 fold_build2_loc (loc, NE_EXPR, type, arg, |
6603 build_real (TREE_TYPE (arg), | 6906 build_real (TREE_TYPE (arg), |
6604 c2))); | 6907 c2))); |
6605 } | 6908 } |
6606 | 6909 |
6607 /* sqrt(x) < c is the same as x < c*c, if we ignore NaNs. */ | 6910 /* sqrt(x) < c is the same as x < c*c, if we ignore NaNs. */ |
6608 if (! HONOR_NANS (mode)) | 6911 if (! HONOR_NANS (mode)) |
6609 return fold_build2 (code, type, arg, | 6912 return fold_build2_loc (loc, code, type, arg, |
6610 build_real (TREE_TYPE (arg), c2)); | 6913 build_real (TREE_TYPE (arg), c2)); |
6611 | 6914 |
6612 /* sqrt(x) < c is the same as x >= 0 && x < c*c. */ | 6915 /* sqrt(x) < c is the same as x >= 0 && x < c*c. */ |
6613 if (lang_hooks.decls.global_bindings_p () == 0 | 6916 if (lang_hooks.decls.global_bindings_p () == 0 |
6614 && ! CONTAINS_PLACEHOLDER_P (arg)) | 6917 && ! CONTAINS_PLACEHOLDER_P (arg)) |
6615 { | 6918 { |
6616 arg = save_expr (arg); | 6919 arg = save_expr (arg); |
6617 return fold_build2 (TRUTH_ANDIF_EXPR, type, | 6920 return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type, |
6618 fold_build2 (GE_EXPR, type, arg, | 6921 fold_build2_loc (loc, GE_EXPR, type, arg, |
6619 build_real (TREE_TYPE (arg), | 6922 build_real (TREE_TYPE (arg), |
6620 dconst0)), | 6923 dconst0)), |
6621 fold_build2 (code, type, arg, | 6924 fold_build2_loc (loc, code, type, arg, |
6622 build_real (TREE_TYPE (arg), | 6925 build_real (TREE_TYPE (arg), |
6623 c2))); | 6926 c2))); |
6624 } | 6927 } |
6625 } | 6928 } |
6626 } | 6929 } |
6637 | 6940 |
6638 The function returns the constant folded tree if a simplification | 6941 The function returns the constant folded tree if a simplification |
6639 can be made, and NULL_TREE otherwise. */ | 6942 can be made, and NULL_TREE otherwise. */ |
6640 | 6943 |
6641 static tree | 6944 static tree |
6642 fold_inf_compare (enum tree_code code, tree type, tree arg0, tree arg1) | 6945 fold_inf_compare (location_t loc, enum tree_code code, tree type, |
6946 tree arg0, tree arg1) | |
6643 { | 6947 { |
6644 enum machine_mode mode; | 6948 enum machine_mode mode; |
6645 REAL_VALUE_TYPE max; | 6949 REAL_VALUE_TYPE max; |
6646 tree temp; | 6950 tree temp; |
6647 bool neg; | 6951 bool neg; |
6657 { | 6961 { |
6658 case GT_EXPR: | 6962 case GT_EXPR: |
6659 /* x > +Inf is always false, if with ignore sNANs. */ | 6963 /* x > +Inf is always false, if with ignore sNANs. */ |
6660 if (HONOR_SNANS (mode)) | 6964 if (HONOR_SNANS (mode)) |
6661 return NULL_TREE; | 6965 return NULL_TREE; |
6662 return omit_one_operand (type, integer_zero_node, arg0); | 6966 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
6663 | 6967 |
6664 case LE_EXPR: | 6968 case LE_EXPR: |
6665 /* x <= +Inf is always true, if we don't case about NaNs. */ | 6969 /* x <= +Inf is always true, if we don't case about NaNs. */ |
6666 if (! HONOR_NANS (mode)) | 6970 if (! HONOR_NANS (mode)) |
6667 return omit_one_operand (type, integer_one_node, arg0); | 6971 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
6668 | 6972 |
6669 /* x <= +Inf is the same as x == x, i.e. isfinite(x). */ | 6973 /* x <= +Inf is the same as x == x, i.e. isfinite(x). */ |
6670 if (lang_hooks.decls.global_bindings_p () == 0 | 6974 if (lang_hooks.decls.global_bindings_p () == 0 |
6671 && ! CONTAINS_PLACEHOLDER_P (arg0)) | 6975 && ! CONTAINS_PLACEHOLDER_P (arg0)) |
6672 { | 6976 { |
6673 arg0 = save_expr (arg0); | 6977 arg0 = save_expr (arg0); |
6674 return fold_build2 (EQ_EXPR, type, arg0, arg0); | 6978 return fold_build2_loc (loc, EQ_EXPR, type, arg0, arg0); |
6675 } | 6979 } |
6676 break; | 6980 break; |
6677 | 6981 |
6678 case EQ_EXPR: | 6982 case EQ_EXPR: |
6679 case GE_EXPR: | 6983 case GE_EXPR: |
6680 /* x == +Inf and x >= +Inf are always equal to x > DBL_MAX. */ | 6984 /* x == +Inf and x >= +Inf are always equal to x > DBL_MAX. */ |
6681 real_maxval (&max, neg, mode); | 6985 real_maxval (&max, neg, mode); |
6682 return fold_build2 (neg ? LT_EXPR : GT_EXPR, type, | 6986 return fold_build2_loc (loc, neg ? LT_EXPR : GT_EXPR, type, |
6683 arg0, build_real (TREE_TYPE (arg0), max)); | 6987 arg0, build_real (TREE_TYPE (arg0), max)); |
6684 | 6988 |
6685 case LT_EXPR: | 6989 case LT_EXPR: |
6686 /* x < +Inf is always equal to x <= DBL_MAX. */ | 6990 /* x < +Inf is always equal to x <= DBL_MAX. */ |
6687 real_maxval (&max, neg, mode); | 6991 real_maxval (&max, neg, mode); |
6688 return fold_build2 (neg ? GE_EXPR : LE_EXPR, type, | 6992 return fold_build2_loc (loc, neg ? GE_EXPR : LE_EXPR, type, |
6689 arg0, build_real (TREE_TYPE (arg0), max)); | 6993 arg0, build_real (TREE_TYPE (arg0), max)); |
6690 | 6994 |
6691 case NE_EXPR: | 6995 case NE_EXPR: |
6692 /* x != +Inf is always equal to !(x > DBL_MAX). */ | 6996 /* x != +Inf is always equal to !(x > DBL_MAX). */ |
6693 real_maxval (&max, neg, mode); | 6997 real_maxval (&max, neg, mode); |
6694 if (! HONOR_NANS (mode)) | 6998 if (! HONOR_NANS (mode)) |
6695 return fold_build2 (neg ? GE_EXPR : LE_EXPR, type, | 6999 return fold_build2_loc (loc, neg ? GE_EXPR : LE_EXPR, type, |
6696 arg0, build_real (TREE_TYPE (arg0), max)); | 7000 arg0, build_real (TREE_TYPE (arg0), max)); |
6697 | 7001 |
6698 temp = fold_build2 (neg ? LT_EXPR : GT_EXPR, type, | 7002 temp = fold_build2_loc (loc, neg ? LT_EXPR : GT_EXPR, type, |
6699 arg0, build_real (TREE_TYPE (arg0), max)); | 7003 arg0, build_real (TREE_TYPE (arg0), max)); |
6700 return fold_build1 (TRUTH_NOT_EXPR, type, temp); | 7004 return fold_build1_loc (loc, TRUTH_NOT_EXPR, type, temp); |
6701 | 7005 |
6702 default: | 7006 default: |
6703 break; | 7007 break; |
6704 } | 7008 } |
6705 | 7009 |
6716 | 7020 |
6717 The function returns the constant folded tree if a simplification | 7021 The function returns the constant folded tree if a simplification |
6718 can be made, and NULL_TREE otherwise. */ | 7022 can be made, and NULL_TREE otherwise. */ |
6719 | 7023 |
6720 static tree | 7024 static tree |
6721 fold_div_compare (enum tree_code code, tree type, tree arg0, tree arg1) | 7025 fold_div_compare (location_t loc, |
7026 enum tree_code code, tree type, tree arg0, tree arg1) | |
6722 { | 7027 { |
6723 tree prod, tmp, hi, lo; | 7028 tree prod, tmp, hi, lo; |
6724 tree arg00 = TREE_OPERAND (arg0, 0); | 7029 tree arg00 = TREE_OPERAND (arg0, 0); |
6725 tree arg01 = TREE_OPERAND (arg0, 1); | 7030 tree arg01 = TREE_OPERAND (arg0, 1); |
6726 unsigned HOST_WIDE_INT lpart; | 7031 unsigned HOST_WIDE_INT lpart; |
6813 | 7118 |
6814 switch (code) | 7119 switch (code) |
6815 { | 7120 { |
6816 case EQ_EXPR: | 7121 case EQ_EXPR: |
6817 if (TREE_OVERFLOW (lo) && TREE_OVERFLOW (hi)) | 7122 if (TREE_OVERFLOW (lo) && TREE_OVERFLOW (hi)) |
6818 return omit_one_operand (type, integer_zero_node, arg00); | 7123 return omit_one_operand_loc (loc, type, integer_zero_node, arg00); |
6819 if (TREE_OVERFLOW (hi)) | 7124 if (TREE_OVERFLOW (hi)) |
6820 return fold_build2 (GE_EXPR, type, arg00, lo); | 7125 return fold_build2_loc (loc, GE_EXPR, type, arg00, lo); |
6821 if (TREE_OVERFLOW (lo)) | 7126 if (TREE_OVERFLOW (lo)) |
6822 return fold_build2 (LE_EXPR, type, arg00, hi); | 7127 return fold_build2_loc (loc, LE_EXPR, type, arg00, hi); |
6823 return build_range_check (type, arg00, 1, lo, hi); | 7128 return build_range_check (loc, type, arg00, 1, lo, hi); |
6824 | 7129 |
6825 case NE_EXPR: | 7130 case NE_EXPR: |
6826 if (TREE_OVERFLOW (lo) && TREE_OVERFLOW (hi)) | 7131 if (TREE_OVERFLOW (lo) && TREE_OVERFLOW (hi)) |
6827 return omit_one_operand (type, integer_one_node, arg00); | 7132 return omit_one_operand_loc (loc, type, integer_one_node, arg00); |
6828 if (TREE_OVERFLOW (hi)) | 7133 if (TREE_OVERFLOW (hi)) |
6829 return fold_build2 (LT_EXPR, type, arg00, lo); | 7134 return fold_build2_loc (loc, LT_EXPR, type, arg00, lo); |
6830 if (TREE_OVERFLOW (lo)) | 7135 if (TREE_OVERFLOW (lo)) |
6831 return fold_build2 (GT_EXPR, type, arg00, hi); | 7136 return fold_build2_loc (loc, GT_EXPR, type, arg00, hi); |
6832 return build_range_check (type, arg00, 0, lo, hi); | 7137 return build_range_check (loc, type, arg00, 0, lo, hi); |
6833 | 7138 |
6834 case LT_EXPR: | 7139 case LT_EXPR: |
6835 if (TREE_OVERFLOW (lo)) | 7140 if (TREE_OVERFLOW (lo)) |
6836 { | 7141 { |
6837 tmp = neg_overflow ? integer_zero_node : integer_one_node; | 7142 tmp = neg_overflow ? integer_zero_node : integer_one_node; |
6838 return omit_one_operand (type, tmp, arg00); | 7143 return omit_one_operand_loc (loc, type, tmp, arg00); |
6839 } | 7144 } |
6840 return fold_build2 (LT_EXPR, type, arg00, lo); | 7145 return fold_build2_loc (loc, LT_EXPR, type, arg00, lo); |
6841 | 7146 |
6842 case LE_EXPR: | 7147 case LE_EXPR: |
6843 if (TREE_OVERFLOW (hi)) | 7148 if (TREE_OVERFLOW (hi)) |
6844 { | 7149 { |
6845 tmp = neg_overflow ? integer_zero_node : integer_one_node; | 7150 tmp = neg_overflow ? integer_zero_node : integer_one_node; |
6846 return omit_one_operand (type, tmp, arg00); | 7151 return omit_one_operand_loc (loc, type, tmp, arg00); |
6847 } | 7152 } |
6848 return fold_build2 (LE_EXPR, type, arg00, hi); | 7153 return fold_build2_loc (loc, LE_EXPR, type, arg00, hi); |
6849 | 7154 |
6850 case GT_EXPR: | 7155 case GT_EXPR: |
6851 if (TREE_OVERFLOW (hi)) | 7156 if (TREE_OVERFLOW (hi)) |
6852 { | 7157 { |
6853 tmp = neg_overflow ? integer_one_node : integer_zero_node; | 7158 tmp = neg_overflow ? integer_one_node : integer_zero_node; |
6854 return omit_one_operand (type, tmp, arg00); | 7159 return omit_one_operand_loc (loc, type, tmp, arg00); |
6855 } | 7160 } |
6856 return fold_build2 (GT_EXPR, type, arg00, hi); | 7161 return fold_build2_loc (loc, GT_EXPR, type, arg00, hi); |
6857 | 7162 |
6858 case GE_EXPR: | 7163 case GE_EXPR: |
6859 if (TREE_OVERFLOW (lo)) | 7164 if (TREE_OVERFLOW (lo)) |
6860 { | 7165 { |
6861 tmp = neg_overflow ? integer_one_node : integer_zero_node; | 7166 tmp = neg_overflow ? integer_one_node : integer_zero_node; |
6862 return omit_one_operand (type, tmp, arg00); | 7167 return omit_one_operand_loc (loc, type, tmp, arg00); |
6863 } | 7168 } |
6864 return fold_build2 (GE_EXPR, type, arg00, lo); | 7169 return fold_build2_loc (loc, GE_EXPR, type, arg00, lo); |
6865 | 7170 |
6866 default: | 7171 default: |
6867 break; | 7172 break; |
6868 } | 7173 } |
6869 | 7174 |
6875 equality/inequality test, then return a simplified form of the test | 7180 equality/inequality test, then return a simplified form of the test |
6876 using a sign testing. Otherwise return NULL. TYPE is the desired | 7181 using a sign testing. Otherwise return NULL. TYPE is the desired |
6877 result type. */ | 7182 result type. */ |
6878 | 7183 |
6879 static tree | 7184 static tree |
6880 fold_single_bit_test_into_sign_test (enum tree_code code, tree arg0, tree arg1, | 7185 fold_single_bit_test_into_sign_test (location_t loc, |
7186 enum tree_code code, tree arg0, tree arg1, | |
6881 tree result_type) | 7187 tree result_type) |
6882 { | 7188 { |
6883 /* If this is testing a single bit, we can optimize the test. */ | 7189 /* If this is testing a single bit, we can optimize the test. */ |
6884 if ((code == NE_EXPR || code == EQ_EXPR) | 7190 if ((code == NE_EXPR || code == EQ_EXPR) |
6885 && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1) | 7191 && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1) |
6894 i.e. when arg00's type is not a partial mode. */ | 7200 i.e. when arg00's type is not a partial mode. */ |
6895 && TYPE_PRECISION (TREE_TYPE (arg00)) | 7201 && TYPE_PRECISION (TREE_TYPE (arg00)) |
6896 == GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (arg00)))) | 7202 == GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (arg00)))) |
6897 { | 7203 { |
6898 tree stype = signed_type_for (TREE_TYPE (arg00)); | 7204 tree stype = signed_type_for (TREE_TYPE (arg00)); |
6899 return fold_build2 (code == EQ_EXPR ? GE_EXPR : LT_EXPR, | 7205 return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR, |
6900 result_type, fold_convert (stype, arg00), | 7206 result_type, |
7207 fold_convert_loc (loc, stype, arg00), | |
6901 build_int_cst (stype, 0)); | 7208 build_int_cst (stype, 0)); |
6902 } | 7209 } |
6903 } | 7210 } |
6904 | 7211 |
6905 return NULL_TREE; | 7212 return NULL_TREE; |
6909 equality/inequality test, then return a simplified form of | 7216 equality/inequality test, then return a simplified form of |
6910 the test using shifts and logical operations. Otherwise return | 7217 the test using shifts and logical operations. Otherwise return |
6911 NULL. TYPE is the desired result type. */ | 7218 NULL. TYPE is the desired result type. */ |
6912 | 7219 |
6913 tree | 7220 tree |
6914 fold_single_bit_test (enum tree_code code, tree arg0, tree arg1, | 7221 fold_single_bit_test (location_t loc, enum tree_code code, |
6915 tree result_type) | 7222 tree arg0, tree arg1, tree result_type) |
6916 { | 7223 { |
6917 /* If this is testing a single bit, we can optimize the test. */ | 7224 /* If this is testing a single bit, we can optimize the test. */ |
6918 if ((code == NE_EXPR || code == EQ_EXPR) | 7225 if ((code == NE_EXPR || code == EQ_EXPR) |
6919 && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1) | 7226 && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1) |
6920 && integer_pow2p (TREE_OPERAND (arg0, 1))) | 7227 && integer_pow2p (TREE_OPERAND (arg0, 1))) |
6927 tree signed_type, unsigned_type, intermediate_type; | 7234 tree signed_type, unsigned_type, intermediate_type; |
6928 tree tem, one; | 7235 tree tem, one; |
6929 | 7236 |
6930 /* First, see if we can fold the single bit test into a sign-bit | 7237 /* First, see if we can fold the single bit test into a sign-bit |
6931 test. */ | 7238 test. */ |
6932 tem = fold_single_bit_test_into_sign_test (code, arg0, arg1, | 7239 tem = fold_single_bit_test_into_sign_test (loc, code, arg0, arg1, |
6933 result_type); | 7240 result_type); |
6934 if (tem) | 7241 if (tem) |
6935 return tem; | 7242 return tem; |
6936 | 7243 |
6937 /* Otherwise we have (A & C) != 0 where C is a single bit, | 7244 /* Otherwise we have (A & C) != 0 where C is a single bit, |
6953 | 7260 |
6954 /* If we are going to be able to omit the AND below, we must do our | 7261 /* If we are going to be able to omit the AND below, we must do our |
6955 operations as unsigned. If we must use the AND, we have a choice. | 7262 operations as unsigned. If we must use the AND, we have a choice. |
6956 Normally unsigned is faster, but for some machines signed is. */ | 7263 Normally unsigned is faster, but for some machines signed is. */ |
6957 #ifdef LOAD_EXTEND_OP | 7264 #ifdef LOAD_EXTEND_OP |
6958 ops_unsigned = (LOAD_EXTEND_OP (operand_mode) == SIGN_EXTEND | 7265 ops_unsigned = (LOAD_EXTEND_OP (operand_mode) == SIGN_EXTEND |
6959 && !flag_syntax_only) ? 0 : 1; | 7266 && !flag_syntax_only) ? 0 : 1; |
6960 #else | 7267 #else |
6961 ops_unsigned = 1; | 7268 ops_unsigned = 1; |
6962 #endif | 7269 #endif |
6963 | 7270 |
6964 signed_type = lang_hooks.types.type_for_mode (operand_mode, 0); | 7271 signed_type = lang_hooks.types.type_for_mode (operand_mode, 0); |
6965 unsigned_type = lang_hooks.types.type_for_mode (operand_mode, 1); | 7272 unsigned_type = lang_hooks.types.type_for_mode (operand_mode, 1); |
6966 intermediate_type = ops_unsigned ? unsigned_type : signed_type; | 7273 intermediate_type = ops_unsigned ? unsigned_type : signed_type; |
6967 inner = fold_convert (intermediate_type, inner); | 7274 inner = fold_convert_loc (loc, intermediate_type, inner); |
6968 | 7275 |
6969 if (bitnum != 0) | 7276 if (bitnum != 0) |
6970 inner = build2 (RSHIFT_EXPR, intermediate_type, | 7277 inner = build2 (RSHIFT_EXPR, intermediate_type, |
6971 inner, size_int (bitnum)); | 7278 inner, size_int (bitnum)); |
6972 | 7279 |
6973 one = build_int_cst (intermediate_type, 1); | 7280 one = build_int_cst (intermediate_type, 1); |
6974 | 7281 |
6975 if (code == EQ_EXPR) | 7282 if (code == EQ_EXPR) |
6976 inner = fold_build2 (BIT_XOR_EXPR, intermediate_type, inner, one); | 7283 inner = fold_build2_loc (loc, BIT_XOR_EXPR, intermediate_type, inner, one); |
6977 | 7284 |
6978 /* Put the AND last so it can combine with more things. */ | 7285 /* Put the AND last so it can combine with more things. */ |
6979 inner = build2 (BIT_AND_EXPR, intermediate_type, inner, one); | 7286 inner = build2 (BIT_AND_EXPR, intermediate_type, inner, one); |
6980 | 7287 |
6981 /* Make sure to return the proper type. */ | 7288 /* Make sure to return the proper type. */ |
6982 inner = fold_convert (result_type, inner); | 7289 inner = fold_convert_loc (loc, result_type, inner); |
6983 | 7290 |
6984 return inner; | 7291 return inner; |
6985 } | 7292 } |
6986 return NULL_TREE; | 7293 return NULL_TREE; |
6987 } | 7294 } |
7069 | 7376 |
7070 /* Fold comparison ARG0 CODE ARG1 (with result in TYPE), where | 7377 /* Fold comparison ARG0 CODE ARG1 (with result in TYPE), where |
7071 ARG0 is extended to a wider type. */ | 7378 ARG0 is extended to a wider type. */ |
7072 | 7379 |
7073 static tree | 7380 static tree |
7074 fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1) | 7381 fold_widened_comparison (location_t loc, enum tree_code code, |
7382 tree type, tree arg0, tree arg1) | |
7075 { | 7383 { |
7076 tree arg0_unw = get_unwidened (arg0, NULL_TREE); | 7384 tree arg0_unw = get_unwidened (arg0, NULL_TREE); |
7077 tree arg1_unw; | 7385 tree arg1_unw; |
7078 tree shorter_type, outer_type; | 7386 tree shorter_type, outer_type; |
7079 tree min, max; | 7387 tree min, max; |
7107 == TYPE_UNSIGNED (TREE_TYPE (arg1_unw)))) | 7415 == TYPE_UNSIGNED (TREE_TYPE (arg1_unw)))) |
7108 || (TREE_CODE (arg1_unw) == INTEGER_CST | 7416 || (TREE_CODE (arg1_unw) == INTEGER_CST |
7109 && (TREE_CODE (shorter_type) == INTEGER_TYPE | 7417 && (TREE_CODE (shorter_type) == INTEGER_TYPE |
7110 || TREE_CODE (shorter_type) == BOOLEAN_TYPE) | 7418 || TREE_CODE (shorter_type) == BOOLEAN_TYPE) |
7111 && int_fits_type_p (arg1_unw, shorter_type)))) | 7419 && int_fits_type_p (arg1_unw, shorter_type)))) |
7112 return fold_build2 (code, type, arg0_unw, | 7420 return fold_build2_loc (loc, code, type, arg0_unw, |
7113 fold_convert (shorter_type, arg1_unw)); | 7421 fold_convert_loc (loc, shorter_type, arg1_unw)); |
7114 | 7422 |
7115 if (TREE_CODE (arg1_unw) != INTEGER_CST | 7423 if (TREE_CODE (arg1_unw) != INTEGER_CST |
7116 || TREE_CODE (shorter_type) != INTEGER_TYPE | 7424 || TREE_CODE (shorter_type) != INTEGER_TYPE |
7117 || !int_fits_type_p (arg1_unw, shorter_type)) | 7425 || !int_fits_type_p (arg1_unw, shorter_type)) |
7118 return NULL_TREE; | 7426 return NULL_TREE; |
7130 | 7438 |
7131 switch (code) | 7439 switch (code) |
7132 { | 7440 { |
7133 case EQ_EXPR: | 7441 case EQ_EXPR: |
7134 if (above || below) | 7442 if (above || below) |
7135 return omit_one_operand (type, integer_zero_node, arg0); | 7443 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
7136 break; | 7444 break; |
7137 | 7445 |
7138 case NE_EXPR: | 7446 case NE_EXPR: |
7139 if (above || below) | 7447 if (above || below) |
7140 return omit_one_operand (type, integer_one_node, arg0); | 7448 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
7141 break; | 7449 break; |
7142 | 7450 |
7143 case LT_EXPR: | 7451 case LT_EXPR: |
7144 case LE_EXPR: | 7452 case LE_EXPR: |
7145 if (above) | 7453 if (above) |
7146 return omit_one_operand (type, integer_one_node, arg0); | 7454 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
7147 else if (below) | 7455 else if (below) |
7148 return omit_one_operand (type, integer_zero_node, arg0); | 7456 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
7149 | 7457 |
7150 case GT_EXPR: | 7458 case GT_EXPR: |
7151 case GE_EXPR: | 7459 case GE_EXPR: |
7152 if (above) | 7460 if (above) |
7153 return omit_one_operand (type, integer_zero_node, arg0); | 7461 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
7154 else if (below) | 7462 else if (below) |
7155 return omit_one_operand (type, integer_one_node, arg0); | 7463 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
7156 | 7464 |
7157 default: | 7465 default: |
7158 break; | 7466 break; |
7159 } | 7467 } |
7160 | 7468 |
7163 | 7471 |
7164 /* Fold comparison ARG0 CODE ARG1 (with result in TYPE), where for | 7472 /* Fold comparison ARG0 CODE ARG1 (with result in TYPE), where for |
7165 ARG0 just the signedness is changed. */ | 7473 ARG0 just the signedness is changed. */ |
7166 | 7474 |
7167 static tree | 7475 static tree |
7168 fold_sign_changed_comparison (enum tree_code code, tree type, | 7476 fold_sign_changed_comparison (location_t loc, enum tree_code code, tree type, |
7169 tree arg0, tree arg1) | 7477 tree arg0, tree arg1) |
7170 { | 7478 { |
7171 tree arg0_inner; | 7479 tree arg0_inner; |
7172 tree inner_type, outer_type; | 7480 tree inner_type, outer_type; |
7173 | 7481 |
7188 #endif | 7496 #endif |
7189 | 7497 |
7190 if (TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type)) | 7498 if (TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type)) |
7191 return NULL_TREE; | 7499 return NULL_TREE; |
7192 | 7500 |
7193 /* If the conversion is from an integral subtype to its basetype | |
7194 leave it alone. */ | |
7195 if (TREE_TYPE (inner_type) == outer_type) | |
7196 return NULL_TREE; | |
7197 | |
7198 if (TREE_CODE (arg1) != INTEGER_CST | 7501 if (TREE_CODE (arg1) != INTEGER_CST |
7199 && !(CONVERT_EXPR_P (arg1) | 7502 && !(CONVERT_EXPR_P (arg1) |
7200 && TREE_TYPE (TREE_OPERAND (arg1, 0)) == inner_type)) | 7503 && TREE_TYPE (TREE_OPERAND (arg1, 0)) == inner_type)) |
7201 return NULL_TREE; | 7504 return NULL_TREE; |
7202 | 7505 |
7209 if (TREE_CODE (arg1) == INTEGER_CST) | 7512 if (TREE_CODE (arg1) == INTEGER_CST) |
7210 arg1 = force_fit_type_double (inner_type, TREE_INT_CST_LOW (arg1), | 7513 arg1 = force_fit_type_double (inner_type, TREE_INT_CST_LOW (arg1), |
7211 TREE_INT_CST_HIGH (arg1), 0, | 7514 TREE_INT_CST_HIGH (arg1), 0, |
7212 TREE_OVERFLOW (arg1)); | 7515 TREE_OVERFLOW (arg1)); |
7213 else | 7516 else |
7214 arg1 = fold_convert (inner_type, arg1); | 7517 arg1 = fold_convert_loc (loc, inner_type, arg1); |
7215 | 7518 |
7216 return fold_build2 (code, type, arg0_inner, arg1); | 7519 return fold_build2_loc (loc, code, type, arg0_inner, arg1); |
7217 } | 7520 } |
7218 | 7521 |
7219 /* Tries to replace &a[idx] p+ s * delta with &a[idx + delta], if s is | 7522 /* Tries to replace &a[idx] p+ s * delta with &a[idx + delta], if s is |
7220 step of the array. Reconstructs s and delta in the case of s * delta | 7523 step of the array. Reconstructs s and delta in the case of s * |
7221 being an integer constant (and thus already folded). | 7524 delta being an integer constant (and thus already folded). ADDR is |
7222 ADDR is the address. MULT is the multiplicative expression. | 7525 the address. MULT is the multiplicative expression. If the |
7223 If the function succeeds, the new address expression is returned. Otherwise | 7526 function succeeds, the new address expression is returned. |
7224 NULL_TREE is returned. */ | 7527 Otherwise NULL_TREE is returned. LOC is the location of the |
7528 resulting expression. */ | |
7225 | 7529 |
7226 static tree | 7530 static tree |
7227 try_move_mult_to_index (tree addr, tree op1) | 7531 try_move_mult_to_index (location_t loc, tree addr, tree op1) |
7228 { | 7532 { |
7229 tree s, delta, step; | 7533 tree s, delta, step; |
7230 tree ref = TREE_OPERAND (addr, 0), pref; | 7534 tree ref = TREE_OPERAND (addr, 0), pref; |
7231 tree ret, pos; | 7535 tree ret, pos; |
7232 tree itype; | 7536 tree itype; |
7241 { | 7545 { |
7242 tree arg0 = TREE_OPERAND (op1, 0), arg1 = TREE_OPERAND (op1, 1); | 7546 tree arg0 = TREE_OPERAND (op1, 0), arg1 = TREE_OPERAND (op1, 1); |
7243 | 7547 |
7244 STRIP_NOPS (arg0); | 7548 STRIP_NOPS (arg0); |
7245 STRIP_NOPS (arg1); | 7549 STRIP_NOPS (arg1); |
7246 | 7550 |
7247 if (TREE_CODE (arg0) == INTEGER_CST) | 7551 if (TREE_CODE (arg0) == INTEGER_CST) |
7248 { | 7552 { |
7249 s = arg0; | 7553 s = arg0; |
7250 delta = arg1; | 7554 delta = arg1; |
7251 } | 7555 } |
7271 | 7575 |
7272 for (;; ref = TREE_OPERAND (ref, 0)) | 7576 for (;; ref = TREE_OPERAND (ref, 0)) |
7273 { | 7577 { |
7274 if (TREE_CODE (ref) == ARRAY_REF) | 7578 if (TREE_CODE (ref) == ARRAY_REF) |
7275 { | 7579 { |
7580 tree domain; | |
7581 | |
7276 /* Remember if this was a multi-dimensional array. */ | 7582 /* Remember if this was a multi-dimensional array. */ |
7277 if (TREE_CODE (TREE_OPERAND (ref, 0)) == ARRAY_REF) | 7583 if (TREE_CODE (TREE_OPERAND (ref, 0)) == ARRAY_REF) |
7278 mdim = true; | 7584 mdim = true; |
7279 | 7585 |
7280 itype = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (ref, 0))); | 7586 domain = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (ref, 0))); |
7281 if (! itype) | 7587 if (! domain) |
7282 continue; | 7588 continue; |
7589 itype = TREE_TYPE (domain); | |
7283 | 7590 |
7284 step = array_ref_element_size (ref); | 7591 step = array_ref_element_size (ref); |
7285 if (TREE_CODE (step) != INTEGER_CST) | 7592 if (TREE_CODE (step) != INTEGER_CST) |
7286 continue; | 7593 continue; |
7287 | 7594 |
7304 if (mdim) | 7611 if (mdim) |
7305 { | 7612 { |
7306 tree tmp; | 7613 tree tmp; |
7307 | 7614 |
7308 if (TREE_CODE (TREE_OPERAND (ref, 1)) != INTEGER_CST | 7615 if (TREE_CODE (TREE_OPERAND (ref, 1)) != INTEGER_CST |
7309 || !INTEGRAL_TYPE_P (itype) | 7616 || !TYPE_MAX_VALUE (domain) |
7310 || !TYPE_MAX_VALUE (itype) | 7617 || TREE_CODE (TYPE_MAX_VALUE (domain)) != INTEGER_CST) |
7311 || TREE_CODE (TYPE_MAX_VALUE (itype)) != INTEGER_CST) | |
7312 continue; | 7618 continue; |
7313 | 7619 |
7314 tmp = fold_binary (PLUS_EXPR, itype, | 7620 tmp = fold_binary_loc (loc, PLUS_EXPR, itype, |
7315 fold_convert (itype, | 7621 fold_convert_loc (loc, itype, |
7316 TREE_OPERAND (ref, 1)), | 7622 TREE_OPERAND (ref, 1)), |
7317 fold_convert (itype, delta)); | 7623 fold_convert_loc (loc, itype, delta)); |
7318 if (!tmp | 7624 if (!tmp |
7319 || TREE_CODE (tmp) != INTEGER_CST | 7625 || TREE_CODE (tmp) != INTEGER_CST |
7320 || tree_int_cst_lt (TYPE_MAX_VALUE (itype), tmp)) | 7626 || tree_int_cst_lt (TYPE_MAX_VALUE (domain), tmp)) |
7321 continue; | 7627 continue; |
7322 } | 7628 } |
7323 | 7629 |
7324 break; | 7630 break; |
7325 } | 7631 } |
7333 /* We found the suitable array reference. So copy everything up to it, | 7639 /* We found the suitable array reference. So copy everything up to it, |
7334 and replace the index. */ | 7640 and replace the index. */ |
7335 | 7641 |
7336 pref = TREE_OPERAND (addr, 0); | 7642 pref = TREE_OPERAND (addr, 0); |
7337 ret = copy_node (pref); | 7643 ret = copy_node (pref); |
7644 SET_EXPR_LOCATION (ret, loc); | |
7338 pos = ret; | 7645 pos = ret; |
7339 | 7646 |
7340 while (pref != ref) | 7647 while (pref != ref) |
7341 { | 7648 { |
7342 pref = TREE_OPERAND (pref, 0); | 7649 pref = TREE_OPERAND (pref, 0); |
7343 TREE_OPERAND (pos, 0) = copy_node (pref); | 7650 TREE_OPERAND (pos, 0) = copy_node (pref); |
7344 pos = TREE_OPERAND (pos, 0); | 7651 pos = TREE_OPERAND (pos, 0); |
7345 } | 7652 } |
7346 | 7653 |
7347 TREE_OPERAND (pos, 1) = fold_build2 (PLUS_EXPR, itype, | 7654 TREE_OPERAND (pos, 1) = fold_build2_loc (loc, PLUS_EXPR, itype, |
7348 fold_convert (itype, | 7655 fold_convert_loc (loc, itype, |
7349 TREE_OPERAND (pos, 1)), | 7656 TREE_OPERAND (pos, 1)), |
7350 fold_convert (itype, delta)); | 7657 fold_convert_loc (loc, itype, delta)); |
7351 | 7658 |
7352 return fold_build1 (ADDR_EXPR, TREE_TYPE (addr), ret); | 7659 return fold_build1_loc (loc, ADDR_EXPR, TREE_TYPE (addr), ret); |
7353 } | 7660 } |
7354 | 7661 |
7355 | 7662 |
7356 /* Fold A < X && A + 1 > Y to A < X && A >= Y. Normally A + 1 > Y | 7663 /* Fold A < X && A + 1 > Y to A < X && A >= Y. Normally A + 1 > Y |
7357 means A >= Y && A != MAX, but in this case we know that | 7664 means A >= Y && A != MAX, but in this case we know that |
7358 A < X <= MAX. INEQ is A + 1 > Y, BOUND is A < X. */ | 7665 A < X <= MAX. INEQ is A + 1 > Y, BOUND is A < X. */ |
7359 | 7666 |
7360 static tree | 7667 static tree |
7361 fold_to_nonsharp_ineq_using_bound (tree ineq, tree bound) | 7668 fold_to_nonsharp_ineq_using_bound (location_t loc, tree ineq, tree bound) |
7362 { | 7669 { |
7363 tree a, typea, type = TREE_TYPE (ineq), a1, diff, y; | 7670 tree a, typea, type = TREE_TYPE (ineq), a1, diff, y; |
7364 | 7671 |
7365 if (TREE_CODE (bound) == LT_EXPR) | 7672 if (TREE_CODE (bound) == LT_EXPR) |
7366 a = TREE_OPERAND (bound, 0); | 7673 a = TREE_OPERAND (bound, 0); |
7391 return NULL_TREE; | 7698 return NULL_TREE; |
7392 | 7699 |
7393 if (POINTER_TYPE_P (typea)) | 7700 if (POINTER_TYPE_P (typea)) |
7394 { | 7701 { |
7395 /* Convert the pointer types into integer before taking the difference. */ | 7702 /* Convert the pointer types into integer before taking the difference. */ |
7396 tree ta = fold_convert (ssizetype, a); | 7703 tree ta = fold_convert_loc (loc, ssizetype, a); |
7397 tree ta1 = fold_convert (ssizetype, a1); | 7704 tree ta1 = fold_convert_loc (loc, ssizetype, a1); |
7398 diff = fold_binary (MINUS_EXPR, ssizetype, ta1, ta); | 7705 diff = fold_binary_loc (loc, MINUS_EXPR, ssizetype, ta1, ta); |
7399 } | 7706 } |
7400 else | 7707 else |
7401 diff = fold_binary (MINUS_EXPR, typea, a1, a); | 7708 diff = fold_binary_loc (loc, MINUS_EXPR, typea, a1, a); |
7402 | 7709 |
7403 if (!diff || !integer_onep (diff)) | 7710 if (!diff || !integer_onep (diff)) |
7404 return NULL_TREE; | 7711 return NULL_TREE; |
7405 | 7712 |
7406 return fold_build2 (GE_EXPR, type, a, y); | 7713 return fold_build2_loc (loc, GE_EXPR, type, a, y); |
7407 } | 7714 } |
7408 | 7715 |
7409 /* Fold a sum or difference of at least one multiplication. | 7716 /* Fold a sum or difference of at least one multiplication. |
7410 Returns the folded tree or NULL if no simplification could be made. */ | 7717 Returns the folded tree or NULL if no simplification could be made. */ |
7411 | 7718 |
7412 static tree | 7719 static tree |
7413 fold_plusminus_mult_expr (enum tree_code code, tree type, tree arg0, tree arg1) | 7720 fold_plusminus_mult_expr (location_t loc, enum tree_code code, tree type, |
7721 tree arg0, tree arg1) | |
7414 { | 7722 { |
7415 tree arg00, arg01, arg10, arg11; | 7723 tree arg00, arg01, arg10, arg11; |
7416 tree alt0 = NULL_TREE, alt1 = NULL_TREE, same; | 7724 tree alt0 = NULL_TREE, alt1 = NULL_TREE, same; |
7417 | 7725 |
7418 /* (A * C) +- (B * C) -> (A+-B) * C. | 7726 /* (A * C) +- (B * C) -> (A+-B) * C. |
7500 swap = true; | 7808 swap = true; |
7501 } | 7809 } |
7502 else | 7810 else |
7503 maybe_same = arg11; | 7811 maybe_same = arg11; |
7504 | 7812 |
7505 if (exact_log2 (abs (int11)) > 0 && int01 % int11 == 0) | 7813 if (exact_log2 (abs (int11)) > 0 && int01 % int11 == 0 |
7814 /* The remainder should not be a constant, otherwise we | |
7815 end up folding i * 4 + 2 to (i * 2 + 1) * 2 which has | |
7816 increased the number of multiplications necessary. */ | |
7817 && TREE_CODE (arg10) != INTEGER_CST) | |
7506 { | 7818 { |
7507 alt0 = fold_build2 (MULT_EXPR, TREE_TYPE (arg00), arg00, | 7819 alt0 = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (arg00), arg00, |
7508 build_int_cst (TREE_TYPE (arg00), | 7820 build_int_cst (TREE_TYPE (arg00), |
7509 int01 / int11)); | 7821 int01 / int11)); |
7510 alt1 = arg10; | 7822 alt1 = arg10; |
7511 same = maybe_same; | 7823 same = maybe_same; |
7512 if (swap) | 7824 if (swap) |
7513 maybe_same = alt0, alt0 = alt1, alt1 = maybe_same; | 7825 maybe_same = alt0, alt0 = alt1, alt1 = maybe_same; |
7514 } | 7826 } |
7515 } | 7827 } |
7516 | 7828 |
7517 if (same) | 7829 if (same) |
7518 return fold_build2 (MULT_EXPR, type, | 7830 return fold_build2_loc (loc, MULT_EXPR, type, |
7519 fold_build2 (code, type, | 7831 fold_build2_loc (loc, code, type, |
7520 fold_convert (type, alt0), | 7832 fold_convert_loc (loc, type, alt0), |
7521 fold_convert (type, alt1)), | 7833 fold_convert_loc (loc, type, alt1)), |
7522 fold_convert (type, same)); | 7834 fold_convert_loc (loc, type, same)); |
7523 | 7835 |
7524 return NULL_TREE; | 7836 return NULL_TREE; |
7525 } | 7837 } |
7526 | 7838 |
7527 /* Subroutine of native_encode_expr. Encode the INTEGER_CST | 7839 /* Subroutine of native_encode_expr. Encode the INTEGER_CST |
7947 | 8259 |
7948 return native_interpret_expr (type, buffer, len); | 8260 return native_interpret_expr (type, buffer, len); |
7949 } | 8261 } |
7950 | 8262 |
7951 /* Build an expression for the address of T. Folds away INDIRECT_REF | 8263 /* Build an expression for the address of T. Folds away INDIRECT_REF |
7952 to avoid confusing the gimplify process. When IN_FOLD is true | 8264 to avoid confusing the gimplify process. */ |
7953 avoid modifications of T. */ | 8265 |
7954 | 8266 tree |
7955 static tree | 8267 build_fold_addr_expr_with_type_loc (location_t loc, tree t, tree ptrtype) |
7956 build_fold_addr_expr_with_type_1 (tree t, tree ptrtype, bool in_fold) | |
7957 { | 8268 { |
7958 /* The size of the object is not relevant when talking about its address. */ | 8269 /* The size of the object is not relevant when talking about its address. */ |
7959 if (TREE_CODE (t) == WITH_SIZE_EXPR) | 8270 if (TREE_CODE (t) == WITH_SIZE_EXPR) |
7960 t = TREE_OPERAND (t, 0); | 8271 t = TREE_OPERAND (t, 0); |
7961 | 8272 |
7964 || TREE_CODE (t) == MISALIGNED_INDIRECT_REF) | 8275 || TREE_CODE (t) == MISALIGNED_INDIRECT_REF) |
7965 { | 8276 { |
7966 t = TREE_OPERAND (t, 0); | 8277 t = TREE_OPERAND (t, 0); |
7967 | 8278 |
7968 if (TREE_TYPE (t) != ptrtype) | 8279 if (TREE_TYPE (t) != ptrtype) |
7969 t = build1 (NOP_EXPR, ptrtype, t); | 8280 { |
7970 } | 8281 t = build1 (NOP_EXPR, ptrtype, t); |
7971 else if (!in_fold) | 8282 SET_EXPR_LOCATION (t, loc); |
7972 { | 8283 } |
7973 tree base = t; | 8284 } |
7974 | 8285 else if (TREE_CODE (t) == VIEW_CONVERT_EXPR) |
7975 while (handled_component_p (base)) | 8286 { |
7976 base = TREE_OPERAND (base, 0); | 8287 t = build_fold_addr_expr_loc (loc, TREE_OPERAND (t, 0)); |
7977 | 8288 |
7978 if (DECL_P (base)) | 8289 if (TREE_TYPE (t) != ptrtype) |
7979 TREE_ADDRESSABLE (base) = 1; | 8290 t = fold_convert_loc (loc, ptrtype, t); |
7980 | 8291 } |
8292 else | |
8293 { | |
7981 t = build1 (ADDR_EXPR, ptrtype, t); | 8294 t = build1 (ADDR_EXPR, ptrtype, t); |
7982 } | 8295 SET_EXPR_LOCATION (t, loc); |
7983 else | 8296 } |
7984 t = build1 (ADDR_EXPR, ptrtype, t); | |
7985 | 8297 |
7986 return t; | 8298 return t; |
7987 } | 8299 } |
7988 | 8300 |
7989 /* Build an expression for the address of T with type PTRTYPE. This | 8301 /* Build an expression for the address of T. */ |
7990 function modifies the input parameter 'T' by sometimes setting the | |
7991 TREE_ADDRESSABLE flag. */ | |
7992 | 8302 |
7993 tree | 8303 tree |
7994 build_fold_addr_expr_with_type (tree t, tree ptrtype) | 8304 build_fold_addr_expr_loc (location_t loc, tree t) |
7995 { | |
7996 return build_fold_addr_expr_with_type_1 (t, ptrtype, false); | |
7997 } | |
7998 | |
7999 /* Build an expression for the address of T. This function modifies | |
8000 the input parameter 'T' by sometimes setting the TREE_ADDRESSABLE | |
8001 flag. When called from fold functions, use fold_addr_expr instead. */ | |
8002 | |
8003 tree | |
8004 build_fold_addr_expr (tree t) | |
8005 { | |
8006 return build_fold_addr_expr_with_type_1 (t, | |
8007 build_pointer_type (TREE_TYPE (t)), | |
8008 false); | |
8009 } | |
8010 | |
8011 /* Same as build_fold_addr_expr, builds an expression for the address | |
8012 of T, but avoids touching the input node 't'. Fold functions | |
8013 should use this version. */ | |
8014 | |
8015 static tree | |
8016 fold_addr_expr (tree t) | |
8017 { | 8305 { |
8018 tree ptrtype = build_pointer_type (TREE_TYPE (t)); | 8306 tree ptrtype = build_pointer_type (TREE_TYPE (t)); |
8019 | 8307 |
8020 return build_fold_addr_expr_with_type_1 (t, ptrtype, true); | 8308 return build_fold_addr_expr_with_type_loc (loc, t, ptrtype); |
8021 } | 8309 } |
8022 | 8310 |
8023 /* Fold a unary expression of code CODE and type TYPE with operand | 8311 /* Fold a unary expression of code CODE and type TYPE with operand |
8024 OP0. Return the folded expression if folding is successful. | 8312 OP0. Return the folded expression if folding is successful. |
8025 Otherwise, return NULL_TREE. */ | 8313 Otherwise, return NULL_TREE. */ |
8026 | 8314 |
8027 tree | 8315 tree |
8028 fold_unary (enum tree_code code, tree type, tree op0) | 8316 fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0) |
8029 { | 8317 { |
8030 tree tem; | 8318 tree tem; |
8031 tree arg0; | 8319 tree arg0; |
8032 enum tree_code_class kind = TREE_CODE_CLASS (code); | 8320 enum tree_code_class kind = TREE_CODE_CLASS (code); |
8033 | 8321 |
8063 | 8351 |
8064 if (TREE_CODE_CLASS (code) == tcc_unary) | 8352 if (TREE_CODE_CLASS (code) == tcc_unary) |
8065 { | 8353 { |
8066 if (TREE_CODE (arg0) == COMPOUND_EXPR) | 8354 if (TREE_CODE (arg0) == COMPOUND_EXPR) |
8067 return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0), | 8355 return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0), |
8068 fold_build1 (code, type, | 8356 fold_build1_loc (loc, code, type, |
8069 fold_convert (TREE_TYPE (op0), | 8357 fold_convert_loc (loc, TREE_TYPE (op0), |
8070 TREE_OPERAND (arg0, 1)))); | 8358 TREE_OPERAND (arg0, 1)))); |
8071 else if (TREE_CODE (arg0) == COND_EXPR) | 8359 else if (TREE_CODE (arg0) == COND_EXPR) |
8072 { | 8360 { |
8073 tree arg01 = TREE_OPERAND (arg0, 1); | 8361 tree arg01 = TREE_OPERAND (arg0, 1); |
8074 tree arg02 = TREE_OPERAND (arg0, 2); | 8362 tree arg02 = TREE_OPERAND (arg0, 2); |
8075 if (! VOID_TYPE_P (TREE_TYPE (arg01))) | 8363 if (! VOID_TYPE_P (TREE_TYPE (arg01))) |
8076 arg01 = fold_build1 (code, type, | 8364 arg01 = fold_build1_loc (loc, code, type, |
8077 fold_convert (TREE_TYPE (op0), arg01)); | 8365 fold_convert_loc (loc, |
8366 TREE_TYPE (op0), arg01)); | |
8078 if (! VOID_TYPE_P (TREE_TYPE (arg02))) | 8367 if (! VOID_TYPE_P (TREE_TYPE (arg02))) |
8079 arg02 = fold_build1 (code, type, | 8368 arg02 = fold_build1_loc (loc, code, type, |
8080 fold_convert (TREE_TYPE (op0), arg02)); | 8369 fold_convert_loc (loc, |
8081 tem = fold_build3 (COND_EXPR, type, TREE_OPERAND (arg0, 0), | 8370 TREE_TYPE (op0), arg02)); |
8371 tem = fold_build3_loc (loc, COND_EXPR, type, TREE_OPERAND (arg0, 0), | |
8082 arg01, arg02); | 8372 arg01, arg02); |
8083 | 8373 |
8084 /* If this was a conversion, and all we did was to move into | 8374 /* If this was a conversion, and all we did was to move into |
8085 inside the COND_EXPR, bring it back out. But leave it if | 8375 inside the COND_EXPR, bring it back out. But leave it if |
8086 it is a conversion from integer to integer and the | 8376 it is a conversion from integer to integer and the |
8102 && (! (INTEGRAL_TYPE_P (TREE_TYPE (tem)) | 8392 && (! (INTEGRAL_TYPE_P (TREE_TYPE (tem)) |
8103 && (INTEGRAL_TYPE_P | 8393 && (INTEGRAL_TYPE_P |
8104 (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (tem, 1), 0)))) | 8394 (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (tem, 1), 0)))) |
8105 && TYPE_PRECISION (TREE_TYPE (tem)) <= BITS_PER_WORD) | 8395 && TYPE_PRECISION (TREE_TYPE (tem)) <= BITS_PER_WORD) |
8106 || flag_syntax_only)) | 8396 || flag_syntax_only)) |
8107 tem = build1 (code, type, | 8397 { |
8108 build3 (COND_EXPR, | 8398 tem = build1 (code, type, |
8109 TREE_TYPE (TREE_OPERAND | 8399 build3 (COND_EXPR, |
8110 (TREE_OPERAND (tem, 1), 0)), | 8400 TREE_TYPE (TREE_OPERAND |
8111 TREE_OPERAND (tem, 0), | 8401 (TREE_OPERAND (tem, 1), 0)), |
8112 TREE_OPERAND (TREE_OPERAND (tem, 1), 0), | 8402 TREE_OPERAND (tem, 0), |
8113 TREE_OPERAND (TREE_OPERAND (tem, 2), 0))); | 8403 TREE_OPERAND (TREE_OPERAND (tem, 1), 0), |
8404 TREE_OPERAND (TREE_OPERAND (tem, 2), 0))); | |
8405 SET_EXPR_LOCATION (tem, loc); | |
8406 } | |
8114 return tem; | 8407 return tem; |
8115 } | 8408 } |
8116 else if (COMPARISON_CLASS_P (arg0)) | 8409 else if (COMPARISON_CLASS_P (arg0)) |
8117 { | 8410 { |
8118 if (TREE_CODE (type) == BOOLEAN_TYPE) | 8411 if (TREE_CODE (type) == BOOLEAN_TYPE) |
8120 arg0 = copy_node (arg0); | 8413 arg0 = copy_node (arg0); |
8121 TREE_TYPE (arg0) = type; | 8414 TREE_TYPE (arg0) = type; |
8122 return arg0; | 8415 return arg0; |
8123 } | 8416 } |
8124 else if (TREE_CODE (type) != INTEGER_TYPE) | 8417 else if (TREE_CODE (type) != INTEGER_TYPE) |
8125 return fold_build3 (COND_EXPR, type, arg0, | 8418 return fold_build3_loc (loc, COND_EXPR, type, arg0, |
8126 fold_build1 (code, type, | 8419 fold_build1_loc (loc, code, type, |
8127 integer_one_node), | 8420 integer_one_node), |
8128 fold_build1 (code, type, | 8421 fold_build1_loc (loc, code, type, |
8129 integer_zero_node)); | 8422 integer_zero_node)); |
8130 } | 8423 } |
8131 } | 8424 } |
8132 | 8425 |
8133 switch (code) | 8426 switch (code) |
8135 case PAREN_EXPR: | 8428 case PAREN_EXPR: |
8136 /* Re-association barriers around constants and other re-association | 8429 /* Re-association barriers around constants and other re-association |
8137 barriers can be removed. */ | 8430 barriers can be removed. */ |
8138 if (CONSTANT_CLASS_P (op0) | 8431 if (CONSTANT_CLASS_P (op0) |
8139 || TREE_CODE (op0) == PAREN_EXPR) | 8432 || TREE_CODE (op0) == PAREN_EXPR) |
8140 return fold_convert (type, op0); | 8433 return fold_convert_loc (loc, type, op0); |
8141 return NULL_TREE; | 8434 return NULL_TREE; |
8142 | 8435 |
8143 CASE_CONVERT: | 8436 CASE_CONVERT: |
8144 case FLOAT_EXPR: | 8437 case FLOAT_EXPR: |
8145 case FIX_TRUNC_EXPR: | 8438 case FIX_TRUNC_EXPR: |
8146 if (TREE_TYPE (op0) == type) | 8439 if (TREE_TYPE (op0) == type) |
8147 return op0; | 8440 return op0; |
8148 | 8441 |
8149 /* If we have (type) (a CMP b) and type is an integral type, return | 8442 /* If we have (type) (a CMP b) and type is an integral type, return |
8150 new expression involving the new type. */ | 8443 new expression involving the new type. */ |
8151 if (COMPARISON_CLASS_P (op0) && INTEGRAL_TYPE_P (type)) | 8444 if (COMPARISON_CLASS_P (op0) && INTEGRAL_TYPE_P (type)) |
8152 return fold_build2 (TREE_CODE (op0), type, TREE_OPERAND (op0, 0), | 8445 return fold_build2_loc (loc, TREE_CODE (op0), type, TREE_OPERAND (op0, 0), |
8153 TREE_OPERAND (op0, 1)); | 8446 TREE_OPERAND (op0, 1)); |
8154 | 8447 |
8155 /* Handle cases of two conversions in a row. */ | 8448 /* Handle cases of two conversions in a row. */ |
8156 if (CONVERT_EXPR_P (op0)) | 8449 if (CONVERT_EXPR_P (op0)) |
8157 { | 8450 { |
8182 conversion is needed. */ | 8475 conversion is needed. */ |
8183 if (TYPE_MAIN_VARIANT (inside_type) == TYPE_MAIN_VARIANT (type) | 8476 if (TYPE_MAIN_VARIANT (inside_type) == TYPE_MAIN_VARIANT (type) |
8184 && (((inter_int || inter_ptr) && final_int) | 8477 && (((inter_int || inter_ptr) && final_int) |
8185 || (inter_float && final_float)) | 8478 || (inter_float && final_float)) |
8186 && inter_prec >= final_prec) | 8479 && inter_prec >= final_prec) |
8187 return fold_build1 (code, type, TREE_OPERAND (op0, 0)); | 8480 return fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 0)); |
8188 | 8481 |
8189 /* Likewise, if the intermediate and initial types are either both | 8482 /* Likewise, if the intermediate and initial types are either both |
8190 float or both integer, we don't need the middle conversion if the | 8483 float or both integer, we don't need the middle conversion if the |
8191 former is wider than the latter and doesn't change the signedness | 8484 former is wider than the latter and doesn't change the signedness |
8192 (for integers). Avoid this if the final type is a pointer since | 8485 (for integers). Avoid this if the final type is a pointer since |
8200 || inter_unsignedp == inside_unsignedp) | 8493 || inter_unsignedp == inside_unsignedp) |
8201 && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (type)) | 8494 && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (type)) |
8202 && TYPE_MODE (type) == TYPE_MODE (inter_type)) | 8495 && TYPE_MODE (type) == TYPE_MODE (inter_type)) |
8203 && ! final_ptr | 8496 && ! final_ptr |
8204 && (! final_vec || inter_prec == inside_prec)) | 8497 && (! final_vec || inter_prec == inside_prec)) |
8205 return fold_build1 (code, type, TREE_OPERAND (op0, 0)); | 8498 return fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 0)); |
8206 | 8499 |
8207 /* If we have a sign-extension of a zero-extended value, we can | 8500 /* If we have a sign-extension of a zero-extended value, we can |
8208 replace that by a single zero-extension. */ | 8501 replace that by a single zero-extension. */ |
8209 if (inside_int && inter_int && final_int | 8502 if (inside_int && inter_int && final_int |
8210 && inside_prec < inter_prec && inter_prec < final_prec | 8503 && inside_prec < inter_prec && inter_prec < final_prec |
8211 && inside_unsignedp && !inter_unsignedp) | 8504 && inside_unsignedp && !inter_unsignedp) |
8212 return fold_build1 (code, type, TREE_OPERAND (op0, 0)); | 8505 return fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 0)); |
8213 | 8506 |
8214 /* Two conversions in a row are not needed unless: | 8507 /* Two conversions in a row are not needed unless: |
8215 - some conversion is floating-point (overstrict for now), or | 8508 - some conversion is floating-point (overstrict for now), or |
8216 - some conversion is a vector (overstrict for now), or | 8509 - some conversion is a vector (overstrict for now), or |
8217 - the intermediate type is narrower than both initial and | 8510 - the intermediate type is narrower than both initial and |
8232 == (final_unsignedp && final_prec > inter_prec)) | 8525 == (final_unsignedp && final_prec > inter_prec)) |
8233 && ! (inside_ptr && inter_prec != final_prec) | 8526 && ! (inside_ptr && inter_prec != final_prec) |
8234 && ! (final_ptr && inside_prec != inter_prec) | 8527 && ! (final_ptr && inside_prec != inter_prec) |
8235 && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (type)) | 8528 && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (type)) |
8236 && TYPE_MODE (type) == TYPE_MODE (inter_type))) | 8529 && TYPE_MODE (type) == TYPE_MODE (inter_type))) |
8237 return fold_build1 (code, type, TREE_OPERAND (op0, 0)); | 8530 return fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 0)); |
8238 } | 8531 } |
8239 | 8532 |
8240 /* Handle (T *)&A.B.C for A being of type T and B and C | 8533 /* Handle (T *)&A.B.C for A being of type T and B and C |
8241 living at offset zero. This occurs frequently in | 8534 living at offset zero. This occurs frequently in |
8242 C++ upcasting and then accessing the base. */ | 8535 C++ upcasting and then accessing the base. */ |
8255 the address of the base if it has the same base type | 8548 the address of the base if it has the same base type |
8256 as the result type. */ | 8549 as the result type. */ |
8257 if (! offset && bitpos == 0 | 8550 if (! offset && bitpos == 0 |
8258 && TYPE_MAIN_VARIANT (TREE_TYPE (type)) | 8551 && TYPE_MAIN_VARIANT (TREE_TYPE (type)) |
8259 == TYPE_MAIN_VARIANT (TREE_TYPE (base))) | 8552 == TYPE_MAIN_VARIANT (TREE_TYPE (base))) |
8260 return fold_convert (type, fold_addr_expr (base)); | 8553 return fold_convert_loc (loc, type, |
8554 build_fold_addr_expr_loc (loc, base)); | |
8261 } | 8555 } |
8262 | 8556 |
8263 if (TREE_CODE (op0) == MODIFY_EXPR | 8557 if (TREE_CODE (op0) == MODIFY_EXPR |
8264 && TREE_CONSTANT (TREE_OPERAND (op0, 1)) | 8558 && TREE_CONSTANT (TREE_OPERAND (op0, 1)) |
8265 /* Detect assigning a bitfield. */ | 8559 /* Detect assigning a bitfield. */ |
8267 && DECL_BIT_FIELD | 8561 && DECL_BIT_FIELD |
8268 (TREE_OPERAND (TREE_OPERAND (op0, 0), 1)))) | 8562 (TREE_OPERAND (TREE_OPERAND (op0, 0), 1)))) |
8269 { | 8563 { |
8270 /* Don't leave an assignment inside a conversion | 8564 /* Don't leave an assignment inside a conversion |
8271 unless assigning a bitfield. */ | 8565 unless assigning a bitfield. */ |
8272 tem = fold_build1 (code, type, TREE_OPERAND (op0, 1)); | 8566 tem = fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 1)); |
8273 /* First do the assignment, then return converted constant. */ | 8567 /* First do the assignment, then return converted constant. */ |
8274 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem), op0, tem); | 8568 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem), op0, tem); |
8275 TREE_NO_WARNING (tem) = 1; | 8569 TREE_NO_WARNING (tem) = 1; |
8276 TREE_USED (tem) = 1; | 8570 TREE_USED (tem) = 1; |
8571 SET_EXPR_LOCATION (tem, loc); | |
8277 return tem; | 8572 return tem; |
8278 } | 8573 } |
8279 | 8574 |
8280 /* Convert (T)(x & c) into (T)x & (T)c, if c is an integer | 8575 /* Convert (T)(x & c) into (T)x & (T)c, if c is an integer |
8281 constants (if x has signed type, the sign bit cannot be set | 8576 constants (if x has signed type, the sign bit cannot be set |
8283 ??? We don't do it for BOOLEAN_TYPE or ENUMERAL_TYPE because they | 8578 ??? We don't do it for BOOLEAN_TYPE or ENUMERAL_TYPE because they |
8284 very likely don't have maximal range for their precision and this | 8579 very likely don't have maximal range for their precision and this |
8285 transformation effectively doesn't preserve non-maximal ranges. */ | 8580 transformation effectively doesn't preserve non-maximal ranges. */ |
8286 if (TREE_CODE (type) == INTEGER_TYPE | 8581 if (TREE_CODE (type) == INTEGER_TYPE |
8287 && TREE_CODE (op0) == BIT_AND_EXPR | 8582 && TREE_CODE (op0) == BIT_AND_EXPR |
8288 && TREE_CODE (TREE_OPERAND (op0, 1)) == INTEGER_CST | 8583 && TREE_CODE (TREE_OPERAND (op0, 1)) == INTEGER_CST) |
8289 /* Not if the conversion is to the sub-type. */ | 8584 { |
8290 && TREE_TYPE (type) != TREE_TYPE (op0)) | 8585 tree and_expr = op0; |
8291 { | 8586 tree and0 = TREE_OPERAND (and_expr, 0); |
8292 tree and = op0; | 8587 tree and1 = TREE_OPERAND (and_expr, 1); |
8293 tree and0 = TREE_OPERAND (and, 0), and1 = TREE_OPERAND (and, 1); | |
8294 int change = 0; | 8588 int change = 0; |
8295 | 8589 |
8296 if (TYPE_UNSIGNED (TREE_TYPE (and)) | 8590 if (TYPE_UNSIGNED (TREE_TYPE (and_expr)) |
8297 || (TYPE_PRECISION (type) | 8591 || (TYPE_PRECISION (type) |
8298 <= TYPE_PRECISION (TREE_TYPE (and)))) | 8592 <= TYPE_PRECISION (TREE_TYPE (and_expr)))) |
8299 change = 1; | 8593 change = 1; |
8300 else if (TYPE_PRECISION (TREE_TYPE (and1)) | 8594 else if (TYPE_PRECISION (TREE_TYPE (and1)) |
8301 <= HOST_BITS_PER_WIDE_INT | 8595 <= HOST_BITS_PER_WIDE_INT |
8302 && host_integerp (and1, 1)) | 8596 && host_integerp (and1, 1)) |
8303 { | 8597 { |
8312 && !flag_syntax_only | 8606 && !flag_syntax_only |
8313 && (LOAD_EXTEND_OP (TYPE_MODE (TREE_TYPE (and0))) | 8607 && (LOAD_EXTEND_OP (TYPE_MODE (TREE_TYPE (and0))) |
8314 == ZERO_EXTEND)) | 8608 == ZERO_EXTEND)) |
8315 { | 8609 { |
8316 tree uns = unsigned_type_for (TREE_TYPE (and0)); | 8610 tree uns = unsigned_type_for (TREE_TYPE (and0)); |
8317 and0 = fold_convert (uns, and0); | 8611 and0 = fold_convert_loc (loc, uns, and0); |
8318 and1 = fold_convert (uns, and1); | 8612 and1 = fold_convert_loc (loc, uns, and1); |
8319 } | 8613 } |
8320 #endif | 8614 #endif |
8321 } | 8615 } |
8322 if (change) | 8616 if (change) |
8323 { | 8617 { |
8324 tem = force_fit_type_double (type, TREE_INT_CST_LOW (and1), | 8618 tem = force_fit_type_double (type, TREE_INT_CST_LOW (and1), |
8325 TREE_INT_CST_HIGH (and1), 0, | 8619 TREE_INT_CST_HIGH (and1), 0, |
8326 TREE_OVERFLOW (and1)); | 8620 TREE_OVERFLOW (and1)); |
8327 return fold_build2 (BIT_AND_EXPR, type, | 8621 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
8328 fold_convert (type, and0), tem); | 8622 fold_convert_loc (loc, type, and0), tem); |
8329 } | 8623 } |
8330 } | 8624 } |
8331 | 8625 |
8332 /* Convert (T1)(X p+ Y) into ((T1)X p+ Y), for pointer type, | 8626 /* Convert (T1)(X p+ Y) into ((T1)X p+ Y), for pointer type, |
8333 when one of the new casts will fold away. Conservatively we assume | 8627 when one of the new casts will fold away. Conservatively we assume |
8339 || TREE_CODE (TREE_OPERAND (arg0, 1)) == NOP_EXPR)) | 8633 || TREE_CODE (TREE_OPERAND (arg0, 1)) == NOP_EXPR)) |
8340 { | 8634 { |
8341 tree arg00 = TREE_OPERAND (arg0, 0); | 8635 tree arg00 = TREE_OPERAND (arg0, 0); |
8342 tree arg01 = TREE_OPERAND (arg0, 1); | 8636 tree arg01 = TREE_OPERAND (arg0, 1); |
8343 | 8637 |
8344 return fold_build2 (TREE_CODE (arg0), type, fold_convert (type, arg00), | 8638 return fold_build2_loc (loc, |
8345 fold_convert (sizetype, arg01)); | 8639 TREE_CODE (arg0), type, |
8640 fold_convert_loc (loc, type, arg00), | |
8641 fold_convert_loc (loc, sizetype, arg01)); | |
8346 } | 8642 } |
8347 | 8643 |
8348 /* Convert (T1)(~(T2)X) into ~(T1)X if T1 and T2 are integral types | 8644 /* Convert (T1)(~(T2)X) into ~(T1)X if T1 and T2 are integral types |
8349 of the same precision, and X is an integer type not narrower than | 8645 of the same precision, and X is an integer type not narrower than |
8350 types T1 or T2, i.e. the cast (T2)X isn't an extension. */ | 8646 types T1 or T2, i.e. the cast (T2)X isn't an extension. */ |
8355 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0))) | 8651 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0))) |
8356 { | 8652 { |
8357 tem = TREE_OPERAND (TREE_OPERAND (op0, 0), 0); | 8653 tem = TREE_OPERAND (TREE_OPERAND (op0, 0), 0); |
8358 if (INTEGRAL_TYPE_P (TREE_TYPE (tem)) | 8654 if (INTEGRAL_TYPE_P (TREE_TYPE (tem)) |
8359 && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (tem))) | 8655 && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (tem))) |
8360 return fold_build1 (BIT_NOT_EXPR, type, fold_convert (type, tem)); | 8656 return fold_build1_loc (loc, BIT_NOT_EXPR, type, |
8657 fold_convert_loc (loc, type, tem)); | |
8361 } | 8658 } |
8362 | 8659 |
8363 /* Convert (T1)(X * Y) into (T1)X * (T1)Y if T1 is narrower than the | 8660 /* Convert (T1)(X * Y) into (T1)X * (T1)Y if T1 is narrower than the |
8364 type of X and Y (integer types only). */ | 8661 type of X and Y (integer types only). */ |
8365 if (INTEGRAL_TYPE_P (type) | 8662 if (INTEGRAL_TYPE_P (type) |
8374 else | 8671 else |
8375 mult_type = unsigned_type_for (type); | 8672 mult_type = unsigned_type_for (type); |
8376 | 8673 |
8377 if (TYPE_PRECISION (mult_type) < TYPE_PRECISION (TREE_TYPE (op0))) | 8674 if (TYPE_PRECISION (mult_type) < TYPE_PRECISION (TREE_TYPE (op0))) |
8378 { | 8675 { |
8379 tem = fold_build2 (MULT_EXPR, mult_type, | 8676 tem = fold_build2_loc (loc, MULT_EXPR, mult_type, |
8380 fold_convert (mult_type, | 8677 fold_convert_loc (loc, mult_type, |
8381 TREE_OPERAND (op0, 0)), | 8678 TREE_OPERAND (op0, 0)), |
8382 fold_convert (mult_type, | 8679 fold_convert_loc (loc, mult_type, |
8383 TREE_OPERAND (op0, 1))); | 8680 TREE_OPERAND (op0, 1))); |
8384 return fold_convert (type, tem); | 8681 return fold_convert_loc (loc, type, tem); |
8385 } | 8682 } |
8386 } | 8683 } |
8387 | 8684 |
8388 tem = fold_convert_const (code, type, op0); | 8685 tem = fold_convert_const (code, type, op0); |
8389 return tem ? tem : NULL_TREE; | 8686 return tem ? tem : NULL_TREE; |
8687 | |
8688 case ADDR_SPACE_CONVERT_EXPR: | |
8689 if (integer_zerop (arg0)) | |
8690 return fold_convert_const (code, type, arg0); | |
8691 return NULL_TREE; | |
8390 | 8692 |
8391 case FIXED_CONVERT_EXPR: | 8693 case FIXED_CONVERT_EXPR: |
8392 tem = fold_convert_const (code, type, arg0); | 8694 tem = fold_convert_const (code, type, arg0); |
8393 return tem ? tem : NULL_TREE; | 8695 return tem ? tem : NULL_TREE; |
8394 | 8696 |
8395 case VIEW_CONVERT_EXPR: | 8697 case VIEW_CONVERT_EXPR: |
8396 if (TREE_TYPE (op0) == type) | 8698 if (TREE_TYPE (op0) == type) |
8397 return op0; | 8699 return op0; |
8398 if (TREE_CODE (op0) == VIEW_CONVERT_EXPR) | 8700 if (TREE_CODE (op0) == VIEW_CONVERT_EXPR) |
8399 return fold_build1 (VIEW_CONVERT_EXPR, type, TREE_OPERAND (op0, 0)); | 8701 return fold_build1_loc (loc, VIEW_CONVERT_EXPR, |
8702 type, TREE_OPERAND (op0, 0)); | |
8400 | 8703 |
8401 /* For integral conversions with the same precision or pointer | 8704 /* For integral conversions with the same precision or pointer |
8402 conversions use a NOP_EXPR instead. */ | 8705 conversions use a NOP_EXPR instead. */ |
8403 if ((INTEGRAL_TYPE_P (type) | 8706 if ((INTEGRAL_TYPE_P (type) |
8404 || POINTER_TYPE_P (type)) | 8707 || POINTER_TYPE_P (type)) |
8405 && (INTEGRAL_TYPE_P (TREE_TYPE (op0)) | 8708 && (INTEGRAL_TYPE_P (TREE_TYPE (op0)) |
8406 || POINTER_TYPE_P (TREE_TYPE (op0))) | 8709 || POINTER_TYPE_P (TREE_TYPE (op0))) |
8407 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0)) | 8710 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0))) |
8408 /* Do not muck with VIEW_CONVERT_EXPRs that convert from | 8711 return fold_convert_loc (loc, type, op0); |
8409 a sub-type to its base type as generated by the Ada FE. */ | |
8410 && !(INTEGRAL_TYPE_P (TREE_TYPE (op0)) | |
8411 && TREE_TYPE (TREE_TYPE (op0)))) | |
8412 return fold_convert (type, op0); | |
8413 | 8712 |
8414 /* Strip inner integral conversions that do not change the precision. */ | 8713 /* Strip inner integral conversions that do not change the precision. */ |
8415 if (CONVERT_EXPR_P (op0) | 8714 if (CONVERT_EXPR_P (op0) |
8416 && (INTEGRAL_TYPE_P (TREE_TYPE (op0)) | 8715 && (INTEGRAL_TYPE_P (TREE_TYPE (op0)) |
8417 || POINTER_TYPE_P (TREE_TYPE (op0))) | 8716 || POINTER_TYPE_P (TREE_TYPE (op0))) |
8418 && (INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0))) | 8717 && (INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0))) |
8419 || POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0)))) | 8718 || POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0)))) |
8420 && (TYPE_PRECISION (TREE_TYPE (op0)) | 8719 && (TYPE_PRECISION (TREE_TYPE (op0)) |
8421 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0))))) | 8720 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0))))) |
8422 return fold_build1 (VIEW_CONVERT_EXPR, type, TREE_OPERAND (op0, 0)); | 8721 return fold_build1_loc (loc, VIEW_CONVERT_EXPR, |
8722 type, TREE_OPERAND (op0, 0)); | |
8423 | 8723 |
8424 return fold_view_convert_expr (type, op0); | 8724 return fold_view_convert_expr (type, op0); |
8425 | 8725 |
8426 case NEGATE_EXPR: | 8726 case NEGATE_EXPR: |
8427 tem = fold_negate_expr (arg0); | 8727 tem = fold_negate_expr (loc, arg0); |
8428 if (tem) | 8728 if (tem) |
8429 return fold_convert (type, tem); | 8729 return fold_convert_loc (loc, type, tem); |
8430 return NULL_TREE; | 8730 return NULL_TREE; |
8431 | 8731 |
8432 case ABS_EXPR: | 8732 case ABS_EXPR: |
8433 if (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST) | 8733 if (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST) |
8434 return fold_abs_const (arg0, type); | 8734 return fold_abs_const (arg0, type); |
8435 else if (TREE_CODE (arg0) == NEGATE_EXPR) | 8735 else if (TREE_CODE (arg0) == NEGATE_EXPR) |
8436 return fold_build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0)); | 8736 return fold_build1_loc (loc, ABS_EXPR, type, TREE_OPERAND (arg0, 0)); |
8437 /* Convert fabs((double)float) into (double)fabsf(float). */ | 8737 /* Convert fabs((double)float) into (double)fabsf(float). */ |
8438 else if (TREE_CODE (arg0) == NOP_EXPR | 8738 else if (TREE_CODE (arg0) == NOP_EXPR |
8439 && TREE_CODE (type) == REAL_TYPE) | 8739 && TREE_CODE (type) == REAL_TYPE) |
8440 { | 8740 { |
8441 tree targ0 = strip_float_extensions (arg0); | 8741 tree targ0 = strip_float_extensions (arg0); |
8442 if (targ0 != arg0) | 8742 if (targ0 != arg0) |
8443 return fold_convert (type, fold_build1 (ABS_EXPR, | 8743 return fold_convert_loc (loc, type, |
8444 TREE_TYPE (targ0), | 8744 fold_build1_loc (loc, ABS_EXPR, |
8445 targ0)); | 8745 TREE_TYPE (targ0), |
8746 targ0)); | |
8446 } | 8747 } |
8447 /* ABS_EXPR<ABS_EXPR<x>> = ABS_EXPR<x> even if flag_wrapv is on. */ | 8748 /* ABS_EXPR<ABS_EXPR<x>> = ABS_EXPR<x> even if flag_wrapv is on. */ |
8448 else if (TREE_CODE (arg0) == ABS_EXPR) | 8749 else if (TREE_CODE (arg0) == ABS_EXPR) |
8449 return arg0; | 8750 return arg0; |
8450 else if (tree_expr_nonnegative_p (arg0)) | 8751 else if (tree_expr_nonnegative_p (arg0)) |
8453 /* Strip sign ops from argument. */ | 8754 /* Strip sign ops from argument. */ |
8454 if (TREE_CODE (type) == REAL_TYPE) | 8755 if (TREE_CODE (type) == REAL_TYPE) |
8455 { | 8756 { |
8456 tem = fold_strip_sign_ops (arg0); | 8757 tem = fold_strip_sign_ops (arg0); |
8457 if (tem) | 8758 if (tem) |
8458 return fold_build1 (ABS_EXPR, type, fold_convert (type, tem)); | 8759 return fold_build1_loc (loc, ABS_EXPR, type, |
8760 fold_convert_loc (loc, type, tem)); | |
8459 } | 8761 } |
8460 return NULL_TREE; | 8762 return NULL_TREE; |
8461 | 8763 |
8462 case CONJ_EXPR: | 8764 case CONJ_EXPR: |
8463 if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE) | 8765 if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE) |
8464 return fold_convert (type, arg0); | 8766 return fold_convert_loc (loc, type, arg0); |
8465 if (TREE_CODE (arg0) == COMPLEX_EXPR) | 8767 if (TREE_CODE (arg0) == COMPLEX_EXPR) |
8466 { | 8768 { |
8467 tree itype = TREE_TYPE (type); | 8769 tree itype = TREE_TYPE (type); |
8468 tree rpart = fold_convert (itype, TREE_OPERAND (arg0, 0)); | 8770 tree rpart = fold_convert_loc (loc, itype, TREE_OPERAND (arg0, 0)); |
8469 tree ipart = fold_convert (itype, TREE_OPERAND (arg0, 1)); | 8771 tree ipart = fold_convert_loc (loc, itype, TREE_OPERAND (arg0, 1)); |
8470 return fold_build2 (COMPLEX_EXPR, type, rpart, negate_expr (ipart)); | 8772 return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart, |
8773 negate_expr (ipart)); | |
8471 } | 8774 } |
8472 if (TREE_CODE (arg0) == COMPLEX_CST) | 8775 if (TREE_CODE (arg0) == COMPLEX_CST) |
8473 { | 8776 { |
8474 tree itype = TREE_TYPE (type); | 8777 tree itype = TREE_TYPE (type); |
8475 tree rpart = fold_convert (itype, TREE_REALPART (arg0)); | 8778 tree rpart = fold_convert_loc (loc, itype, TREE_REALPART (arg0)); |
8476 tree ipart = fold_convert (itype, TREE_IMAGPART (arg0)); | 8779 tree ipart = fold_convert_loc (loc, itype, TREE_IMAGPART (arg0)); |
8477 return build_complex (type, rpart, negate_expr (ipart)); | 8780 return build_complex (type, rpart, negate_expr (ipart)); |
8478 } | 8781 } |
8479 if (TREE_CODE (arg0) == CONJ_EXPR) | 8782 if (TREE_CODE (arg0) == CONJ_EXPR) |
8480 return fold_convert (type, TREE_OPERAND (arg0, 0)); | 8783 return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); |
8481 return NULL_TREE; | 8784 return NULL_TREE; |
8482 | 8785 |
8483 case BIT_NOT_EXPR: | 8786 case BIT_NOT_EXPR: |
8484 if (TREE_CODE (arg0) == INTEGER_CST) | 8787 if (TREE_CODE (arg0) == INTEGER_CST) |
8485 return fold_not_const (arg0, type); | 8788 return fold_not_const (arg0, type); |
8486 else if (TREE_CODE (arg0) == BIT_NOT_EXPR) | 8789 else if (TREE_CODE (arg0) == BIT_NOT_EXPR) |
8487 return fold_convert (type, TREE_OPERAND (arg0, 0)); | 8790 return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); |
8488 /* Convert ~ (-A) to A - 1. */ | 8791 /* Convert ~ (-A) to A - 1. */ |
8489 else if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == NEGATE_EXPR) | 8792 else if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == NEGATE_EXPR) |
8490 return fold_build2 (MINUS_EXPR, type, | 8793 return fold_build2_loc (loc, MINUS_EXPR, type, |
8491 fold_convert (type, TREE_OPERAND (arg0, 0)), | 8794 fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)), |
8492 build_int_cst (type, 1)); | 8795 build_int_cst (type, 1)); |
8493 /* Convert ~ (A - 1) or ~ (A + -1) to -A. */ | 8796 /* Convert ~ (A - 1) or ~ (A + -1) to -A. */ |
8494 else if (INTEGRAL_TYPE_P (type) | 8797 else if (INTEGRAL_TYPE_P (type) |
8495 && ((TREE_CODE (arg0) == MINUS_EXPR | 8798 && ((TREE_CODE (arg0) == MINUS_EXPR |
8496 && integer_onep (TREE_OPERAND (arg0, 1))) | 8799 && integer_onep (TREE_OPERAND (arg0, 1))) |
8497 || (TREE_CODE (arg0) == PLUS_EXPR | 8800 || (TREE_CODE (arg0) == PLUS_EXPR |
8498 && integer_all_onesp (TREE_OPERAND (arg0, 1))))) | 8801 && integer_all_onesp (TREE_OPERAND (arg0, 1))))) |
8499 return fold_build1 (NEGATE_EXPR, type, | 8802 return fold_build1_loc (loc, NEGATE_EXPR, type, |
8500 fold_convert (type, TREE_OPERAND (arg0, 0))); | 8803 fold_convert_loc (loc, type, |
8804 TREE_OPERAND (arg0, 0))); | |
8501 /* Convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */ | 8805 /* Convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */ |
8502 else if (TREE_CODE (arg0) == BIT_XOR_EXPR | 8806 else if (TREE_CODE (arg0) == BIT_XOR_EXPR |
8503 && (tem = fold_unary (BIT_NOT_EXPR, type, | 8807 && (tem = fold_unary_loc (loc, BIT_NOT_EXPR, type, |
8504 fold_convert (type, | 8808 fold_convert_loc (loc, type, |
8505 TREE_OPERAND (arg0, 0))))) | 8809 TREE_OPERAND (arg0, 0))))) |
8506 return fold_build2 (BIT_XOR_EXPR, type, tem, | 8810 return fold_build2_loc (loc, BIT_XOR_EXPR, type, tem, |
8507 fold_convert (type, TREE_OPERAND (arg0, 1))); | 8811 fold_convert_loc (loc, type, |
8812 TREE_OPERAND (arg0, 1))); | |
8508 else if (TREE_CODE (arg0) == BIT_XOR_EXPR | 8813 else if (TREE_CODE (arg0) == BIT_XOR_EXPR |
8509 && (tem = fold_unary (BIT_NOT_EXPR, type, | 8814 && (tem = fold_unary_loc (loc, BIT_NOT_EXPR, type, |
8510 fold_convert (type, | 8815 fold_convert_loc (loc, type, |
8511 TREE_OPERAND (arg0, 1))))) | 8816 TREE_OPERAND (arg0, 1))))) |
8512 return fold_build2 (BIT_XOR_EXPR, type, | 8817 return fold_build2_loc (loc, BIT_XOR_EXPR, type, |
8513 fold_convert (type, TREE_OPERAND (arg0, 0)), tem); | 8818 fold_convert_loc (loc, type, |
8819 TREE_OPERAND (arg0, 0)), tem); | |
8514 /* Perform BIT_NOT_EXPR on each element individually. */ | 8820 /* Perform BIT_NOT_EXPR on each element individually. */ |
8515 else if (TREE_CODE (arg0) == VECTOR_CST) | 8821 else if (TREE_CODE (arg0) == VECTOR_CST) |
8516 { | 8822 { |
8517 tree elements = TREE_VECTOR_CST_ELTS (arg0), elem, list = NULL_TREE; | 8823 tree elements = TREE_VECTOR_CST_ELTS (arg0), elem, list = NULL_TREE; |
8518 int count = TYPE_VECTOR_SUBPARTS (type), i; | 8824 int count = TYPE_VECTOR_SUBPARTS (type), i; |
8520 for (i = 0; i < count; i++) | 8826 for (i = 0; i < count; i++) |
8521 { | 8827 { |
8522 if (elements) | 8828 if (elements) |
8523 { | 8829 { |
8524 elem = TREE_VALUE (elements); | 8830 elem = TREE_VALUE (elements); |
8525 elem = fold_unary (BIT_NOT_EXPR, TREE_TYPE (type), elem); | 8831 elem = fold_unary_loc (loc, BIT_NOT_EXPR, TREE_TYPE (type), elem); |
8526 if (elem == NULL_TREE) | 8832 if (elem == NULL_TREE) |
8527 break; | 8833 break; |
8528 elements = TREE_CHAIN (elements); | 8834 elements = TREE_CHAIN (elements); |
8529 } | 8835 } |
8530 else | 8836 else |
8538 return NULL_TREE; | 8844 return NULL_TREE; |
8539 | 8845 |
8540 case TRUTH_NOT_EXPR: | 8846 case TRUTH_NOT_EXPR: |
8541 /* The argument to invert_truthvalue must have Boolean type. */ | 8847 /* The argument to invert_truthvalue must have Boolean type. */ |
8542 if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE) | 8848 if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE) |
8543 arg0 = fold_convert (boolean_type_node, arg0); | 8849 arg0 = fold_convert_loc (loc, boolean_type_node, arg0); |
8544 | 8850 |
8545 /* Note that the operand of this must be an int | 8851 /* Note that the operand of this must be an int |
8546 and its values must be 0 or 1. | 8852 and its values must be 0 or 1. |
8547 ("true" is a fixed value perhaps depending on the language, | 8853 ("true" is a fixed value perhaps depending on the language, |
8548 but we don't handle values other than 1 correctly yet.) */ | 8854 but we don't handle values other than 1 correctly yet.) */ |
8549 tem = fold_truth_not_expr (arg0); | 8855 tem = fold_truth_not_expr (loc, arg0); |
8550 if (!tem) | 8856 if (!tem) |
8551 return NULL_TREE; | 8857 return NULL_TREE; |
8552 return fold_convert (type, tem); | 8858 return fold_convert_loc (loc, type, tem); |
8553 | 8859 |
8554 case REALPART_EXPR: | 8860 case REALPART_EXPR: |
8555 if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE) | 8861 if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE) |
8556 return fold_convert (type, arg0); | 8862 return fold_convert_loc (loc, type, arg0); |
8557 if (TREE_CODE (arg0) == COMPLEX_EXPR) | 8863 if (TREE_CODE (arg0) == COMPLEX_EXPR) |
8558 return omit_one_operand (type, TREE_OPERAND (arg0, 0), | 8864 return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 0), |
8559 TREE_OPERAND (arg0, 1)); | 8865 TREE_OPERAND (arg0, 1)); |
8560 if (TREE_CODE (arg0) == COMPLEX_CST) | 8866 if (TREE_CODE (arg0) == COMPLEX_CST) |
8561 return fold_convert (type, TREE_REALPART (arg0)); | 8867 return fold_convert_loc (loc, type, TREE_REALPART (arg0)); |
8562 if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) | 8868 if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) |
8563 { | 8869 { |
8564 tree itype = TREE_TYPE (TREE_TYPE (arg0)); | 8870 tree itype = TREE_TYPE (TREE_TYPE (arg0)); |
8565 tem = fold_build2 (TREE_CODE (arg0), itype, | 8871 tem = fold_build2_loc (loc, TREE_CODE (arg0), itype, |
8566 fold_build1 (REALPART_EXPR, itype, | 8872 fold_build1_loc (loc, REALPART_EXPR, itype, |
8567 TREE_OPERAND (arg0, 0)), | 8873 TREE_OPERAND (arg0, 0)), |
8568 fold_build1 (REALPART_EXPR, itype, | 8874 fold_build1_loc (loc, REALPART_EXPR, itype, |
8569 TREE_OPERAND (arg0, 1))); | 8875 TREE_OPERAND (arg0, 1))); |
8570 return fold_convert (type, tem); | 8876 return fold_convert_loc (loc, type, tem); |
8571 } | 8877 } |
8572 if (TREE_CODE (arg0) == CONJ_EXPR) | 8878 if (TREE_CODE (arg0) == CONJ_EXPR) |
8573 { | 8879 { |
8574 tree itype = TREE_TYPE (TREE_TYPE (arg0)); | 8880 tree itype = TREE_TYPE (TREE_TYPE (arg0)); |
8575 tem = fold_build1 (REALPART_EXPR, itype, TREE_OPERAND (arg0, 0)); | 8881 tem = fold_build1_loc (loc, REALPART_EXPR, itype, |
8576 return fold_convert (type, tem); | 8882 TREE_OPERAND (arg0, 0)); |
8883 return fold_convert_loc (loc, type, tem); | |
8577 } | 8884 } |
8578 if (TREE_CODE (arg0) == CALL_EXPR) | 8885 if (TREE_CODE (arg0) == CALL_EXPR) |
8579 { | 8886 { |
8580 tree fn = get_callee_fndecl (arg0); | 8887 tree fn = get_callee_fndecl (arg0); |
8581 if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL) | 8888 if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL) |
8582 switch (DECL_FUNCTION_CODE (fn)) | 8889 switch (DECL_FUNCTION_CODE (fn)) |
8583 { | 8890 { |
8584 CASE_FLT_FN (BUILT_IN_CEXPI): | 8891 CASE_FLT_FN (BUILT_IN_CEXPI): |
8585 fn = mathfn_built_in (type, BUILT_IN_COS); | 8892 fn = mathfn_built_in (type, BUILT_IN_COS); |
8586 if (fn) | 8893 if (fn) |
8587 return build_call_expr (fn, 1, CALL_EXPR_ARG (arg0, 0)); | 8894 return build_call_expr_loc (loc, fn, 1, CALL_EXPR_ARG (arg0, 0)); |
8588 break; | 8895 break; |
8589 | 8896 |
8590 default: | 8897 default: |
8591 break; | 8898 break; |
8592 } | 8899 } |
8593 } | 8900 } |
8594 return NULL_TREE; | 8901 return NULL_TREE; |
8595 | 8902 |
8596 case IMAGPART_EXPR: | 8903 case IMAGPART_EXPR: |
8597 if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE) | 8904 if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE) |
8598 return fold_convert (type, integer_zero_node); | 8905 return fold_convert_loc (loc, type, integer_zero_node); |
8599 if (TREE_CODE (arg0) == COMPLEX_EXPR) | 8906 if (TREE_CODE (arg0) == COMPLEX_EXPR) |
8600 return omit_one_operand (type, TREE_OPERAND (arg0, 1), | 8907 return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 1), |
8601 TREE_OPERAND (arg0, 0)); | 8908 TREE_OPERAND (arg0, 0)); |
8602 if (TREE_CODE (arg0) == COMPLEX_CST) | 8909 if (TREE_CODE (arg0) == COMPLEX_CST) |
8603 return fold_convert (type, TREE_IMAGPART (arg0)); | 8910 return fold_convert_loc (loc, type, TREE_IMAGPART (arg0)); |
8604 if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) | 8911 if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) |
8605 { | 8912 { |
8606 tree itype = TREE_TYPE (TREE_TYPE (arg0)); | 8913 tree itype = TREE_TYPE (TREE_TYPE (arg0)); |
8607 tem = fold_build2 (TREE_CODE (arg0), itype, | 8914 tem = fold_build2_loc (loc, TREE_CODE (arg0), itype, |
8608 fold_build1 (IMAGPART_EXPR, itype, | 8915 fold_build1_loc (loc, IMAGPART_EXPR, itype, |
8609 TREE_OPERAND (arg0, 0)), | 8916 TREE_OPERAND (arg0, 0)), |
8610 fold_build1 (IMAGPART_EXPR, itype, | 8917 fold_build1_loc (loc, IMAGPART_EXPR, itype, |
8611 TREE_OPERAND (arg0, 1))); | 8918 TREE_OPERAND (arg0, 1))); |
8612 return fold_convert (type, tem); | 8919 return fold_convert_loc (loc, type, tem); |
8613 } | 8920 } |
8614 if (TREE_CODE (arg0) == CONJ_EXPR) | 8921 if (TREE_CODE (arg0) == CONJ_EXPR) |
8615 { | 8922 { |
8616 tree itype = TREE_TYPE (TREE_TYPE (arg0)); | 8923 tree itype = TREE_TYPE (TREE_TYPE (arg0)); |
8617 tem = fold_build1 (IMAGPART_EXPR, itype, TREE_OPERAND (arg0, 0)); | 8924 tem = fold_build1_loc (loc, IMAGPART_EXPR, itype, TREE_OPERAND (arg0, 0)); |
8618 return fold_convert (type, negate_expr (tem)); | 8925 return fold_convert_loc (loc, type, negate_expr (tem)); |
8619 } | 8926 } |
8620 if (TREE_CODE (arg0) == CALL_EXPR) | 8927 if (TREE_CODE (arg0) == CALL_EXPR) |
8621 { | 8928 { |
8622 tree fn = get_callee_fndecl (arg0); | 8929 tree fn = get_callee_fndecl (arg0); |
8623 if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL) | 8930 if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL) |
8624 switch (DECL_FUNCTION_CODE (fn)) | 8931 switch (DECL_FUNCTION_CODE (fn)) |
8625 { | 8932 { |
8626 CASE_FLT_FN (BUILT_IN_CEXPI): | 8933 CASE_FLT_FN (BUILT_IN_CEXPI): |
8627 fn = mathfn_built_in (type, BUILT_IN_SIN); | 8934 fn = mathfn_built_in (type, BUILT_IN_SIN); |
8628 if (fn) | 8935 if (fn) |
8629 return build_call_expr (fn, 1, CALL_EXPR_ARG (arg0, 0)); | 8936 return build_call_expr_loc (loc, fn, 1, CALL_EXPR_ARG (arg0, 0)); |
8630 break; | 8937 break; |
8631 | 8938 |
8632 default: | 8939 default: |
8633 break; | 8940 break; |
8634 } | 8941 } |
8644 /* If the operation was a conversion do _not_ mark a resulting constant | 8951 /* If the operation was a conversion do _not_ mark a resulting constant |
8645 with TREE_OVERFLOW if the original constant was not. These conversions | 8952 with TREE_OVERFLOW if the original constant was not. These conversions |
8646 have implementation defined behavior and retaining the TREE_OVERFLOW | 8953 have implementation defined behavior and retaining the TREE_OVERFLOW |
8647 flag here would confuse later passes such as VRP. */ | 8954 flag here would confuse later passes such as VRP. */ |
8648 tree | 8955 tree |
8649 fold_unary_ignore_overflow (enum tree_code code, tree type, tree op0) | 8956 fold_unary_ignore_overflow_loc (location_t loc, enum tree_code code, |
8650 { | 8957 tree type, tree op0) |
8651 tree res = fold_unary (code, type, op0); | 8958 { |
8959 tree res = fold_unary_loc (loc, code, type, op0); | |
8652 if (res | 8960 if (res |
8653 && TREE_CODE (res) == INTEGER_CST | 8961 && TREE_CODE (res) == INTEGER_CST |
8654 && TREE_CODE (op0) == INTEGER_CST | 8962 && TREE_CODE (op0) == INTEGER_CST |
8655 && CONVERT_EXPR_CODE_P (code)) | 8963 && CONVERT_EXPR_CODE_P (code)) |
8656 TREE_OVERFLOW (res) = TREE_OVERFLOW (op0); | 8964 TREE_OVERFLOW (res) = TREE_OVERFLOW (op0); |
8662 OP0 and OP1, containing either a MIN-MAX or a MAX-MIN combination. | 8970 OP0 and OP1, containing either a MIN-MAX or a MAX-MIN combination. |
8663 Return the folded expression if folding is successful. Otherwise, | 8971 Return the folded expression if folding is successful. Otherwise, |
8664 return NULL_TREE. */ | 8972 return NULL_TREE. */ |
8665 | 8973 |
8666 static tree | 8974 static tree |
8667 fold_minmax (enum tree_code code, tree type, tree op0, tree op1) | 8975 fold_minmax (location_t loc, enum tree_code code, tree type, tree op0, tree op1) |
8668 { | 8976 { |
8669 enum tree_code compl_code; | 8977 enum tree_code compl_code; |
8670 | 8978 |
8671 if (code == MIN_EXPR) | 8979 if (code == MIN_EXPR) |
8672 compl_code = MAX_EXPR; | 8980 compl_code = MAX_EXPR; |
8676 gcc_unreachable (); | 8984 gcc_unreachable (); |
8677 | 8985 |
8678 /* MIN (MAX (a, b), b) == b. */ | 8986 /* MIN (MAX (a, b), b) == b. */ |
8679 if (TREE_CODE (op0) == compl_code | 8987 if (TREE_CODE (op0) == compl_code |
8680 && operand_equal_p (TREE_OPERAND (op0, 1), op1, 0)) | 8988 && operand_equal_p (TREE_OPERAND (op0, 1), op1, 0)) |
8681 return omit_one_operand (type, op1, TREE_OPERAND (op0, 0)); | 8989 return omit_one_operand_loc (loc, type, op1, TREE_OPERAND (op0, 0)); |
8682 | 8990 |
8683 /* MIN (MAX (b, a), b) == b. */ | 8991 /* MIN (MAX (b, a), b) == b. */ |
8684 if (TREE_CODE (op0) == compl_code | 8992 if (TREE_CODE (op0) == compl_code |
8685 && operand_equal_p (TREE_OPERAND (op0, 0), op1, 0) | 8993 && operand_equal_p (TREE_OPERAND (op0, 0), op1, 0) |
8686 && reorder_operands_p (TREE_OPERAND (op0, 1), op1)) | 8994 && reorder_operands_p (TREE_OPERAND (op0, 1), op1)) |
8687 return omit_one_operand (type, op1, TREE_OPERAND (op0, 1)); | 8995 return omit_one_operand_loc (loc, type, op1, TREE_OPERAND (op0, 1)); |
8688 | 8996 |
8689 /* MIN (a, MAX (a, b)) == a. */ | 8997 /* MIN (a, MAX (a, b)) == a. */ |
8690 if (TREE_CODE (op1) == compl_code | 8998 if (TREE_CODE (op1) == compl_code |
8691 && operand_equal_p (op0, TREE_OPERAND (op1, 0), 0) | 8999 && operand_equal_p (op0, TREE_OPERAND (op1, 0), 0) |
8692 && reorder_operands_p (op0, TREE_OPERAND (op1, 1))) | 9000 && reorder_operands_p (op0, TREE_OPERAND (op1, 1))) |
8693 return omit_one_operand (type, op0, TREE_OPERAND (op1, 1)); | 9001 return omit_one_operand_loc (loc, type, op0, TREE_OPERAND (op1, 1)); |
8694 | 9002 |
8695 /* MIN (a, MAX (b, a)) == a. */ | 9003 /* MIN (a, MAX (b, a)) == a. */ |
8696 if (TREE_CODE (op1) == compl_code | 9004 if (TREE_CODE (op1) == compl_code |
8697 && operand_equal_p (op0, TREE_OPERAND (op1, 1), 0) | 9005 && operand_equal_p (op0, TREE_OPERAND (op1, 1), 0) |
8698 && reorder_operands_p (op0, TREE_OPERAND (op1, 0))) | 9006 && reorder_operands_p (op0, TREE_OPERAND (op1, 0))) |
8699 return omit_one_operand (type, op0, TREE_OPERAND (op1, 0)); | 9007 return omit_one_operand_loc (loc, type, op0, TREE_OPERAND (op1, 0)); |
8700 | 9008 |
8701 return NULL_TREE; | 9009 return NULL_TREE; |
8702 } | 9010 } |
8703 | 9011 |
8704 /* Helper that tries to canonicalize the comparison ARG0 CODE ARG1 | 9012 /* Helper that tries to canonicalize the comparison ARG0 CODE ARG1 |
8708 possible, otherwise returns NULL_TREE. | 9016 possible, otherwise returns NULL_TREE. |
8709 Set *STRICT_OVERFLOW_P to true if the canonicalization is only | 9017 Set *STRICT_OVERFLOW_P to true if the canonicalization is only |
8710 valid if signed overflow is undefined. */ | 9018 valid if signed overflow is undefined. */ |
8711 | 9019 |
8712 static tree | 9020 static tree |
8713 maybe_canonicalize_comparison_1 (enum tree_code code, tree type, | 9021 maybe_canonicalize_comparison_1 (location_t loc, enum tree_code code, tree type, |
8714 tree arg0, tree arg1, | 9022 tree arg0, tree arg1, |
8715 bool *strict_overflow_p) | 9023 bool *strict_overflow_p) |
8716 { | 9024 { |
8717 enum tree_code code0 = TREE_CODE (arg0); | 9025 enum tree_code code0 = TREE_CODE (arg0); |
8718 tree t, cst0 = NULL_TREE; | 9026 tree t, cst0 = NULL_TREE; |
8801 return NULL_TREE; | 9109 return NULL_TREE; |
8802 | 9110 |
8803 t = int_const_binop (sgn0 == -1 ? PLUS_EXPR : MINUS_EXPR, | 9111 t = int_const_binop (sgn0 == -1 ? PLUS_EXPR : MINUS_EXPR, |
8804 cst0, build_int_cst (TREE_TYPE (cst0), 1), 0); | 9112 cst0, build_int_cst (TREE_TYPE (cst0), 1), 0); |
8805 if (code0 != INTEGER_CST) | 9113 if (code0 != INTEGER_CST) |
8806 t = fold_build2 (code0, TREE_TYPE (arg0), TREE_OPERAND (arg0, 0), t); | 9114 t = fold_build2_loc (loc, code0, TREE_TYPE (arg0), TREE_OPERAND (arg0, 0), t); |
8807 | 9115 |
8808 /* If swapping might yield to a more canonical form, do so. */ | 9116 /* If swapping might yield to a more canonical form, do so. */ |
8809 if (swap) | 9117 if (swap) |
8810 return fold_build2 (swap_tree_comparison (code), type, arg1, t); | 9118 return fold_build2_loc (loc, swap_tree_comparison (code), type, arg1, t); |
8811 else | 9119 else |
8812 return fold_build2 (code, type, t, arg1); | 9120 return fold_build2_loc (loc, code, type, t, arg1); |
8813 } | 9121 } |
8814 | 9122 |
8815 /* Canonicalize the comparison ARG0 CODE ARG1 with type TYPE with undefined | 9123 /* Canonicalize the comparison ARG0 CODE ARG1 with type TYPE with undefined |
8816 overflow further. Try to decrease the magnitude of constants involved | 9124 overflow further. Try to decrease the magnitude of constants involved |
8817 by changing LE_EXPR and GE_EXPR to LT_EXPR and GT_EXPR or vice versa | 9125 by changing LE_EXPR and GE_EXPR to LT_EXPR and GT_EXPR or vice versa |
8818 and put sole constants at the second argument position. | 9126 and put sole constants at the second argument position. |
8819 Returns the canonicalized tree if changed, otherwise NULL_TREE. */ | 9127 Returns the canonicalized tree if changed, otherwise NULL_TREE. */ |
8820 | 9128 |
8821 static tree | 9129 static tree |
8822 maybe_canonicalize_comparison (enum tree_code code, tree type, | 9130 maybe_canonicalize_comparison (location_t loc, enum tree_code code, tree type, |
8823 tree arg0, tree arg1) | 9131 tree arg0, tree arg1) |
8824 { | 9132 { |
8825 tree t; | 9133 tree t; |
8826 bool strict_overflow_p; | 9134 bool strict_overflow_p; |
8827 const char * const warnmsg = G_("assuming signed overflow does not occur " | 9135 const char * const warnmsg = G_("assuming signed overflow does not occur " |
8828 "when reducing constant in comparison"); | 9136 "when reducing constant in comparison"); |
8829 | 9137 |
8830 /* Try canonicalization by simplifying arg0. */ | 9138 /* Try canonicalization by simplifying arg0. */ |
8831 strict_overflow_p = false; | 9139 strict_overflow_p = false; |
8832 t = maybe_canonicalize_comparison_1 (code, type, arg0, arg1, | 9140 t = maybe_canonicalize_comparison_1 (loc, code, type, arg0, arg1, |
8833 &strict_overflow_p); | 9141 &strict_overflow_p); |
8834 if (t) | 9142 if (t) |
8835 { | 9143 { |
8836 if (strict_overflow_p) | 9144 if (strict_overflow_p) |
8837 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE); | 9145 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE); |
8840 | 9148 |
8841 /* Try canonicalization by simplifying arg1 using the swapped | 9149 /* Try canonicalization by simplifying arg1 using the swapped |
8842 comparison. */ | 9150 comparison. */ |
8843 code = swap_tree_comparison (code); | 9151 code = swap_tree_comparison (code); |
8844 strict_overflow_p = false; | 9152 strict_overflow_p = false; |
8845 t = maybe_canonicalize_comparison_1 (code, type, arg1, arg0, | 9153 t = maybe_canonicalize_comparison_1 (loc, code, type, arg1, arg0, |
8846 &strict_overflow_p); | 9154 &strict_overflow_p); |
8847 if (t && strict_overflow_p) | 9155 if (t && strict_overflow_p) |
8848 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE); | 9156 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE); |
8849 return t; | 9157 return t; |
8850 } | 9158 } |
8912 fold_binary should call fold_binary. Fold a comparison with | 9220 fold_binary should call fold_binary. Fold a comparison with |
8913 tree code CODE and type TYPE with operands OP0 and OP1. Return | 9221 tree code CODE and type TYPE with operands OP0 and OP1. Return |
8914 the folded comparison or NULL_TREE. */ | 9222 the folded comparison or NULL_TREE. */ |
8915 | 9223 |
8916 static tree | 9224 static tree |
8917 fold_comparison (enum tree_code code, tree type, tree op0, tree op1) | 9225 fold_comparison (location_t loc, enum tree_code code, tree type, |
9226 tree op0, tree op1) | |
8918 { | 9227 { |
8919 tree arg0, arg1, tem; | 9228 tree arg0, arg1, tem; |
8920 | 9229 |
8921 arg0 = op0; | 9230 arg0 = op0; |
8922 arg1 = op1; | 9231 arg1 = op1; |
8928 if (tem != NULL_TREE) | 9237 if (tem != NULL_TREE) |
8929 return tem; | 9238 return tem; |
8930 | 9239 |
8931 /* If one arg is a real or integer constant, put it last. */ | 9240 /* If one arg is a real or integer constant, put it last. */ |
8932 if (tree_swap_operands_p (arg0, arg1, true)) | 9241 if (tree_swap_operands_p (arg0, arg1, true)) |
8933 return fold_build2 (swap_tree_comparison (code), type, op1, op0); | 9242 return fold_build2_loc (loc, swap_tree_comparison (code), type, op1, op0); |
8934 | 9243 |
8935 /* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 +- C1. */ | 9244 /* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 +- C1. */ |
8936 if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) | 9245 if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) |
8937 && (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST | 9246 && (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST |
8938 && !TREE_OVERFLOW (TREE_OPERAND (arg0, 1)) | 9247 && !TREE_OVERFLOW (TREE_OPERAND (arg0, 1)) |
8945 tree variable = TREE_OPERAND (arg0, 0); | 9254 tree variable = TREE_OPERAND (arg0, 0); |
8946 tree lhs; | 9255 tree lhs; |
8947 int lhs_add; | 9256 int lhs_add; |
8948 lhs_add = TREE_CODE (arg0) != PLUS_EXPR; | 9257 lhs_add = TREE_CODE (arg0) != PLUS_EXPR; |
8949 | 9258 |
8950 lhs = fold_build2 (lhs_add ? PLUS_EXPR : MINUS_EXPR, | 9259 lhs = fold_build2_loc (loc, lhs_add ? PLUS_EXPR : MINUS_EXPR, |
8951 TREE_TYPE (arg1), const2, const1); | 9260 TREE_TYPE (arg1), const2, const1); |
8952 | 9261 |
8953 /* If the constant operation overflowed this can be | 9262 /* If the constant operation overflowed this can be |
8954 simplified as a comparison against INT_MAX/INT_MIN. */ | 9263 simplified as a comparison against INT_MAX/INT_MIN. */ |
8955 if (TREE_CODE (lhs) == INTEGER_CST | 9264 if (TREE_CODE (lhs) == INTEGER_CST |
8974 VARIABLE + 1 CODE2 INT_MIN | 9283 VARIABLE + 1 CODE2 INT_MIN |
8975 and decide on the result. */ | 9284 and decide on the result. */ |
8976 if (code2 == LT_EXPR | 9285 if (code2 == LT_EXPR |
8977 || code2 == LE_EXPR | 9286 || code2 == LE_EXPR |
8978 || code2 == EQ_EXPR) | 9287 || code2 == EQ_EXPR) |
8979 return omit_one_operand (type, boolean_false_node, variable); | 9288 return omit_one_operand_loc (loc, type, boolean_false_node, variable); |
8980 else if (code2 == NE_EXPR | 9289 else if (code2 == NE_EXPR |
8981 || code2 == GE_EXPR | 9290 || code2 == GE_EXPR |
8982 || code2 == GT_EXPR) | 9291 || code2 == GT_EXPR) |
8983 return omit_one_operand (type, boolean_true_node, variable); | 9292 return omit_one_operand_loc (loc, type, boolean_true_node, variable); |
8984 } | 9293 } |
8985 | 9294 |
8986 if (TREE_CODE (lhs) == TREE_CODE (arg1) | 9295 if (TREE_CODE (lhs) == TREE_CODE (arg1) |
8987 && (TREE_CODE (lhs) != INTEGER_CST | 9296 && (TREE_CODE (lhs) != INTEGER_CST |
8988 || !TREE_OVERFLOW (lhs))) | 9297 || !TREE_OVERFLOW (lhs))) |
8989 { | 9298 { |
8990 fold_overflow_warning (("assuming signed overflow does not occur " | 9299 fold_overflow_warning (("assuming signed overflow does not occur " |
8991 "when changing X +- C1 cmp C2 to " | 9300 "when changing X +- C1 cmp C2 to " |
8992 "X cmp C1 +- C2"), | 9301 "X cmp C1 +- C2"), |
8993 WARN_STRICT_OVERFLOW_COMPARISON); | 9302 WARN_STRICT_OVERFLOW_COMPARISON); |
8994 return fold_build2 (code, type, variable, lhs); | 9303 return fold_build2_loc (loc, code, type, variable, lhs); |
8995 } | 9304 } |
8996 } | 9305 } |
8997 | 9306 |
8998 /* For comparisons of pointers we can decompose it to a compile time | 9307 /* For comparisons of pointers we can decompose it to a compile time |
8999 comparison of the base objects and the offsets into the object. | 9308 comparison of the base objects and the offsets into the object. |
9059 || (offset0 && offset1 | 9368 || (offset0 && offset1 |
9060 && operand_equal_p (offset0, offset1, 0))) | 9369 && operand_equal_p (offset0, offset1, 0))) |
9061 && (code == EQ_EXPR | 9370 && (code == EQ_EXPR |
9062 || code == NE_EXPR | 9371 || code == NE_EXPR |
9063 || POINTER_TYPE_OVERFLOW_UNDEFINED)) | 9372 || POINTER_TYPE_OVERFLOW_UNDEFINED)) |
9064 | 9373 |
9065 { | 9374 { |
9066 if (code != EQ_EXPR | 9375 if (code != EQ_EXPR |
9067 && code != NE_EXPR | 9376 && code != NE_EXPR |
9068 && bitpos0 != bitpos1 | 9377 && bitpos0 != bitpos1 |
9069 && (pointer_may_wrap_p (base0, offset0, bitpos0) | 9378 && (pointer_may_wrap_p (base0, offset0, bitpos0) |
9110 zero extended from their type in case it is narrower than | 9419 zero extended from their type in case it is narrower than |
9111 size type. */ | 9420 size type. */ |
9112 if (offset0 == NULL_TREE) | 9421 if (offset0 == NULL_TREE) |
9113 offset0 = build_int_cst (signed_size_type_node, 0); | 9422 offset0 = build_int_cst (signed_size_type_node, 0); |
9114 else | 9423 else |
9115 offset0 = fold_convert (signed_size_type_node, offset0); | 9424 offset0 = fold_convert_loc (loc, signed_size_type_node, |
9425 offset0); | |
9116 if (offset1 == NULL_TREE) | 9426 if (offset1 == NULL_TREE) |
9117 offset1 = build_int_cst (signed_size_type_node, 0); | 9427 offset1 = build_int_cst (signed_size_type_node, 0); |
9118 else | 9428 else |
9119 offset1 = fold_convert (signed_size_type_node, offset1); | 9429 offset1 = fold_convert_loc (loc, signed_size_type_node, |
9430 offset1); | |
9120 | 9431 |
9121 if (code != EQ_EXPR | 9432 if (code != EQ_EXPR |
9122 && code != NE_EXPR | 9433 && code != NE_EXPR |
9123 && (pointer_may_wrap_p (base0, offset0, bitpos0) | 9434 && (pointer_may_wrap_p (base0, offset0, bitpos0) |
9124 || pointer_may_wrap_p (base1, offset1, bitpos1))) | 9435 || pointer_may_wrap_p (base1, offset1, bitpos1))) |
9125 fold_overflow_warning (("assuming pointer wraparound does not " | 9436 fold_overflow_warning (("assuming pointer wraparound does not " |
9126 "occur when comparing P +- C1 with " | 9437 "occur when comparing P +- C1 with " |
9127 "P +- C2"), | 9438 "P +- C2"), |
9128 WARN_STRICT_OVERFLOW_COMPARISON); | 9439 WARN_STRICT_OVERFLOW_COMPARISON); |
9129 | 9440 |
9130 return fold_build2 (code, type, offset0, offset1); | 9441 return fold_build2_loc (loc, code, type, offset0, offset1); |
9131 } | 9442 } |
9132 } | 9443 } |
9133 /* For non-equal bases we can simplify if they are addresses | 9444 /* For non-equal bases we can simplify if they are addresses |
9134 of local binding decls or constants. */ | 9445 of local binding decls or constants. */ |
9135 else if (indirect_base0 && indirect_base1 | 9446 else if (indirect_base0 && indirect_base1 |
9149 && (targetm.binds_local_p (base1) | 9460 && (targetm.binds_local_p (base1) |
9150 || CONSTANT_CLASS_P (base0))) | 9461 || CONSTANT_CLASS_P (base0))) |
9151 || CONSTANT_CLASS_P (base1))) | 9462 || CONSTANT_CLASS_P (base1))) |
9152 { | 9463 { |
9153 if (code == EQ_EXPR) | 9464 if (code == EQ_EXPR) |
9154 return omit_two_operands (type, boolean_false_node, arg0, arg1); | 9465 return omit_two_operands_loc (loc, type, boolean_false_node, |
9466 arg0, arg1); | |
9155 else if (code == NE_EXPR) | 9467 else if (code == NE_EXPR) |
9156 return omit_two_operands (type, boolean_true_node, arg0, arg1); | 9468 return omit_two_operands_loc (loc, type, boolean_true_node, |
9469 arg0, arg1); | |
9157 } | 9470 } |
9158 /* For equal offsets we can simplify to a comparison of the | 9471 /* For equal offsets we can simplify to a comparison of the |
9159 base addresses. */ | 9472 base addresses. */ |
9160 else if (bitpos0 == bitpos1 | 9473 else if (bitpos0 == bitpos1 |
9161 && (indirect_base0 | 9474 && (indirect_base0 |
9165 && ((offset0 == offset1) | 9478 && ((offset0 == offset1) |
9166 || (offset0 && offset1 | 9479 || (offset0 && offset1 |
9167 && operand_equal_p (offset0, offset1, 0)))) | 9480 && operand_equal_p (offset0, offset1, 0)))) |
9168 { | 9481 { |
9169 if (indirect_base0) | 9482 if (indirect_base0) |
9170 base0 = fold_addr_expr (base0); | 9483 base0 = build_fold_addr_expr_loc (loc, base0); |
9171 if (indirect_base1) | 9484 if (indirect_base1) |
9172 base1 = fold_addr_expr (base1); | 9485 base1 = build_fold_addr_expr_loc (loc, base1); |
9173 return fold_build2 (code, type, base0, base1); | 9486 return fold_build2_loc (loc, code, type, base0, base1); |
9174 } | 9487 } |
9175 } | 9488 } |
9176 | 9489 |
9177 /* Transform comparisons of the form X +- C1 CMP Y +- C2 to | 9490 /* Transform comparisons of the form X +- C1 CMP Y +- C2 to |
9178 X CMP Y +- C2 +- C1 for signed X, Y. This is valid if | 9491 X CMP Y +- C2 +- C1 for signed X, Y. This is valid if |
9202 const2, const1, 0); | 9515 const2, const1, 0); |
9203 if (!TREE_OVERFLOW (cst) | 9516 if (!TREE_OVERFLOW (cst) |
9204 && tree_int_cst_compare (const2, cst) == tree_int_cst_sgn (const2)) | 9517 && tree_int_cst_compare (const2, cst) == tree_int_cst_sgn (const2)) |
9205 { | 9518 { |
9206 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); | 9519 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); |
9207 return fold_build2 (code, type, | 9520 return fold_build2_loc (loc, code, type, |
9208 variable1, | 9521 variable1, |
9209 fold_build2 (TREE_CODE (arg1), TREE_TYPE (arg1), | 9522 fold_build2_loc (loc, |
9523 TREE_CODE (arg1), TREE_TYPE (arg1), | |
9210 variable2, cst)); | 9524 variable2, cst)); |
9211 } | 9525 } |
9212 | 9526 |
9213 cst = int_const_binop (TREE_CODE (arg0) == TREE_CODE (arg1) | 9527 cst = int_const_binop (TREE_CODE (arg0) == TREE_CODE (arg1) |
9214 ? MINUS_EXPR : PLUS_EXPR, | 9528 ? MINUS_EXPR : PLUS_EXPR, |
9215 const1, const2, 0); | 9529 const1, const2, 0); |
9216 if (!TREE_OVERFLOW (cst) | 9530 if (!TREE_OVERFLOW (cst) |
9217 && tree_int_cst_compare (const1, cst) == tree_int_cst_sgn (const1)) | 9531 && tree_int_cst_compare (const1, cst) == tree_int_cst_sgn (const1)) |
9218 { | 9532 { |
9219 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); | 9533 fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); |
9220 return fold_build2 (code, type, | 9534 return fold_build2_loc (loc, code, type, |
9221 fold_build2 (TREE_CODE (arg0), TREE_TYPE (arg0), | 9535 fold_build2_loc (loc, TREE_CODE (arg0), TREE_TYPE (arg0), |
9222 variable1, cst), | 9536 variable1, cst), |
9223 variable2); | 9537 variable2); |
9224 } | 9538 } |
9225 } | 9539 } |
9226 | 9540 |
9248 | 9562 |
9249 /* If const1 is negative we swap the sense of the comparison. */ | 9563 /* If const1 is negative we swap the sense of the comparison. */ |
9250 if (tree_int_cst_sgn (const1) < 0) | 9564 if (tree_int_cst_sgn (const1) < 0) |
9251 cmp_code = swap_tree_comparison (cmp_code); | 9565 cmp_code = swap_tree_comparison (cmp_code); |
9252 | 9566 |
9253 return fold_build2 (cmp_code, type, variable1, const2); | 9567 return fold_build2_loc (loc, cmp_code, type, variable1, const2); |
9254 } | 9568 } |
9255 | 9569 |
9256 tem = maybe_canonicalize_comparison (code, type, op0, op1); | 9570 tem = maybe_canonicalize_comparison (loc, code, type, op0, op1); |
9257 if (tem) | 9571 if (tem) |
9258 return tem; | 9572 return tem; |
9259 | 9573 |
9260 if (FLOAT_TYPE_P (TREE_TYPE (arg0))) | 9574 if (FLOAT_TYPE_P (TREE_TYPE (arg0))) |
9261 { | 9575 { |
9266 if (TYPE_PRECISION (TREE_TYPE (targ1)) > TYPE_PRECISION (newtype)) | 9580 if (TYPE_PRECISION (TREE_TYPE (targ1)) > TYPE_PRECISION (newtype)) |
9267 newtype = TREE_TYPE (targ1); | 9581 newtype = TREE_TYPE (targ1); |
9268 | 9582 |
9269 /* Fold (double)float1 CMP (double)float2 into float1 CMP float2. */ | 9583 /* Fold (double)float1 CMP (double)float2 into float1 CMP float2. */ |
9270 if (TYPE_PRECISION (newtype) < TYPE_PRECISION (TREE_TYPE (arg0))) | 9584 if (TYPE_PRECISION (newtype) < TYPE_PRECISION (TREE_TYPE (arg0))) |
9271 return fold_build2 (code, type, fold_convert (newtype, targ0), | 9585 return fold_build2_loc (loc, code, type, |
9272 fold_convert (newtype, targ1)); | 9586 fold_convert_loc (loc, newtype, targ0), |
9587 fold_convert_loc (loc, newtype, targ1)); | |
9273 | 9588 |
9274 /* (-a) CMP (-b) -> b CMP a */ | 9589 /* (-a) CMP (-b) -> b CMP a */ |
9275 if (TREE_CODE (arg0) == NEGATE_EXPR | 9590 if (TREE_CODE (arg0) == NEGATE_EXPR |
9276 && TREE_CODE (arg1) == NEGATE_EXPR) | 9591 && TREE_CODE (arg1) == NEGATE_EXPR) |
9277 return fold_build2 (code, type, TREE_OPERAND (arg1, 0), | 9592 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg1, 0), |
9278 TREE_OPERAND (arg0, 0)); | 9593 TREE_OPERAND (arg0, 0)); |
9279 | 9594 |
9280 if (TREE_CODE (arg1) == REAL_CST) | 9595 if (TREE_CODE (arg1) == REAL_CST) |
9281 { | 9596 { |
9282 REAL_VALUE_TYPE cst; | 9597 REAL_VALUE_TYPE cst; |
9283 cst = TREE_REAL_CST (arg1); | 9598 cst = TREE_REAL_CST (arg1); |
9284 | 9599 |
9285 /* (-a) CMP CST -> a swap(CMP) (-CST) */ | 9600 /* (-a) CMP CST -> a swap(CMP) (-CST) */ |
9286 if (TREE_CODE (arg0) == NEGATE_EXPR) | 9601 if (TREE_CODE (arg0) == NEGATE_EXPR) |
9287 return fold_build2 (swap_tree_comparison (code), type, | 9602 return fold_build2_loc (loc, swap_tree_comparison (code), type, |
9288 TREE_OPERAND (arg0, 0), | 9603 TREE_OPERAND (arg0, 0), |
9289 build_real (TREE_TYPE (arg1), | 9604 build_real (TREE_TYPE (arg1), |
9290 REAL_VALUE_NEGATE (cst))); | 9605 REAL_VALUE_NEGATE (cst))); |
9291 | 9606 |
9292 /* IEEE doesn't distinguish +0 and -0 in comparisons. */ | 9607 /* IEEE doesn't distinguish +0 and -0 in comparisons. */ |
9293 /* a CMP (-0) -> a CMP 0 */ | 9608 /* a CMP (-0) -> a CMP 0 */ |
9294 if (REAL_VALUE_MINUS_ZERO (cst)) | 9609 if (REAL_VALUE_MINUS_ZERO (cst)) |
9295 return fold_build2 (code, type, arg0, | 9610 return fold_build2_loc (loc, code, type, arg0, |
9296 build_real (TREE_TYPE (arg1), dconst0)); | 9611 build_real (TREE_TYPE (arg1), dconst0)); |
9297 | 9612 |
9298 /* x != NaN is always true, other ops are always false. */ | 9613 /* x != NaN is always true, other ops are always false. */ |
9299 if (REAL_VALUE_ISNAN (cst) | 9614 if (REAL_VALUE_ISNAN (cst) |
9300 && ! HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1)))) | 9615 && ! HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1)))) |
9301 { | 9616 { |
9302 tem = (code == NE_EXPR) ? integer_one_node : integer_zero_node; | 9617 tem = (code == NE_EXPR) ? integer_one_node : integer_zero_node; |
9303 return omit_one_operand (type, tem, arg0); | 9618 return omit_one_operand_loc (loc, type, tem, arg0); |
9304 } | 9619 } |
9305 | 9620 |
9306 /* Fold comparisons against infinity. */ | 9621 /* Fold comparisons against infinity. */ |
9307 if (REAL_VALUE_ISINF (cst) | 9622 if (REAL_VALUE_ISINF (cst) |
9308 && MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg1)))) | 9623 && MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg1)))) |
9309 { | 9624 { |
9310 tem = fold_inf_compare (code, type, arg0, arg1); | 9625 tem = fold_inf_compare (loc, code, type, arg0, arg1); |
9311 if (tem != NULL_TREE) | 9626 if (tem != NULL_TREE) |
9312 return tem; | 9627 return tem; |
9313 } | 9628 } |
9314 } | 9629 } |
9315 | 9630 |
9324 && TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST | 9639 && TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST |
9325 && 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR | 9640 && 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR |
9326 ? MINUS_EXPR : PLUS_EXPR, | 9641 ? MINUS_EXPR : PLUS_EXPR, |
9327 arg1, TREE_OPERAND (arg0, 1), 0)) | 9642 arg1, TREE_OPERAND (arg0, 1), 0)) |
9328 && !TREE_OVERFLOW (tem)) | 9643 && !TREE_OVERFLOW (tem)) |
9329 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), tem); | 9644 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem); |
9330 | 9645 |
9331 /* Likewise, we can simplify a comparison of a real constant with | 9646 /* Likewise, we can simplify a comparison of a real constant with |
9332 a MINUS_EXPR whose first operand is also a real constant, i.e. | 9647 a MINUS_EXPR whose first operand is also a real constant, i.e. |
9333 (c1 - x) < c2 becomes x > c1-c2. Reordering is allowed on | 9648 (c1 - x) < c2 becomes x > c1-c2. Reordering is allowed on |
9334 floating-point types only if -fassociative-math is set. */ | 9649 floating-point types only if -fassociative-math is set. */ |
9335 if (flag_associative_math | 9650 if (flag_associative_math |
9336 && TREE_CODE (arg1) == REAL_CST | 9651 && TREE_CODE (arg1) == REAL_CST |
9337 && TREE_CODE (arg0) == MINUS_EXPR | 9652 && TREE_CODE (arg0) == MINUS_EXPR |
9338 && TREE_CODE (TREE_OPERAND (arg0, 0)) == REAL_CST | 9653 && TREE_CODE (TREE_OPERAND (arg0, 0)) == REAL_CST |
9339 && 0 != (tem = const_binop (MINUS_EXPR, TREE_OPERAND (arg0, 0), | 9654 && 0 != (tem = const_binop (MINUS_EXPR, TREE_OPERAND (arg0, 0), |
9340 arg1, 0)) | 9655 arg1, 0)) |
9341 && !TREE_OVERFLOW (tem)) | 9656 && !TREE_OVERFLOW (tem)) |
9342 return fold_build2 (swap_tree_comparison (code), type, | 9657 return fold_build2_loc (loc, swap_tree_comparison (code), type, |
9343 TREE_OPERAND (arg0, 1), tem); | 9658 TREE_OPERAND (arg0, 1), tem); |
9344 | 9659 |
9345 /* Fold comparisons against built-in math functions. */ | 9660 /* Fold comparisons against built-in math functions. */ |
9346 if (TREE_CODE (arg1) == REAL_CST | 9661 if (TREE_CODE (arg1) == REAL_CST |
9347 && flag_unsafe_math_optimizations | 9662 && flag_unsafe_math_optimizations |
9349 { | 9664 { |
9350 enum built_in_function fcode = builtin_mathfn_code (arg0); | 9665 enum built_in_function fcode = builtin_mathfn_code (arg0); |
9351 | 9666 |
9352 if (fcode != END_BUILTINS) | 9667 if (fcode != END_BUILTINS) |
9353 { | 9668 { |
9354 tem = fold_mathfn_compare (fcode, code, type, arg0, arg1); | 9669 tem = fold_mathfn_compare (loc, fcode, code, type, arg0, arg1); |
9355 if (tem != NULL_TREE) | 9670 if (tem != NULL_TREE) |
9356 return tem; | 9671 return tem; |
9357 } | 9672 } |
9358 } | 9673 } |
9359 } | 9674 } |
9362 && CONVERT_EXPR_P (arg0)) | 9677 && CONVERT_EXPR_P (arg0)) |
9363 { | 9678 { |
9364 /* If we are widening one operand of an integer comparison, | 9679 /* If we are widening one operand of an integer comparison, |
9365 see if the other operand is similarly being widened. Perhaps we | 9680 see if the other operand is similarly being widened. Perhaps we |
9366 can do the comparison in the narrower type. */ | 9681 can do the comparison in the narrower type. */ |
9367 tem = fold_widened_comparison (code, type, arg0, arg1); | 9682 tem = fold_widened_comparison (loc, code, type, arg0, arg1); |
9368 if (tem) | 9683 if (tem) |
9369 return tem; | 9684 return tem; |
9370 | 9685 |
9371 /* Or if we are changing signedness. */ | 9686 /* Or if we are changing signedness. */ |
9372 tem = fold_sign_changed_comparison (code, type, arg0, arg1); | 9687 tem = fold_sign_changed_comparison (loc, code, type, arg0, arg1); |
9373 if (tem) | 9688 if (tem) |
9374 return tem; | 9689 return tem; |
9375 } | 9690 } |
9376 | 9691 |
9377 /* If this is comparing a constant with a MIN_EXPR or a MAX_EXPR of a | 9692 /* If this is comparing a constant with a MIN_EXPR or a MAX_EXPR of a |
9379 if (TREE_CODE (arg1) == INTEGER_CST | 9694 if (TREE_CODE (arg1) == INTEGER_CST |
9380 && (TREE_CODE (arg0) == MIN_EXPR | 9695 && (TREE_CODE (arg0) == MIN_EXPR |
9381 || TREE_CODE (arg0) == MAX_EXPR) | 9696 || TREE_CODE (arg0) == MAX_EXPR) |
9382 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) | 9697 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) |
9383 { | 9698 { |
9384 tem = optimize_minmax_comparison (code, type, op0, op1); | 9699 tem = optimize_minmax_comparison (loc, code, type, op0, op1); |
9385 if (tem) | 9700 if (tem) |
9386 return tem; | 9701 return tem; |
9387 } | 9702 } |
9388 | 9703 |
9389 /* Simplify comparison of something with itself. (For IEEE | 9704 /* Simplify comparison of something with itself. (For IEEE |
9401 case GE_EXPR: | 9716 case GE_EXPR: |
9402 case LE_EXPR: | 9717 case LE_EXPR: |
9403 if (! FLOAT_TYPE_P (TREE_TYPE (arg0)) | 9718 if (! FLOAT_TYPE_P (TREE_TYPE (arg0)) |
9404 || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))) | 9719 || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))) |
9405 return constant_boolean_node (1, type); | 9720 return constant_boolean_node (1, type); |
9406 return fold_build2 (EQ_EXPR, type, arg0, arg1); | 9721 return fold_build2_loc (loc, EQ_EXPR, type, arg0, arg1); |
9407 | 9722 |
9408 case NE_EXPR: | 9723 case NE_EXPR: |
9409 /* For NE, we can only do this simplification if integer | 9724 /* For NE, we can only do this simplification if integer |
9410 or we don't honor IEEE floating point NaNs. */ | 9725 or we don't honor IEEE floating point NaNs. */ |
9411 if (FLOAT_TYPE_P (TREE_TYPE (arg0)) | 9726 if (FLOAT_TYPE_P (TREE_TYPE (arg0)) |
9455 | 9770 |
9456 /* We can't just pass T to eval_subst in case cval1 or cval2 | 9771 /* We can't just pass T to eval_subst in case cval1 or cval2 |
9457 was the same as ARG1. */ | 9772 was the same as ARG1. */ |
9458 | 9773 |
9459 tree high_result | 9774 tree high_result |
9460 = fold_build2 (code, type, | 9775 = fold_build2_loc (loc, code, type, |
9461 eval_subst (arg0, cval1, maxval, | 9776 eval_subst (loc, arg0, cval1, maxval, |
9462 cval2, minval), | 9777 cval2, minval), |
9463 arg1); | 9778 arg1); |
9464 tree equal_result | 9779 tree equal_result |
9465 = fold_build2 (code, type, | 9780 = fold_build2_loc (loc, code, type, |
9466 eval_subst (arg0, cval1, maxval, | 9781 eval_subst (loc, arg0, cval1, maxval, |
9467 cval2, maxval), | 9782 cval2, maxval), |
9468 arg1); | 9783 arg1); |
9469 tree low_result | 9784 tree low_result |
9470 = fold_build2 (code, type, | 9785 = fold_build2_loc (loc, code, type, |
9471 eval_subst (arg0, cval1, minval, | 9786 eval_subst (loc, arg0, cval1, minval, |
9472 cval2, maxval), | 9787 cval2, maxval), |
9473 arg1); | 9788 arg1); |
9474 | 9789 |
9475 /* All three of these results should be 0 or 1. Confirm they are. | 9790 /* All three of these results should be 0 or 1. Confirm they are. |
9476 Then use those values to select the proper code to use. */ | 9791 Then use those values to select the proper code to use. */ |
9485 + (integer_onep (equal_result) * 2) | 9800 + (integer_onep (equal_result) * 2) |
9486 + integer_onep (low_result)) | 9801 + integer_onep (low_result)) |
9487 { | 9802 { |
9488 case 0: | 9803 case 0: |
9489 /* Always false. */ | 9804 /* Always false. */ |
9490 return omit_one_operand (type, integer_zero_node, arg0); | 9805 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
9491 case 1: | 9806 case 1: |
9492 code = LT_EXPR; | 9807 code = LT_EXPR; |
9493 break; | 9808 break; |
9494 case 2: | 9809 case 2: |
9495 code = EQ_EXPR; | 9810 code = EQ_EXPR; |
9506 case 6: | 9821 case 6: |
9507 code = GE_EXPR; | 9822 code = GE_EXPR; |
9508 break; | 9823 break; |
9509 case 7: | 9824 case 7: |
9510 /* Always true. */ | 9825 /* Always true. */ |
9511 return omit_one_operand (type, integer_one_node, arg0); | 9826 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
9512 } | 9827 } |
9513 | 9828 |
9514 if (save_p) | 9829 if (save_p) |
9515 return save_expr (build2 (code, type, cval1, cval2)); | 9830 { |
9516 return fold_build2 (code, type, cval1, cval2); | 9831 tem = save_expr (build2 (code, type, cval1, cval2)); |
9832 SET_EXPR_LOCATION (tem, loc); | |
9833 return tem; | |
9834 } | |
9835 return fold_build2_loc (loc, code, type, cval1, cval2); | |
9517 } | 9836 } |
9518 } | 9837 } |
9519 } | 9838 } |
9520 | 9839 |
9521 /* We can fold X/C1 op C2 where C1 and C2 are integer constants | 9840 /* We can fold X/C1 op C2 where C1 and C2 are integer constants |
9526 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST | 9845 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST |
9527 && !integer_zerop (TREE_OPERAND (arg0, 1)) | 9846 && !integer_zerop (TREE_OPERAND (arg0, 1)) |
9528 && !TREE_OVERFLOW (TREE_OPERAND (arg0, 1)) | 9847 && !TREE_OVERFLOW (TREE_OPERAND (arg0, 1)) |
9529 && !TREE_OVERFLOW (arg1)) | 9848 && !TREE_OVERFLOW (arg1)) |
9530 { | 9849 { |
9531 tem = fold_div_compare (code, type, arg0, arg1); | 9850 tem = fold_div_compare (loc, code, type, arg0, arg1); |
9532 if (tem != NULL_TREE) | 9851 if (tem != NULL_TREE) |
9533 return tem; | 9852 return tem; |
9534 } | 9853 } |
9535 | 9854 |
9536 /* Fold ~X op ~Y as Y op X. */ | 9855 /* Fold ~X op ~Y as Y op X. */ |
9537 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 9856 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
9538 && TREE_CODE (arg1) == BIT_NOT_EXPR) | 9857 && TREE_CODE (arg1) == BIT_NOT_EXPR) |
9539 { | 9858 { |
9540 tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0)); | 9859 tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0)); |
9541 return fold_build2 (code, type, | 9860 return fold_build2_loc (loc, code, type, |
9542 fold_convert (cmp_type, TREE_OPERAND (arg1, 0)), | 9861 fold_convert_loc (loc, cmp_type, |
9862 TREE_OPERAND (arg1, 0)), | |
9543 TREE_OPERAND (arg0, 0)); | 9863 TREE_OPERAND (arg0, 0)); |
9544 } | 9864 } |
9545 | 9865 |
9546 /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */ | 9866 /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */ |
9547 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 9867 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
9548 && TREE_CODE (arg1) == INTEGER_CST) | 9868 && TREE_CODE (arg1) == INTEGER_CST) |
9549 { | 9869 { |
9550 tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0)); | 9870 tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0)); |
9551 return fold_build2 (swap_tree_comparison (code), type, | 9871 return fold_build2_loc (loc, swap_tree_comparison (code), type, |
9552 TREE_OPERAND (arg0, 0), | 9872 TREE_OPERAND (arg0, 0), |
9553 fold_build1 (BIT_NOT_EXPR, cmp_type, | 9873 fold_build1_loc (loc, BIT_NOT_EXPR, cmp_type, |
9554 fold_convert (cmp_type, arg1))); | 9874 fold_convert_loc (loc, cmp_type, arg1))); |
9555 } | 9875 } |
9556 | 9876 |
9557 return NULL_TREE; | 9877 return NULL_TREE; |
9558 } | 9878 } |
9559 | 9879 |
9561 /* Subroutine of fold_binary. Optimize complex multiplications of the | 9881 /* Subroutine of fold_binary. Optimize complex multiplications of the |
9562 form z * conj(z), as pow(realpart(z),2) + pow(imagpart(z),2). The | 9882 form z * conj(z), as pow(realpart(z),2) + pow(imagpart(z),2). The |
9563 argument EXPR represents the expression "z" of type TYPE. */ | 9883 argument EXPR represents the expression "z" of type TYPE. */ |
9564 | 9884 |
9565 static tree | 9885 static tree |
9566 fold_mult_zconjz (tree type, tree expr) | 9886 fold_mult_zconjz (location_t loc, tree type, tree expr) |
9567 { | 9887 { |
9568 tree itype = TREE_TYPE (type); | 9888 tree itype = TREE_TYPE (type); |
9569 tree rpart, ipart, tem; | 9889 tree rpart, ipart, tem; |
9570 | 9890 |
9571 if (TREE_CODE (expr) == COMPLEX_EXPR) | 9891 if (TREE_CODE (expr) == COMPLEX_EXPR) |
9579 ipart = TREE_IMAGPART (expr); | 9899 ipart = TREE_IMAGPART (expr); |
9580 } | 9900 } |
9581 else | 9901 else |
9582 { | 9902 { |
9583 expr = save_expr (expr); | 9903 expr = save_expr (expr); |
9584 rpart = fold_build1 (REALPART_EXPR, itype, expr); | 9904 rpart = fold_build1_loc (loc, REALPART_EXPR, itype, expr); |
9585 ipart = fold_build1 (IMAGPART_EXPR, itype, expr); | 9905 ipart = fold_build1_loc (loc, IMAGPART_EXPR, itype, expr); |
9586 } | 9906 } |
9587 | 9907 |
9588 rpart = save_expr (rpart); | 9908 rpart = save_expr (rpart); |
9589 ipart = save_expr (ipart); | 9909 ipart = save_expr (ipart); |
9590 tem = fold_build2 (PLUS_EXPR, itype, | 9910 tem = fold_build2_loc (loc, PLUS_EXPR, itype, |
9591 fold_build2 (MULT_EXPR, itype, rpart, rpart), | 9911 fold_build2_loc (loc, MULT_EXPR, itype, rpart, rpart), |
9592 fold_build2 (MULT_EXPR, itype, ipart, ipart)); | 9912 fold_build2_loc (loc, MULT_EXPR, itype, ipart, ipart)); |
9593 return fold_build2 (COMPLEX_EXPR, type, tem, | 9913 return fold_build2_loc (loc, COMPLEX_EXPR, type, tem, |
9594 fold_convert (itype, integer_zero_node)); | 9914 fold_convert_loc (loc, itype, integer_zero_node)); |
9595 } | 9915 } |
9596 | 9916 |
9597 | 9917 |
9598 /* Subroutine of fold_binary. If P is the value of EXPR, computes | 9918 /* Subroutine of fold_binary. If P is the value of EXPR, computes |
9599 power-of-two M and (arbitrary) N such that M divides (P-N). This condition | 9919 power-of-two M and (arbitrary) N such that M divides (P-N). This condition |
9600 guarantees that P and N have the same least significant log2(M) bits. | 9920 guarantees that P and N have the same least significant log2(M) bits. |
9601 N is not otherwise constrained. In particular, N is not normalized to | 9921 N is not otherwise constrained. In particular, N is not normalized to |
9602 0 <= N < M as is common. In general, the precise value of P is unknown. | 9922 0 <= N < M as is common. In general, the precise value of P is unknown. |
9603 M is chosen as large as possible such that constant N can be determined. | 9923 M is chosen as large as possible such that constant N can be determined. |
9604 | 9924 |
9605 Returns M and sets *RESIDUE to N. */ | 9925 Returns M and sets *RESIDUE to N. |
9926 | |
9927 If ALLOW_FUNC_ALIGN is true, do take functions' DECL_ALIGN_UNIT into | |
9928 account. This is not always possible due to PR 35705. | |
9929 */ | |
9606 | 9930 |
9607 static unsigned HOST_WIDE_INT | 9931 static unsigned HOST_WIDE_INT |
9608 get_pointer_modulus_and_residue (tree expr, unsigned HOST_WIDE_INT *residue) | 9932 get_pointer_modulus_and_residue (tree expr, unsigned HOST_WIDE_INT *residue, |
9933 bool allow_func_align) | |
9609 { | 9934 { |
9610 enum tree_code code; | 9935 enum tree_code code; |
9611 | 9936 |
9612 *residue = 0; | 9937 *residue = 0; |
9613 | 9938 |
9633 /* We don't handle more complicated offset expressions. */ | 9958 /* We don't handle more complicated offset expressions. */ |
9634 return 1; | 9959 return 1; |
9635 } | 9960 } |
9636 } | 9961 } |
9637 | 9962 |
9638 if (DECL_P (expr) && TREE_CODE (expr) != FUNCTION_DECL) | 9963 if (DECL_P (expr) |
9964 && (allow_func_align || TREE_CODE (expr) != FUNCTION_DECL)) | |
9639 return DECL_ALIGN_UNIT (expr); | 9965 return DECL_ALIGN_UNIT (expr); |
9640 } | 9966 } |
9641 else if (code == POINTER_PLUS_EXPR) | 9967 else if (code == POINTER_PLUS_EXPR) |
9642 { | 9968 { |
9643 tree op0, op1; | 9969 tree op0, op1; |
9644 unsigned HOST_WIDE_INT modulus; | 9970 unsigned HOST_WIDE_INT modulus; |
9645 enum tree_code inner_code; | 9971 enum tree_code inner_code; |
9646 | 9972 |
9647 op0 = TREE_OPERAND (expr, 0); | 9973 op0 = TREE_OPERAND (expr, 0); |
9648 STRIP_NOPS (op0); | 9974 STRIP_NOPS (op0); |
9649 modulus = get_pointer_modulus_and_residue (op0, residue); | 9975 modulus = get_pointer_modulus_and_residue (op0, residue, |
9976 allow_func_align); | |
9650 | 9977 |
9651 op1 = TREE_OPERAND (expr, 1); | 9978 op1 = TREE_OPERAND (expr, 1); |
9652 STRIP_NOPS (op1); | 9979 STRIP_NOPS (op1); |
9653 inner_code = TREE_CODE (op1); | 9980 inner_code = TREE_CODE (op1); |
9654 if (inner_code == INTEGER_CST) | 9981 if (inner_code == INTEGER_CST) |
9660 { | 9987 { |
9661 op1 = TREE_OPERAND (op1, 1); | 9988 op1 = TREE_OPERAND (op1, 1); |
9662 if (TREE_CODE (op1) == INTEGER_CST) | 9989 if (TREE_CODE (op1) == INTEGER_CST) |
9663 { | 9990 { |
9664 unsigned HOST_WIDE_INT align; | 9991 unsigned HOST_WIDE_INT align; |
9665 | 9992 |
9666 /* Compute the greatest power-of-2 divisor of op1. */ | 9993 /* Compute the greatest power-of-2 divisor of op1. */ |
9667 align = TREE_INT_CST_LOW (op1); | 9994 align = TREE_INT_CST_LOW (op1); |
9668 align &= -align; | 9995 align &= -align; |
9669 | 9996 |
9670 /* If align is non-zero and less than *modulus, replace | 9997 /* If align is non-zero and less than *modulus, replace |
9685 return 1; | 10012 return 1; |
9686 } | 10013 } |
9687 | 10014 |
9688 | 10015 |
9689 /* Fold a binary expression of code CODE and type TYPE with operands | 10016 /* Fold a binary expression of code CODE and type TYPE with operands |
9690 OP0 and OP1. Return the folded expression if folding is | 10017 OP0 and OP1. LOC is the location of the resulting expression. |
9691 successful. Otherwise, return NULL_TREE. */ | 10018 Return the folded expression if folding is successful. Otherwise, |
10019 return NULL_TREE. */ | |
9692 | 10020 |
9693 tree | 10021 tree |
9694 fold_binary (enum tree_code code, tree type, tree op0, tree op1) | 10022 fold_binary_loc (location_t loc, |
10023 enum tree_code code, tree type, tree op0, tree op1) | |
9695 { | 10024 { |
9696 enum tree_code_class kind = TREE_CODE_CLASS (code); | 10025 enum tree_code_class kind = TREE_CODE_CLASS (code); |
9697 tree arg0, arg1, tem; | 10026 tree arg0, arg1, tem; |
9698 tree t1 = NULL_TREE; | 10027 tree t1 = NULL_TREE; |
9699 bool strict_overflow_p; | 10028 bool strict_overflow_p; |
9752 tem = NULL_TREE; | 10081 tem = NULL_TREE; |
9753 | 10082 |
9754 if (tem != NULL_TREE) | 10083 if (tem != NULL_TREE) |
9755 { | 10084 { |
9756 if (TREE_TYPE (tem) != type) | 10085 if (TREE_TYPE (tem) != type) |
9757 tem = fold_convert (type, tem); | 10086 tem = fold_convert_loc (loc, type, tem); |
9758 return tem; | 10087 return tem; |
9759 } | 10088 } |
9760 } | 10089 } |
9761 | 10090 |
9762 /* If this is a commutative operation, and ARG0 is a constant, move it | 10091 /* If this is a commutative operation, and ARG0 is a constant, move it |
9763 to ARG1 to reduce the number of tests below. */ | 10092 to ARG1 to reduce the number of tests below. */ |
9764 if (commutative_tree_code (code) | 10093 if (commutative_tree_code (code) |
9765 && tree_swap_operands_p (arg0, arg1, true)) | 10094 && tree_swap_operands_p (arg0, arg1, true)) |
9766 return fold_build2 (code, type, op1, op0); | 10095 return fold_build2_loc (loc, code, type, op1, op0); |
9767 | 10096 |
9768 /* ARG0 is the first operand of EXPR, and ARG1 is the second operand. | 10097 /* ARG0 is the first operand of EXPR, and ARG1 is the second operand. |
9769 | 10098 |
9770 First check for cases where an arithmetic operation is applied to a | 10099 First check for cases where an arithmetic operation is applied to a |
9771 compound, conditional, or comparison operation. Push the arithmetic | 10100 compound, conditional, or comparison operation. Push the arithmetic |
9790 || (truth_value_p (TREE_CODE (arg1)) | 10119 || (truth_value_p (TREE_CODE (arg1)) |
9791 && (truth_value_p (TREE_CODE (arg0)) | 10120 && (truth_value_p (TREE_CODE (arg0)) |
9792 || (TREE_CODE (arg0) == BIT_AND_EXPR | 10121 || (TREE_CODE (arg0) == BIT_AND_EXPR |
9793 && integer_onep (TREE_OPERAND (arg0, 1))))))) | 10122 && integer_onep (TREE_OPERAND (arg0, 1))))))) |
9794 { | 10123 { |
9795 tem = fold_build2 (code == BIT_AND_EXPR ? TRUTH_AND_EXPR | 10124 tem = fold_build2_loc (loc, code == BIT_AND_EXPR ? TRUTH_AND_EXPR |
9796 : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR | 10125 : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR |
9797 : TRUTH_XOR_EXPR, | 10126 : TRUTH_XOR_EXPR, |
9798 boolean_type_node, | 10127 boolean_type_node, |
9799 fold_convert (boolean_type_node, arg0), | 10128 fold_convert_loc (loc, boolean_type_node, arg0), |
9800 fold_convert (boolean_type_node, arg1)); | 10129 fold_convert_loc (loc, boolean_type_node, arg1)); |
9801 | 10130 |
9802 if (code == EQ_EXPR) | 10131 if (code == EQ_EXPR) |
9803 tem = invert_truthvalue (tem); | 10132 tem = invert_truthvalue_loc (loc, tem); |
9804 | 10133 |
9805 return fold_convert (type, tem); | 10134 return fold_convert_loc (loc, type, tem); |
9806 } | 10135 } |
9807 | 10136 |
9808 if (TREE_CODE_CLASS (code) == tcc_binary | 10137 if (TREE_CODE_CLASS (code) == tcc_binary |
9809 || TREE_CODE_CLASS (code) == tcc_comparison) | 10138 || TREE_CODE_CLASS (code) == tcc_comparison) |
9810 { | 10139 { |
9811 if (TREE_CODE (arg0) == COMPOUND_EXPR) | 10140 if (TREE_CODE (arg0) == COMPOUND_EXPR) |
9812 return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0), | 10141 { |
9813 fold_build2 (code, type, | 10142 tem = fold_build2_loc (loc, code, type, |
9814 fold_convert (TREE_TYPE (op0), | 10143 fold_convert_loc (loc, TREE_TYPE (op0), |
9815 TREE_OPERAND (arg0, 1)), | 10144 TREE_OPERAND (arg0, 1)), op1); |
9816 op1)); | 10145 tem = build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0), tem); |
10146 goto fold_binary_exit; | |
10147 } | |
9817 if (TREE_CODE (arg1) == COMPOUND_EXPR | 10148 if (TREE_CODE (arg1) == COMPOUND_EXPR |
9818 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) | 10149 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) |
9819 return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0), | 10150 { |
9820 fold_build2 (code, type, op0, | 10151 tem = fold_build2_loc (loc, code, type, op0, |
9821 fold_convert (TREE_TYPE (op1), | 10152 fold_convert_loc (loc, TREE_TYPE (op1), |
9822 TREE_OPERAND (arg1, 1)))); | 10153 TREE_OPERAND (arg1, 1))); |
10154 tem = build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0), tem); | |
10155 goto fold_binary_exit; | |
10156 } | |
9823 | 10157 |
9824 if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0)) | 10158 if (TREE_CODE (arg0) == COND_EXPR || COMPARISON_CLASS_P (arg0)) |
9825 { | 10159 { |
9826 tem = fold_binary_op_with_conditional_arg (code, type, op0, op1, | 10160 tem = fold_binary_op_with_conditional_arg (loc, code, type, op0, op1, |
9827 arg0, arg1, | 10161 arg0, arg1, |
9828 /*cond_first_p=*/1); | 10162 /*cond_first_p=*/1); |
9829 if (tem != NULL_TREE) | 10163 if (tem != NULL_TREE) |
9830 return tem; | 10164 return tem; |
9831 } | 10165 } |
9832 | 10166 |
9833 if (TREE_CODE (arg1) == COND_EXPR || COMPARISON_CLASS_P (arg1)) | 10167 if (TREE_CODE (arg1) == COND_EXPR || COMPARISON_CLASS_P (arg1)) |
9834 { | 10168 { |
9835 tem = fold_binary_op_with_conditional_arg (code, type, op0, op1, | 10169 tem = fold_binary_op_with_conditional_arg (loc, code, type, op0, op1, |
9836 arg1, arg0, | 10170 arg1, arg0, |
9837 /*cond_first_p=*/0); | 10171 /*cond_first_p=*/0); |
9838 if (tem != NULL_TREE) | 10172 if (tem != NULL_TREE) |
9839 return tem; | 10173 return tem; |
9840 } | 10174 } |
9841 } | 10175 } |
9843 switch (code) | 10177 switch (code) |
9844 { | 10178 { |
9845 case POINTER_PLUS_EXPR: | 10179 case POINTER_PLUS_EXPR: |
9846 /* 0 +p index -> (type)index */ | 10180 /* 0 +p index -> (type)index */ |
9847 if (integer_zerop (arg0)) | 10181 if (integer_zerop (arg0)) |
9848 return non_lvalue (fold_convert (type, arg1)); | 10182 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1)); |
9849 | 10183 |
9850 /* PTR +p 0 -> PTR */ | 10184 /* PTR +p 0 -> PTR */ |
9851 if (integer_zerop (arg1)) | 10185 if (integer_zerop (arg1)) |
9852 return non_lvalue (fold_convert (type, arg0)); | 10186 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
9853 | 10187 |
9854 /* INT +p INT -> (PTR)(INT + INT). Stripping types allows for this. */ | 10188 /* INT +p INT -> (PTR)(INT + INT). Stripping types allows for this. */ |
9855 if (INTEGRAL_TYPE_P (TREE_TYPE (arg1)) | 10189 if (INTEGRAL_TYPE_P (TREE_TYPE (arg1)) |
9856 && INTEGRAL_TYPE_P (TREE_TYPE (arg0))) | 10190 && INTEGRAL_TYPE_P (TREE_TYPE (arg0))) |
9857 return fold_convert (type, fold_build2 (PLUS_EXPR, sizetype, | 10191 return fold_convert_loc (loc, type, |
9858 fold_convert (sizetype, arg1), | 10192 fold_build2_loc (loc, PLUS_EXPR, sizetype, |
9859 fold_convert (sizetype, arg0))); | 10193 fold_convert_loc (loc, sizetype, |
10194 arg1), | |
10195 fold_convert_loc (loc, sizetype, | |
10196 arg0))); | |
9860 | 10197 |
9861 /* index +p PTR -> PTR +p index */ | 10198 /* index +p PTR -> PTR +p index */ |
9862 if (POINTER_TYPE_P (TREE_TYPE (arg1)) | 10199 if (POINTER_TYPE_P (TREE_TYPE (arg1)) |
9863 && INTEGRAL_TYPE_P (TREE_TYPE (arg0))) | 10200 && INTEGRAL_TYPE_P (TREE_TYPE (arg0))) |
9864 return fold_build2 (POINTER_PLUS_EXPR, type, | 10201 return fold_build2_loc (loc, POINTER_PLUS_EXPR, type, |
9865 fold_convert (type, arg1), | 10202 fold_convert_loc (loc, type, arg1), |
9866 fold_convert (sizetype, arg0)); | 10203 fold_convert_loc (loc, sizetype, arg0)); |
9867 | 10204 |
9868 /* (PTR +p B) +p A -> PTR +p (B + A) */ | 10205 /* (PTR +p B) +p A -> PTR +p (B + A) */ |
9869 if (TREE_CODE (arg0) == POINTER_PLUS_EXPR) | 10206 if (TREE_CODE (arg0) == POINTER_PLUS_EXPR) |
9870 { | 10207 { |
9871 tree inner; | 10208 tree inner; |
9872 tree arg01 = fold_convert (sizetype, TREE_OPERAND (arg0, 1)); | 10209 tree arg01 = fold_convert_loc (loc, sizetype, TREE_OPERAND (arg0, 1)); |
9873 tree arg00 = TREE_OPERAND (arg0, 0); | 10210 tree arg00 = TREE_OPERAND (arg0, 0); |
9874 inner = fold_build2 (PLUS_EXPR, sizetype, | 10211 inner = fold_build2_loc (loc, PLUS_EXPR, sizetype, |
9875 arg01, fold_convert (sizetype, arg1)); | 10212 arg01, fold_convert_loc (loc, sizetype, arg1)); |
9876 return fold_convert (type, | 10213 return fold_convert_loc (loc, type, |
9877 fold_build2 (POINTER_PLUS_EXPR, | 10214 fold_build2_loc (loc, POINTER_PLUS_EXPR, |
9878 TREE_TYPE (arg00), arg00, inner)); | 10215 TREE_TYPE (arg00), |
10216 arg00, inner)); | |
9879 } | 10217 } |
9880 | 10218 |
9881 /* PTR_CST +p CST -> CST1 */ | 10219 /* PTR_CST +p CST -> CST1 */ |
9882 if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) | 10220 if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) |
9883 return fold_build2 (PLUS_EXPR, type, arg0, fold_convert (type, arg1)); | 10221 return fold_build2_loc (loc, PLUS_EXPR, type, arg0, |
10222 fold_convert_loc (loc, type, arg1)); | |
9884 | 10223 |
9885 /* Try replacing &a[i1] +p c * i2 with &a[i1 + i2], if c is step | 10224 /* Try replacing &a[i1] +p c * i2 with &a[i1 + i2], if c is step |
9886 of the array. Loop optimizer sometimes produce this type of | 10225 of the array. Loop optimizer sometimes produce this type of |
9887 expressions. */ | 10226 expressions. */ |
9888 if (TREE_CODE (arg0) == ADDR_EXPR) | 10227 if (TREE_CODE (arg0) == ADDR_EXPR) |
9889 { | 10228 { |
9890 tem = try_move_mult_to_index (arg0, fold_convert (sizetype, arg1)); | 10229 tem = try_move_mult_to_index (loc, arg0, |
10230 fold_convert_loc (loc, sizetype, arg1)); | |
9891 if (tem) | 10231 if (tem) |
9892 return fold_convert (type, tem); | 10232 return fold_convert_loc (loc, type, tem); |
9893 } | 10233 } |
9894 | 10234 |
9895 return NULL_TREE; | 10235 return NULL_TREE; |
9896 | 10236 |
9897 case PLUS_EXPR: | 10237 case PLUS_EXPR: |
9898 /* A + (-B) -> A - B */ | 10238 /* A + (-B) -> A - B */ |
9899 if (TREE_CODE (arg1) == NEGATE_EXPR) | 10239 if (TREE_CODE (arg1) == NEGATE_EXPR) |
9900 return fold_build2 (MINUS_EXPR, type, | 10240 return fold_build2_loc (loc, MINUS_EXPR, type, |
9901 fold_convert (type, arg0), | 10241 fold_convert_loc (loc, type, arg0), |
9902 fold_convert (type, TREE_OPERAND (arg1, 0))); | 10242 fold_convert_loc (loc, type, |
10243 TREE_OPERAND (arg1, 0))); | |
9903 /* (-A) + B -> B - A */ | 10244 /* (-A) + B -> B - A */ |
9904 if (TREE_CODE (arg0) == NEGATE_EXPR | 10245 if (TREE_CODE (arg0) == NEGATE_EXPR |
9905 && reorder_operands_p (TREE_OPERAND (arg0, 0), arg1)) | 10246 && reorder_operands_p (TREE_OPERAND (arg0, 0), arg1)) |
9906 return fold_build2 (MINUS_EXPR, type, | 10247 return fold_build2_loc (loc, MINUS_EXPR, type, |
9907 fold_convert (type, arg1), | 10248 fold_convert_loc (loc, type, arg1), |
9908 fold_convert (type, TREE_OPERAND (arg0, 0))); | 10249 fold_convert_loc (loc, type, |
10250 TREE_OPERAND (arg0, 0))); | |
9909 | 10251 |
9910 if (INTEGRAL_TYPE_P (type)) | 10252 if (INTEGRAL_TYPE_P (type)) |
9911 { | 10253 { |
9912 /* Convert ~A + 1 to -A. */ | 10254 /* Convert ~A + 1 to -A. */ |
9913 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 10255 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
9914 && integer_onep (arg1)) | 10256 && integer_onep (arg1)) |
9915 return fold_build1 (NEGATE_EXPR, type, | 10257 return fold_build1_loc (loc, NEGATE_EXPR, type, |
9916 fold_convert (type, TREE_OPERAND (arg0, 0))); | 10258 fold_convert_loc (loc, type, |
10259 TREE_OPERAND (arg0, 0))); | |
9917 | 10260 |
9918 /* ~X + X is -1. */ | 10261 /* ~X + X is -1. */ |
9919 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 10262 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
9920 && !TYPE_OVERFLOW_TRAPS (type)) | 10263 && !TYPE_OVERFLOW_TRAPS (type)) |
9921 { | 10264 { |
9923 | 10266 |
9924 STRIP_NOPS (tem); | 10267 STRIP_NOPS (tem); |
9925 if (operand_equal_p (tem, arg1, 0)) | 10268 if (operand_equal_p (tem, arg1, 0)) |
9926 { | 10269 { |
9927 t1 = build_int_cst_type (type, -1); | 10270 t1 = build_int_cst_type (type, -1); |
9928 return omit_one_operand (type, t1, arg1); | 10271 return omit_one_operand_loc (loc, type, t1, arg1); |
9929 } | 10272 } |
9930 } | 10273 } |
9931 | 10274 |
9932 /* X + ~X is -1. */ | 10275 /* X + ~X is -1. */ |
9933 if (TREE_CODE (arg1) == BIT_NOT_EXPR | 10276 if (TREE_CODE (arg1) == BIT_NOT_EXPR |
9937 | 10280 |
9938 STRIP_NOPS (tem); | 10281 STRIP_NOPS (tem); |
9939 if (operand_equal_p (arg0, tem, 0)) | 10282 if (operand_equal_p (arg0, tem, 0)) |
9940 { | 10283 { |
9941 t1 = build_int_cst_type (type, -1); | 10284 t1 = build_int_cst_type (type, -1); |
9942 return omit_one_operand (type, t1, arg0); | 10285 return omit_one_operand_loc (loc, type, t1, arg0); |
9943 } | 10286 } |
9944 } | 10287 } |
9945 | 10288 |
9946 /* X + (X / CST) * -CST is X % CST. */ | 10289 /* X + (X / CST) * -CST is X % CST. */ |
9947 if (TREE_CODE (arg1) == MULT_EXPR | 10290 if (TREE_CODE (arg1) == MULT_EXPR |
9949 && operand_equal_p (arg0, | 10292 && operand_equal_p (arg0, |
9950 TREE_OPERAND (TREE_OPERAND (arg1, 0), 0), 0)) | 10293 TREE_OPERAND (TREE_OPERAND (arg1, 0), 0), 0)) |
9951 { | 10294 { |
9952 tree cst0 = TREE_OPERAND (TREE_OPERAND (arg1, 0), 1); | 10295 tree cst0 = TREE_OPERAND (TREE_OPERAND (arg1, 0), 1); |
9953 tree cst1 = TREE_OPERAND (arg1, 1); | 10296 tree cst1 = TREE_OPERAND (arg1, 1); |
9954 tree sum = fold_binary (PLUS_EXPR, TREE_TYPE (cst1), cst1, cst0); | 10297 tree sum = fold_binary_loc (loc, PLUS_EXPR, TREE_TYPE (cst1), |
10298 cst1, cst0); | |
9955 if (sum && integer_zerop (sum)) | 10299 if (sum && integer_zerop (sum)) |
9956 return fold_convert (type, | 10300 return fold_convert_loc (loc, type, |
9957 fold_build2 (TRUNC_MOD_EXPR, | 10301 fold_build2_loc (loc, TRUNC_MOD_EXPR, |
9958 TREE_TYPE (arg0), arg0, cst0)); | 10302 TREE_TYPE (arg0), arg0, |
10303 cst0)); | |
9959 } | 10304 } |
9960 } | 10305 } |
9961 | 10306 |
9962 /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the | 10307 /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the |
9963 same or one. Make sure type is not saturating. | 10308 same or one. Make sure type is not saturating. |
9965 if ((TREE_CODE (arg0) == MULT_EXPR | 10310 if ((TREE_CODE (arg0) == MULT_EXPR |
9966 || TREE_CODE (arg1) == MULT_EXPR) | 10311 || TREE_CODE (arg1) == MULT_EXPR) |
9967 && !TYPE_SATURATING (type) | 10312 && !TYPE_SATURATING (type) |
9968 && (!FLOAT_TYPE_P (type) || flag_associative_math)) | 10313 && (!FLOAT_TYPE_P (type) || flag_associative_math)) |
9969 { | 10314 { |
9970 tree tem = fold_plusminus_mult_expr (code, type, arg0, arg1); | 10315 tree tem = fold_plusminus_mult_expr (loc, code, type, arg0, arg1); |
9971 if (tem) | 10316 if (tem) |
9972 return tem; | 10317 return tem; |
9973 } | 10318 } |
9974 | 10319 |
9975 if (! FLOAT_TYPE_P (type)) | 10320 if (! FLOAT_TYPE_P (type)) |
9976 { | 10321 { |
9977 if (integer_zerop (arg1)) | 10322 if (integer_zerop (arg1)) |
9978 return non_lvalue (fold_convert (type, arg0)); | 10323 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
9979 | 10324 |
9980 /* If we are adding two BIT_AND_EXPR's, both of which are and'ing | 10325 /* If we are adding two BIT_AND_EXPR's, both of which are and'ing |
9981 with a constant, and the two constants have no bits in common, | 10326 with a constant, and the two constants have no bits in common, |
9982 we should treat this as a BIT_IOR_EXPR since this may produce more | 10327 we should treat this as a BIT_IOR_EXPR since this may produce more |
9983 simplifications. */ | 10328 simplifications. */ |
10016 STRIP_NOPS (parg0); | 10361 STRIP_NOPS (parg0); |
10017 STRIP_NOPS (parg1); | 10362 STRIP_NOPS (parg1); |
10018 | 10363 |
10019 if (TREE_CODE (parg0) == MULT_EXPR | 10364 if (TREE_CODE (parg0) == MULT_EXPR |
10020 && TREE_CODE (parg1) != MULT_EXPR) | 10365 && TREE_CODE (parg1) != MULT_EXPR) |
10021 return fold_build2 (pcode, type, | 10366 return fold_build2_loc (loc, pcode, type, |
10022 fold_build2 (PLUS_EXPR, type, | 10367 fold_build2_loc (loc, PLUS_EXPR, type, |
10023 fold_convert (type, parg0), | 10368 fold_convert_loc (loc, type, |
10024 fold_convert (type, marg)), | 10369 parg0), |
10025 fold_convert (type, parg1)); | 10370 fold_convert_loc (loc, type, |
10371 marg)), | |
10372 fold_convert_loc (loc, type, parg1)); | |
10026 if (TREE_CODE (parg0) != MULT_EXPR | 10373 if (TREE_CODE (parg0) != MULT_EXPR |
10027 && TREE_CODE (parg1) == MULT_EXPR) | 10374 && TREE_CODE (parg1) == MULT_EXPR) |
10028 return fold_build2 (PLUS_EXPR, type, | 10375 return |
10029 fold_convert (type, parg0), | 10376 fold_build2_loc (loc, PLUS_EXPR, type, |
10030 fold_build2 (pcode, type, | 10377 fold_convert_loc (loc, type, parg0), |
10031 fold_convert (type, marg), | 10378 fold_build2_loc (loc, pcode, type, |
10032 fold_convert (type, | 10379 fold_convert_loc (loc, type, marg), |
10033 parg1))); | 10380 fold_convert_loc (loc, type, |
10381 parg1))); | |
10034 } | 10382 } |
10035 } | 10383 } |
10036 else | 10384 else |
10037 { | 10385 { |
10038 /* See if ARG1 is zero and X + ARG1 reduces to X. */ | 10386 /* See if ARG1 is zero and X + ARG1 reduces to X. */ |
10039 if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 0)) | 10387 if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 0)) |
10040 return non_lvalue (fold_convert (type, arg0)); | 10388 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
10041 | 10389 |
10042 /* Likewise if the operands are reversed. */ | 10390 /* Likewise if the operands are reversed. */ |
10043 if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0)) | 10391 if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0)) |
10044 return non_lvalue (fold_convert (type, arg1)); | 10392 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1)); |
10045 | 10393 |
10046 /* Convert X + -C into X - C. */ | 10394 /* Convert X + -C into X - C. */ |
10047 if (TREE_CODE (arg1) == REAL_CST | 10395 if (TREE_CODE (arg1) == REAL_CST |
10048 && REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1))) | 10396 && REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1))) |
10049 { | 10397 { |
10050 tem = fold_negate_const (arg1, type); | 10398 tem = fold_negate_const (arg1, type); |
10051 if (!TREE_OVERFLOW (arg1) || !flag_trapping_math) | 10399 if (!TREE_OVERFLOW (arg1) || !flag_trapping_math) |
10052 return fold_build2 (MINUS_EXPR, type, | 10400 return fold_build2_loc (loc, MINUS_EXPR, type, |
10053 fold_convert (type, arg0), | 10401 fold_convert_loc (loc, type, arg0), |
10054 fold_convert (type, tem)); | 10402 fold_convert_loc (loc, type, tem)); |
10055 } | 10403 } |
10056 | 10404 |
10057 /* Fold __complex__ ( x, 0 ) + __complex__ ( 0, y ) | 10405 /* Fold __complex__ ( x, 0 ) + __complex__ ( 0, y ) |
10058 to __complex__ ( x, y ). This is not the same for SNaNs or | 10406 to __complex__ ( x, y ). This is not the same for SNaNs or |
10059 if signed zeros are involved. */ | 10407 if signed zeros are involved. */ |
10060 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) | 10408 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) |
10061 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))) | 10409 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))) |
10062 && COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))) | 10410 && COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))) |
10063 { | 10411 { |
10064 tree rtype = TREE_TYPE (TREE_TYPE (arg0)); | 10412 tree rtype = TREE_TYPE (TREE_TYPE (arg0)); |
10065 tree arg0r = fold_unary (REALPART_EXPR, rtype, arg0); | 10413 tree arg0r = fold_unary_loc (loc, REALPART_EXPR, rtype, arg0); |
10066 tree arg0i = fold_unary (IMAGPART_EXPR, rtype, arg0); | 10414 tree arg0i = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg0); |
10067 bool arg0rz = false, arg0iz = false; | 10415 bool arg0rz = false, arg0iz = false; |
10068 if ((arg0r && (arg0rz = real_zerop (arg0r))) | 10416 if ((arg0r && (arg0rz = real_zerop (arg0r))) |
10069 || (arg0i && (arg0iz = real_zerop (arg0i)))) | 10417 || (arg0i && (arg0iz = real_zerop (arg0i)))) |
10070 { | 10418 { |
10071 tree arg1r = fold_unary (REALPART_EXPR, rtype, arg1); | 10419 tree arg1r = fold_unary_loc (loc, REALPART_EXPR, rtype, arg1); |
10072 tree arg1i = fold_unary (IMAGPART_EXPR, rtype, arg1); | 10420 tree arg1i = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg1); |
10073 if (arg0rz && arg1i && real_zerop (arg1i)) | 10421 if (arg0rz && arg1i && real_zerop (arg1i)) |
10074 { | 10422 { |
10075 tree rp = arg1r ? arg1r | 10423 tree rp = arg1r ? arg1r |
10076 : build1 (REALPART_EXPR, rtype, arg1); | 10424 : build1 (REALPART_EXPR, rtype, arg1); |
10077 tree ip = arg0i ? arg0i | 10425 tree ip = arg0i ? arg0i |
10078 : build1 (IMAGPART_EXPR, rtype, arg0); | 10426 : build1 (IMAGPART_EXPR, rtype, arg0); |
10079 return fold_build2 (COMPLEX_EXPR, type, rp, ip); | 10427 return fold_build2_loc (loc, COMPLEX_EXPR, type, rp, ip); |
10080 } | 10428 } |
10081 else if (arg0iz && arg1r && real_zerop (arg1r)) | 10429 else if (arg0iz && arg1r && real_zerop (arg1r)) |
10082 { | 10430 { |
10083 tree rp = arg0r ? arg0r | 10431 tree rp = arg0r ? arg0r |
10084 : build1 (REALPART_EXPR, rtype, arg0); | 10432 : build1 (REALPART_EXPR, rtype, arg0); |
10085 tree ip = arg1i ? arg1i | 10433 tree ip = arg1i ? arg1i |
10086 : build1 (IMAGPART_EXPR, rtype, arg1); | 10434 : build1 (IMAGPART_EXPR, rtype, arg1); |
10087 return fold_build2 (COMPLEX_EXPR, type, rp, ip); | 10435 return fold_build2_loc (loc, COMPLEX_EXPR, type, rp, ip); |
10088 } | 10436 } |
10089 } | 10437 } |
10090 } | 10438 } |
10091 | 10439 |
10092 if (flag_unsafe_math_optimizations | 10440 if (flag_unsafe_math_optimizations |
10093 && (TREE_CODE (arg0) == RDIV_EXPR || TREE_CODE (arg0) == MULT_EXPR) | 10441 && (TREE_CODE (arg0) == RDIV_EXPR || TREE_CODE (arg0) == MULT_EXPR) |
10094 && (TREE_CODE (arg1) == RDIV_EXPR || TREE_CODE (arg1) == MULT_EXPR) | 10442 && (TREE_CODE (arg1) == RDIV_EXPR || TREE_CODE (arg1) == MULT_EXPR) |
10095 && (tem = distribute_real_division (code, type, arg0, arg1))) | 10443 && (tem = distribute_real_division (loc, code, type, arg0, arg1))) |
10096 return tem; | 10444 return tem; |
10097 | 10445 |
10098 /* Convert x+x into x*2.0. */ | 10446 /* Convert x+x into x*2.0. */ |
10099 if (operand_equal_p (arg0, arg1, 0) | 10447 if (operand_equal_p (arg0, arg1, 0) |
10100 && SCALAR_FLOAT_TYPE_P (type)) | 10448 && SCALAR_FLOAT_TYPE_P (type)) |
10101 return fold_build2 (MULT_EXPR, type, arg0, | 10449 return fold_build2_loc (loc, MULT_EXPR, type, arg0, |
10102 build_real (type, dconst2)); | 10450 build_real (type, dconst2)); |
10103 | 10451 |
10104 /* Convert a + (b*c + d*e) into (a + b*c) + d*e. | 10452 /* Convert a + (b*c + d*e) into (a + b*c) + d*e. |
10105 We associate floats only if the user has specified | 10453 We associate floats only if the user has specified |
10106 -fassociative-math. */ | 10454 -fassociative-math. */ |
10107 if (flag_associative_math | 10455 if (flag_associative_math |
10108 && TREE_CODE (arg1) == PLUS_EXPR | 10456 && TREE_CODE (arg1) == PLUS_EXPR |
10109 && TREE_CODE (arg0) != MULT_EXPR) | 10457 && TREE_CODE (arg0) != MULT_EXPR) |
10112 tree tree11 = TREE_OPERAND (arg1, 1); | 10460 tree tree11 = TREE_OPERAND (arg1, 1); |
10113 if (TREE_CODE (tree11) == MULT_EXPR | 10461 if (TREE_CODE (tree11) == MULT_EXPR |
10114 && TREE_CODE (tree10) == MULT_EXPR) | 10462 && TREE_CODE (tree10) == MULT_EXPR) |
10115 { | 10463 { |
10116 tree tree0; | 10464 tree tree0; |
10117 tree0 = fold_build2 (PLUS_EXPR, type, arg0, tree10); | 10465 tree0 = fold_build2_loc (loc, PLUS_EXPR, type, arg0, tree10); |
10118 return fold_build2 (PLUS_EXPR, type, tree0, tree11); | 10466 return fold_build2_loc (loc, PLUS_EXPR, type, tree0, tree11); |
10119 } | 10467 } |
10120 } | 10468 } |
10121 /* Convert (b*c + d*e) + a into b*c + (d*e +a). | 10469 /* Convert (b*c + d*e) + a into b*c + (d*e +a). |
10122 We associate floats only if the user has specified | 10470 We associate floats only if the user has specified |
10123 -fassociative-math. */ | 10471 -fassociative-math. */ |
10124 if (flag_associative_math | 10472 if (flag_associative_math |
10125 && TREE_CODE (arg0) == PLUS_EXPR | 10473 && TREE_CODE (arg0) == PLUS_EXPR |
10126 && TREE_CODE (arg1) != MULT_EXPR) | 10474 && TREE_CODE (arg1) != MULT_EXPR) |
10129 tree tree01 = TREE_OPERAND (arg0, 1); | 10477 tree tree01 = TREE_OPERAND (arg0, 1); |
10130 if (TREE_CODE (tree01) == MULT_EXPR | 10478 if (TREE_CODE (tree01) == MULT_EXPR |
10131 && TREE_CODE (tree00) == MULT_EXPR) | 10479 && TREE_CODE (tree00) == MULT_EXPR) |
10132 { | 10480 { |
10133 tree tree0; | 10481 tree tree0; |
10134 tree0 = fold_build2 (PLUS_EXPR, type, tree01, arg1); | 10482 tree0 = fold_build2_loc (loc, PLUS_EXPR, type, tree01, arg1); |
10135 return fold_build2 (PLUS_EXPR, type, tree00, tree0); | 10483 return fold_build2_loc (loc, PLUS_EXPR, type, tree00, tree0); |
10136 } | 10484 } |
10137 } | 10485 } |
10138 } | 10486 } |
10139 | 10487 |
10140 bit_rotate: | 10488 bit_rotate: |
10170 && code11 == INTEGER_CST | 10518 && code11 == INTEGER_CST |
10171 && TREE_INT_CST_HIGH (tree01) == 0 | 10519 && TREE_INT_CST_HIGH (tree01) == 0 |
10172 && TREE_INT_CST_HIGH (tree11) == 0 | 10520 && TREE_INT_CST_HIGH (tree11) == 0 |
10173 && ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW (tree11)) | 10521 && ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW (tree11)) |
10174 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0))))) | 10522 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0))))) |
10175 return build2 (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0), | 10523 { |
10176 code0 == LSHIFT_EXPR ? tree01 : tree11); | 10524 tem = build2 (LROTATE_EXPR, |
10525 TREE_TYPE (TREE_OPERAND (arg0, 0)), | |
10526 TREE_OPERAND (arg0, 0), | |
10527 code0 == LSHIFT_EXPR | |
10528 ? tree01 : tree11); | |
10529 SET_EXPR_LOCATION (tem, loc); | |
10530 return fold_convert_loc (loc, type, tem); | |
10531 } | |
10177 else if (code11 == MINUS_EXPR) | 10532 else if (code11 == MINUS_EXPR) |
10178 { | 10533 { |
10179 tree tree110, tree111; | 10534 tree tree110, tree111; |
10180 tree110 = TREE_OPERAND (tree11, 0); | 10535 tree110 = TREE_OPERAND (tree11, 0); |
10181 tree111 = TREE_OPERAND (tree11, 1); | 10536 tree111 = TREE_OPERAND (tree11, 1); |
10185 && 0 == compare_tree_int (tree110, | 10540 && 0 == compare_tree_int (tree110, |
10186 TYPE_PRECISION | 10541 TYPE_PRECISION |
10187 (TREE_TYPE (TREE_OPERAND | 10542 (TREE_TYPE (TREE_OPERAND |
10188 (arg0, 0)))) | 10543 (arg0, 0)))) |
10189 && operand_equal_p (tree01, tree111, 0)) | 10544 && operand_equal_p (tree01, tree111, 0)) |
10190 return build2 ((code0 == LSHIFT_EXPR | 10545 return |
10191 ? LROTATE_EXPR | 10546 fold_convert_loc (loc, type, |
10192 : RROTATE_EXPR), | 10547 build2 ((code0 == LSHIFT_EXPR |
10193 type, TREE_OPERAND (arg0, 0), tree01); | 10548 ? LROTATE_EXPR |
10549 : RROTATE_EXPR), | |
10550 TREE_TYPE (TREE_OPERAND (arg0, 0)), | |
10551 TREE_OPERAND (arg0, 0), tree01)); | |
10194 } | 10552 } |
10195 else if (code01 == MINUS_EXPR) | 10553 else if (code01 == MINUS_EXPR) |
10196 { | 10554 { |
10197 tree tree010, tree011; | 10555 tree tree010, tree011; |
10198 tree010 = TREE_OPERAND (tree01, 0); | 10556 tree010 = TREE_OPERAND (tree01, 0); |
10203 && 0 == compare_tree_int (tree010, | 10561 && 0 == compare_tree_int (tree010, |
10204 TYPE_PRECISION | 10562 TYPE_PRECISION |
10205 (TREE_TYPE (TREE_OPERAND | 10563 (TREE_TYPE (TREE_OPERAND |
10206 (arg0, 0)))) | 10564 (arg0, 0)))) |
10207 && operand_equal_p (tree11, tree011, 0)) | 10565 && operand_equal_p (tree11, tree011, 0)) |
10208 return build2 ((code0 != LSHIFT_EXPR | 10566 return fold_convert_loc |
10209 ? LROTATE_EXPR | 10567 (loc, type, |
10210 : RROTATE_EXPR), | 10568 build2 ((code0 != LSHIFT_EXPR |
10211 type, TREE_OPERAND (arg0, 0), tree11); | 10569 ? LROTATE_EXPR |
10570 : RROTATE_EXPR), | |
10571 TREE_TYPE (TREE_OPERAND (arg0, 0)), | |
10572 TREE_OPERAND (arg0, 0), tree11)); | |
10212 } | 10573 } |
10213 } | 10574 } |
10214 } | 10575 } |
10215 | 10576 |
10216 associate: | 10577 associate: |
10265 { | 10626 { |
10266 /* Recombine MINUS_EXPR operands by using PLUS_EXPR. */ | 10627 /* Recombine MINUS_EXPR operands by using PLUS_EXPR. */ |
10267 if (code == MINUS_EXPR) | 10628 if (code == MINUS_EXPR) |
10268 code = PLUS_EXPR; | 10629 code = PLUS_EXPR; |
10269 | 10630 |
10270 var0 = associate_trees (var0, var1, code, type); | 10631 var0 = associate_trees (loc, var0, var1, code, type); |
10271 con0 = associate_trees (con0, con1, code, type); | 10632 con0 = associate_trees (loc, con0, con1, code, type); |
10272 lit0 = associate_trees (lit0, lit1, code, type); | 10633 lit0 = associate_trees (loc, lit0, lit1, code, type); |
10273 minus_lit0 = associate_trees (minus_lit0, minus_lit1, code, type); | 10634 minus_lit0 = associate_trees (loc, minus_lit0, minus_lit1, code, type); |
10274 | 10635 |
10275 /* Preserve the MINUS_EXPR if the negative part of the literal is | 10636 /* Preserve the MINUS_EXPR if the negative part of the literal is |
10276 greater than the positive part. Otherwise, the multiplicative | 10637 greater than the positive part. Otherwise, the multiplicative |
10277 folding code (i.e extract_muldiv) may be fooled in case | 10638 folding code (i.e extract_muldiv) may be fooled in case |
10278 unsigned constants are subtracted, like in the following | 10639 unsigned constants are subtracted, like in the following |
10281 { | 10642 { |
10282 if (TREE_CODE (lit0) == INTEGER_CST | 10643 if (TREE_CODE (lit0) == INTEGER_CST |
10283 && TREE_CODE (minus_lit0) == INTEGER_CST | 10644 && TREE_CODE (minus_lit0) == INTEGER_CST |
10284 && tree_int_cst_lt (lit0, minus_lit0)) | 10645 && tree_int_cst_lt (lit0, minus_lit0)) |
10285 { | 10646 { |
10286 minus_lit0 = associate_trees (minus_lit0, lit0, | 10647 minus_lit0 = associate_trees (loc, minus_lit0, lit0, |
10287 MINUS_EXPR, type); | 10648 MINUS_EXPR, type); |
10288 lit0 = 0; | 10649 lit0 = 0; |
10289 } | 10650 } |
10290 else | 10651 else |
10291 { | 10652 { |
10292 lit0 = associate_trees (lit0, minus_lit0, | 10653 lit0 = associate_trees (loc, lit0, minus_lit0, |
10293 MINUS_EXPR, type); | 10654 MINUS_EXPR, type); |
10294 minus_lit0 = 0; | 10655 minus_lit0 = 0; |
10295 } | 10656 } |
10296 } | 10657 } |
10297 if (minus_lit0) | 10658 if (minus_lit0) |
10298 { | 10659 { |
10299 if (con0 == 0) | 10660 if (con0 == 0) |
10300 return fold_convert (type, | 10661 return |
10301 associate_trees (var0, minus_lit0, | 10662 fold_convert_loc (loc, type, |
10302 MINUS_EXPR, type)); | 10663 associate_trees (loc, var0, minus_lit0, |
10664 MINUS_EXPR, type)); | |
10303 else | 10665 else |
10304 { | 10666 { |
10305 con0 = associate_trees (con0, minus_lit0, | 10667 con0 = associate_trees (loc, con0, minus_lit0, |
10306 MINUS_EXPR, type); | 10668 MINUS_EXPR, type); |
10307 return fold_convert (type, | 10669 return |
10308 associate_trees (var0, con0, | 10670 fold_convert_loc (loc, type, |
10309 PLUS_EXPR, type)); | 10671 associate_trees (loc, var0, con0, |
10672 PLUS_EXPR, type)); | |
10310 } | 10673 } |
10311 } | 10674 } |
10312 | 10675 |
10313 con0 = associate_trees (con0, lit0, code, type); | 10676 con0 = associate_trees (loc, con0, lit0, code, type); |
10314 return fold_convert (type, associate_trees (var0, con0, | 10677 return |
10315 code, type)); | 10678 fold_convert_loc (loc, type, associate_trees (loc, var0, con0, |
10679 code, type)); | |
10316 } | 10680 } |
10317 } | 10681 } |
10318 | 10682 |
10319 return NULL_TREE; | 10683 return NULL_TREE; |
10320 | 10684 |
10324 { | 10688 { |
10325 /* (PTR0 p+ A) - (PTR1 p+ B) -> (PTR0 - PTR1) + (A - B) */ | 10689 /* (PTR0 p+ A) - (PTR1 p+ B) -> (PTR0 - PTR1) + (A - B) */ |
10326 if (TREE_CODE (arg0) == POINTER_PLUS_EXPR | 10690 if (TREE_CODE (arg0) == POINTER_PLUS_EXPR |
10327 && TREE_CODE (arg1) == POINTER_PLUS_EXPR) | 10691 && TREE_CODE (arg1) == POINTER_PLUS_EXPR) |
10328 { | 10692 { |
10329 tree arg00 = fold_convert (type, TREE_OPERAND (arg0, 0)); | 10693 tree arg00 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); |
10330 tree arg01 = fold_convert (type, TREE_OPERAND (arg0, 1)); | 10694 tree arg01 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1)); |
10331 tree arg10 = fold_convert (type, TREE_OPERAND (arg1, 0)); | 10695 tree arg10 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0)); |
10332 tree arg11 = fold_convert (type, TREE_OPERAND (arg1, 1)); | 10696 tree arg11 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1)); |
10333 return fold_build2 (PLUS_EXPR, type, | 10697 return fold_build2_loc (loc, PLUS_EXPR, type, |
10334 fold_build2 (MINUS_EXPR, type, arg00, arg10), | 10698 fold_build2_loc (loc, MINUS_EXPR, type, |
10335 fold_build2 (MINUS_EXPR, type, arg01, arg11)); | 10699 arg00, arg10), |
10700 fold_build2_loc (loc, MINUS_EXPR, type, | |
10701 arg01, arg11)); | |
10336 } | 10702 } |
10337 /* (PTR0 p+ A) - PTR1 -> (PTR0 - PTR1) + A, assuming PTR0 - PTR1 simplifies. */ | 10703 /* (PTR0 p+ A) - PTR1 -> (PTR0 - PTR1) + A, assuming PTR0 - PTR1 simplifies. */ |
10338 else if (TREE_CODE (arg0) == POINTER_PLUS_EXPR) | 10704 else if (TREE_CODE (arg0) == POINTER_PLUS_EXPR) |
10339 { | 10705 { |
10340 tree arg00 = fold_convert (type, TREE_OPERAND (arg0, 0)); | 10706 tree arg00 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); |
10341 tree arg01 = fold_convert (type, TREE_OPERAND (arg0, 1)); | 10707 tree arg01 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1)); |
10342 tree tmp = fold_binary (MINUS_EXPR, type, arg00, fold_convert (type, arg1)); | 10708 tree tmp = fold_binary_loc (loc, MINUS_EXPR, type, arg00, |
10709 fold_convert_loc (loc, type, arg1)); | |
10343 if (tmp) | 10710 if (tmp) |
10344 return fold_build2 (PLUS_EXPR, type, tmp, arg01); | 10711 return fold_build2_loc (loc, PLUS_EXPR, type, tmp, arg01); |
10345 } | 10712 } |
10346 } | 10713 } |
10347 /* A - (-B) -> A + B */ | 10714 /* A - (-B) -> A + B */ |
10348 if (TREE_CODE (arg1) == NEGATE_EXPR) | 10715 if (TREE_CODE (arg1) == NEGATE_EXPR) |
10349 return fold_build2 (PLUS_EXPR, type, op0, | 10716 return fold_build2_loc (loc, PLUS_EXPR, type, op0, |
10350 fold_convert (type, TREE_OPERAND (arg1, 0))); | 10717 fold_convert_loc (loc, type, |
10718 TREE_OPERAND (arg1, 0))); | |
10351 /* (-A) - B -> (-B) - A where B is easily negated and we can swap. */ | 10719 /* (-A) - B -> (-B) - A where B is easily negated and we can swap. */ |
10352 if (TREE_CODE (arg0) == NEGATE_EXPR | 10720 if (TREE_CODE (arg0) == NEGATE_EXPR |
10353 && (FLOAT_TYPE_P (type) | 10721 && (FLOAT_TYPE_P (type) |
10354 || INTEGRAL_TYPE_P (type)) | 10722 || INTEGRAL_TYPE_P (type)) |
10355 && negate_expr_p (arg1) | 10723 && negate_expr_p (arg1) |
10356 && reorder_operands_p (arg0, arg1)) | 10724 && reorder_operands_p (arg0, arg1)) |
10357 return fold_build2 (MINUS_EXPR, type, | 10725 return fold_build2_loc (loc, MINUS_EXPR, type, |
10358 fold_convert (type, negate_expr (arg1)), | 10726 fold_convert_loc (loc, type, |
10359 fold_convert (type, TREE_OPERAND (arg0, 0))); | 10727 negate_expr (arg1)), |
10728 fold_convert_loc (loc, type, | |
10729 TREE_OPERAND (arg0, 0))); | |
10360 /* Convert -A - 1 to ~A. */ | 10730 /* Convert -A - 1 to ~A. */ |
10361 if (INTEGRAL_TYPE_P (type) | 10731 if (INTEGRAL_TYPE_P (type) |
10362 && TREE_CODE (arg0) == NEGATE_EXPR | 10732 && TREE_CODE (arg0) == NEGATE_EXPR |
10363 && integer_onep (arg1) | 10733 && integer_onep (arg1) |
10364 && !TYPE_OVERFLOW_TRAPS (type)) | 10734 && !TYPE_OVERFLOW_TRAPS (type)) |
10365 return fold_build1 (BIT_NOT_EXPR, type, | 10735 return fold_build1_loc (loc, BIT_NOT_EXPR, type, |
10366 fold_convert (type, TREE_OPERAND (arg0, 0))); | 10736 fold_convert_loc (loc, type, |
10737 TREE_OPERAND (arg0, 0))); | |
10367 | 10738 |
10368 /* Convert -1 - A to ~A. */ | 10739 /* Convert -1 - A to ~A. */ |
10369 if (INTEGRAL_TYPE_P (type) | 10740 if (INTEGRAL_TYPE_P (type) |
10370 && integer_all_onesp (arg0)) | 10741 && integer_all_onesp (arg0)) |
10371 return fold_build1 (BIT_NOT_EXPR, type, op1); | 10742 return fold_build1_loc (loc, BIT_NOT_EXPR, type, op1); |
10372 | 10743 |
10373 | 10744 |
10374 /* X - (X / CST) * CST is X % CST. */ | 10745 /* X - (X / CST) * CST is X % CST. */ |
10375 if (INTEGRAL_TYPE_P (type) | 10746 if (INTEGRAL_TYPE_P (type) |
10376 && TREE_CODE (arg1) == MULT_EXPR | 10747 && TREE_CODE (arg1) == MULT_EXPR |
10377 && TREE_CODE (TREE_OPERAND (arg1, 0)) == TRUNC_DIV_EXPR | 10748 && TREE_CODE (TREE_OPERAND (arg1, 0)) == TRUNC_DIV_EXPR |
10378 && operand_equal_p (arg0, | 10749 && operand_equal_p (arg0, |
10379 TREE_OPERAND (TREE_OPERAND (arg1, 0), 0), 0) | 10750 TREE_OPERAND (TREE_OPERAND (arg1, 0), 0), 0) |
10380 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg1, 0), 1), | 10751 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg1, 0), 1), |
10381 TREE_OPERAND (arg1, 1), 0)) | 10752 TREE_OPERAND (arg1, 1), 0)) |
10382 return fold_convert (type, | 10753 return |
10383 fold_build2 (TRUNC_MOD_EXPR, TREE_TYPE (arg0), | 10754 fold_convert_loc (loc, type, |
10384 arg0, TREE_OPERAND (arg1, 1))); | 10755 fold_build2_loc (loc, TRUNC_MOD_EXPR, TREE_TYPE (arg0), |
10756 arg0, TREE_OPERAND (arg1, 1))); | |
10385 | 10757 |
10386 if (! FLOAT_TYPE_P (type)) | 10758 if (! FLOAT_TYPE_P (type)) |
10387 { | 10759 { |
10388 if (integer_zerop (arg0)) | 10760 if (integer_zerop (arg0)) |
10389 return negate_expr (fold_convert (type, arg1)); | 10761 return negate_expr (fold_convert_loc (loc, type, arg1)); |
10390 if (integer_zerop (arg1)) | 10762 if (integer_zerop (arg1)) |
10391 return non_lvalue (fold_convert (type, arg0)); | 10763 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
10392 | 10764 |
10393 /* Fold A - (A & B) into ~B & A. */ | 10765 /* Fold A - (A & B) into ~B & A. */ |
10394 if (!TREE_SIDE_EFFECTS (arg0) | 10766 if (!TREE_SIDE_EFFECTS (arg0) |
10395 && TREE_CODE (arg1) == BIT_AND_EXPR) | 10767 && TREE_CODE (arg1) == BIT_AND_EXPR) |
10396 { | 10768 { |
10397 if (operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)) | 10769 if (operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)) |
10398 { | 10770 { |
10399 tree arg10 = fold_convert (type, TREE_OPERAND (arg1, 0)); | 10771 tree arg10 = fold_convert_loc (loc, type, |
10400 return fold_build2 (BIT_AND_EXPR, type, | 10772 TREE_OPERAND (arg1, 0)); |
10401 fold_build1 (BIT_NOT_EXPR, type, arg10), | 10773 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
10402 fold_convert (type, arg0)); | 10774 fold_build1_loc (loc, BIT_NOT_EXPR, |
10775 type, arg10), | |
10776 fold_convert_loc (loc, type, arg0)); | |
10403 } | 10777 } |
10404 if (operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 10778 if (operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
10405 { | 10779 { |
10406 tree arg11 = fold_convert (type, TREE_OPERAND (arg1, 1)); | 10780 tree arg11 = fold_convert_loc (loc, |
10407 return fold_build2 (BIT_AND_EXPR, type, | 10781 type, TREE_OPERAND (arg1, 1)); |
10408 fold_build1 (BIT_NOT_EXPR, type, arg11), | 10782 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
10409 fold_convert (type, arg0)); | 10783 fold_build1_loc (loc, BIT_NOT_EXPR, |
10784 type, arg11), | |
10785 fold_convert_loc (loc, type, arg0)); | |
10410 } | 10786 } |
10411 } | 10787 } |
10412 | 10788 |
10413 /* Fold (A & ~B) - (A & B) into (A ^ B) - B, where B is | 10789 /* Fold (A & ~B) - (A & B) into (A ^ B) - B, where B is |
10414 any power of 2 minus 1. */ | 10790 any power of 2 minus 1. */ |
10417 && operand_equal_p (TREE_OPERAND (arg0, 0), | 10793 && operand_equal_p (TREE_OPERAND (arg0, 0), |
10418 TREE_OPERAND (arg1, 0), 0)) | 10794 TREE_OPERAND (arg1, 0), 0)) |
10419 { | 10795 { |
10420 tree mask0 = TREE_OPERAND (arg0, 1); | 10796 tree mask0 = TREE_OPERAND (arg0, 1); |
10421 tree mask1 = TREE_OPERAND (arg1, 1); | 10797 tree mask1 = TREE_OPERAND (arg1, 1); |
10422 tree tem = fold_build1 (BIT_NOT_EXPR, type, mask0); | 10798 tree tem = fold_build1_loc (loc, BIT_NOT_EXPR, type, mask0); |
10423 | 10799 |
10424 if (operand_equal_p (tem, mask1, 0)) | 10800 if (operand_equal_p (tem, mask1, 0)) |
10425 { | 10801 { |
10426 tem = fold_build2 (BIT_XOR_EXPR, type, | 10802 tem = fold_build2_loc (loc, BIT_XOR_EXPR, type, |
10427 TREE_OPERAND (arg0, 0), mask1); | 10803 TREE_OPERAND (arg0, 0), mask1); |
10428 return fold_build2 (MINUS_EXPR, type, tem, mask1); | 10804 return fold_build2_loc (loc, MINUS_EXPR, type, tem, mask1); |
10429 } | 10805 } |
10430 } | 10806 } |
10431 } | 10807 } |
10432 | 10808 |
10433 /* See if ARG1 is zero and X - ARG1 reduces to X. */ | 10809 /* See if ARG1 is zero and X - ARG1 reduces to X. */ |
10434 else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 1)) | 10810 else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 1)) |
10435 return non_lvalue (fold_convert (type, arg0)); | 10811 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
10436 | 10812 |
10437 /* (ARG0 - ARG1) is the same as (-ARG1 + ARG0). So check whether | 10813 /* (ARG0 - ARG1) is the same as (-ARG1 + ARG0). So check whether |
10438 ARG0 is zero and X + ARG0 reduces to X, since that would mean | 10814 ARG0 is zero and X + ARG0 reduces to X, since that would mean |
10439 (-ARG1 + ARG0) reduces to -ARG1. */ | 10815 (-ARG1 + ARG0) reduces to -ARG1. */ |
10440 else if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0)) | 10816 else if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0)) |
10441 return negate_expr (fold_convert (type, arg1)); | 10817 return negate_expr (fold_convert_loc (loc, type, arg1)); |
10442 | 10818 |
10443 /* Fold __complex__ ( x, 0 ) - __complex__ ( 0, y ) to | 10819 /* Fold __complex__ ( x, 0 ) - __complex__ ( 0, y ) to |
10444 __complex__ ( x, -y ). This is not the same for SNaNs or if | 10820 __complex__ ( x, -y ). This is not the same for SNaNs or if |
10445 signed zeros are involved. */ | 10821 signed zeros are involved. */ |
10446 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) | 10822 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) |
10447 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))) | 10823 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))) |
10448 && COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))) | 10824 && COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))) |
10449 { | 10825 { |
10450 tree rtype = TREE_TYPE (TREE_TYPE (arg0)); | 10826 tree rtype = TREE_TYPE (TREE_TYPE (arg0)); |
10451 tree arg0r = fold_unary (REALPART_EXPR, rtype, arg0); | 10827 tree arg0r = fold_unary_loc (loc, REALPART_EXPR, rtype, arg0); |
10452 tree arg0i = fold_unary (IMAGPART_EXPR, rtype, arg0); | 10828 tree arg0i = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg0); |
10453 bool arg0rz = false, arg0iz = false; | 10829 bool arg0rz = false, arg0iz = false; |
10454 if ((arg0r && (arg0rz = real_zerop (arg0r))) | 10830 if ((arg0r && (arg0rz = real_zerop (arg0r))) |
10455 || (arg0i && (arg0iz = real_zerop (arg0i)))) | 10831 || (arg0i && (arg0iz = real_zerop (arg0i)))) |
10456 { | 10832 { |
10457 tree arg1r = fold_unary (REALPART_EXPR, rtype, arg1); | 10833 tree arg1r = fold_unary_loc (loc, REALPART_EXPR, rtype, arg1); |
10458 tree arg1i = fold_unary (IMAGPART_EXPR, rtype, arg1); | 10834 tree arg1i = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg1); |
10459 if (arg0rz && arg1i && real_zerop (arg1i)) | 10835 if (arg0rz && arg1i && real_zerop (arg1i)) |
10460 { | 10836 { |
10461 tree rp = fold_build1 (NEGATE_EXPR, rtype, | 10837 tree rp = fold_build1_loc (loc, NEGATE_EXPR, rtype, |
10462 arg1r ? arg1r | 10838 arg1r ? arg1r |
10463 : build1 (REALPART_EXPR, rtype, arg1)); | 10839 : build1 (REALPART_EXPR, rtype, arg1)); |
10464 tree ip = arg0i ? arg0i | 10840 tree ip = arg0i ? arg0i |
10465 : build1 (IMAGPART_EXPR, rtype, arg0); | 10841 : build1 (IMAGPART_EXPR, rtype, arg0); |
10466 return fold_build2 (COMPLEX_EXPR, type, rp, ip); | 10842 return fold_build2_loc (loc, COMPLEX_EXPR, type, rp, ip); |
10467 } | 10843 } |
10468 else if (arg0iz && arg1r && real_zerop (arg1r)) | 10844 else if (arg0iz && arg1r && real_zerop (arg1r)) |
10469 { | 10845 { |
10470 tree rp = arg0r ? arg0r | 10846 tree rp = arg0r ? arg0r |
10471 : build1 (REALPART_EXPR, rtype, arg0); | 10847 : build1 (REALPART_EXPR, rtype, arg0); |
10472 tree ip = fold_build1 (NEGATE_EXPR, rtype, | 10848 tree ip = fold_build1_loc (loc, NEGATE_EXPR, rtype, |
10473 arg1i ? arg1i | 10849 arg1i ? arg1i |
10474 : build1 (IMAGPART_EXPR, rtype, arg1)); | 10850 : build1 (IMAGPART_EXPR, rtype, arg1)); |
10475 return fold_build2 (COMPLEX_EXPR, type, rp, ip); | 10851 return fold_build2_loc (loc, COMPLEX_EXPR, type, rp, ip); |
10476 } | 10852 } |
10477 } | 10853 } |
10478 } | 10854 } |
10479 | 10855 |
10480 /* Fold &x - &x. This can happen from &x.foo - &x. | 10856 /* Fold &x - &x. This can happen from &x.foo - &x. |
10483 Also note that operand_equal_p is always false if an operand | 10859 Also note that operand_equal_p is always false if an operand |
10484 is volatile. */ | 10860 is volatile. */ |
10485 | 10861 |
10486 if ((!FLOAT_TYPE_P (type) || !HONOR_NANS (TYPE_MODE (type))) | 10862 if ((!FLOAT_TYPE_P (type) || !HONOR_NANS (TYPE_MODE (type))) |
10487 && operand_equal_p (arg0, arg1, 0)) | 10863 && operand_equal_p (arg0, arg1, 0)) |
10488 return fold_convert (type, integer_zero_node); | 10864 return fold_convert_loc (loc, type, integer_zero_node); |
10489 | 10865 |
10490 /* A - B -> A + (-B) if B is easily negatable. */ | 10866 /* A - B -> A + (-B) if B is easily negatable. */ |
10491 if (negate_expr_p (arg1) | 10867 if (negate_expr_p (arg1) |
10492 && ((FLOAT_TYPE_P (type) | 10868 && ((FLOAT_TYPE_P (type) |
10493 /* Avoid this transformation if B is a positive REAL_CST. */ | 10869 /* Avoid this transformation if B is a positive REAL_CST. */ |
10494 && (TREE_CODE (arg1) != REAL_CST | 10870 && (TREE_CODE (arg1) != REAL_CST |
10495 || REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1)))) | 10871 || REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1)))) |
10496 || INTEGRAL_TYPE_P (type))) | 10872 || INTEGRAL_TYPE_P (type))) |
10497 return fold_build2 (PLUS_EXPR, type, | 10873 return fold_build2_loc (loc, PLUS_EXPR, type, |
10498 fold_convert (type, arg0), | 10874 fold_convert_loc (loc, type, arg0), |
10499 fold_convert (type, negate_expr (arg1))); | 10875 fold_convert_loc (loc, type, |
10876 negate_expr (arg1))); | |
10500 | 10877 |
10501 /* Try folding difference of addresses. */ | 10878 /* Try folding difference of addresses. */ |
10502 { | 10879 { |
10503 HOST_WIDE_INT diff; | 10880 HOST_WIDE_INT diff; |
10504 | 10881 |
10517 tree aref0 = TREE_OPERAND (arg0, 0); | 10894 tree aref0 = TREE_OPERAND (arg0, 0); |
10518 tree aref1 = TREE_OPERAND (arg1, 0); | 10895 tree aref1 = TREE_OPERAND (arg1, 0); |
10519 if (operand_equal_p (TREE_OPERAND (aref0, 0), | 10896 if (operand_equal_p (TREE_OPERAND (aref0, 0), |
10520 TREE_OPERAND (aref1, 0), 0)) | 10897 TREE_OPERAND (aref1, 0), 0)) |
10521 { | 10898 { |
10522 tree op0 = fold_convert (type, TREE_OPERAND (aref0, 1)); | 10899 tree op0 = fold_convert_loc (loc, type, TREE_OPERAND (aref0, 1)); |
10523 tree op1 = fold_convert (type, TREE_OPERAND (aref1, 1)); | 10900 tree op1 = fold_convert_loc (loc, type, TREE_OPERAND (aref1, 1)); |
10524 tree esz = array_ref_element_size (aref0); | 10901 tree esz = array_ref_element_size (aref0); |
10525 tree diff = build2 (MINUS_EXPR, type, op0, op1); | 10902 tree diff = build2 (MINUS_EXPR, type, op0, op1); |
10526 return fold_build2 (MULT_EXPR, type, diff, | 10903 return fold_build2_loc (loc, MULT_EXPR, type, diff, |
10527 fold_convert (type, esz)); | 10904 fold_convert_loc (loc, type, esz)); |
10528 | 10905 |
10529 } | 10906 } |
10530 } | 10907 } |
10531 | 10908 |
10532 if (flag_unsafe_math_optimizations | 10909 if (FLOAT_TYPE_P (type) |
10910 && flag_unsafe_math_optimizations | |
10533 && (TREE_CODE (arg0) == RDIV_EXPR || TREE_CODE (arg0) == MULT_EXPR) | 10911 && (TREE_CODE (arg0) == RDIV_EXPR || TREE_CODE (arg0) == MULT_EXPR) |
10534 && (TREE_CODE (arg1) == RDIV_EXPR || TREE_CODE (arg1) == MULT_EXPR) | 10912 && (TREE_CODE (arg1) == RDIV_EXPR || TREE_CODE (arg1) == MULT_EXPR) |
10535 && (tem = distribute_real_division (code, type, arg0, arg1))) | 10913 && (tem = distribute_real_division (loc, code, type, arg0, arg1))) |
10536 return tem; | 10914 return tem; |
10537 | 10915 |
10538 /* Handle (A1 * C1) - (A2 * C2) with A1, A2 or C1, C2 being the | 10916 /* Handle (A1 * C1) - (A2 * C2) with A1, A2 or C1, C2 being the |
10539 same or one. Make sure type is not saturating. | 10917 same or one. Make sure type is not saturating. |
10540 fold_plusminus_mult_expr will re-associate. */ | 10918 fold_plusminus_mult_expr will re-associate. */ |
10541 if ((TREE_CODE (arg0) == MULT_EXPR | 10919 if ((TREE_CODE (arg0) == MULT_EXPR |
10542 || TREE_CODE (arg1) == MULT_EXPR) | 10920 || TREE_CODE (arg1) == MULT_EXPR) |
10543 && !TYPE_SATURATING (type) | 10921 && !TYPE_SATURATING (type) |
10544 && (!FLOAT_TYPE_P (type) || flag_associative_math)) | 10922 && (!FLOAT_TYPE_P (type) || flag_associative_math)) |
10545 { | 10923 { |
10546 tree tem = fold_plusminus_mult_expr (code, type, arg0, arg1); | 10924 tree tem = fold_plusminus_mult_expr (loc, code, type, arg0, arg1); |
10547 if (tem) | 10925 if (tem) |
10548 return tem; | 10926 return tem; |
10549 } | 10927 } |
10550 | 10928 |
10551 goto associate; | 10929 goto associate; |
10552 | 10930 |
10553 case MULT_EXPR: | 10931 case MULT_EXPR: |
10554 /* (-A) * (-B) -> A * B */ | 10932 /* (-A) * (-B) -> A * B */ |
10555 if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1)) | 10933 if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1)) |
10556 return fold_build2 (MULT_EXPR, type, | 10934 return fold_build2_loc (loc, MULT_EXPR, type, |
10557 fold_convert (type, TREE_OPERAND (arg0, 0)), | 10935 fold_convert_loc (loc, type, |
10558 fold_convert (type, negate_expr (arg1))); | 10936 TREE_OPERAND (arg0, 0)), |
10937 fold_convert_loc (loc, type, | |
10938 negate_expr (arg1))); | |
10559 if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0)) | 10939 if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0)) |
10560 return fold_build2 (MULT_EXPR, type, | 10940 return fold_build2_loc (loc, MULT_EXPR, type, |
10561 fold_convert (type, negate_expr (arg0)), | 10941 fold_convert_loc (loc, type, |
10562 fold_convert (type, TREE_OPERAND (arg1, 0))); | 10942 negate_expr (arg0)), |
10943 fold_convert_loc (loc, type, | |
10944 TREE_OPERAND (arg1, 0))); | |
10563 | 10945 |
10564 if (! FLOAT_TYPE_P (type)) | 10946 if (! FLOAT_TYPE_P (type)) |
10565 { | 10947 { |
10566 if (integer_zerop (arg1)) | 10948 if (integer_zerop (arg1)) |
10567 return omit_one_operand (type, arg1, arg0); | 10949 return omit_one_operand_loc (loc, type, arg1, arg0); |
10568 if (integer_onep (arg1)) | 10950 if (integer_onep (arg1)) |
10569 return non_lvalue (fold_convert (type, arg0)); | 10951 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
10570 /* Transform x * -1 into -x. Make sure to do the negation | 10952 /* Transform x * -1 into -x. Make sure to do the negation |
10571 on the original operand with conversions not stripped | 10953 on the original operand with conversions not stripped |
10572 because we can only strip non-sign-changing conversions. */ | 10954 because we can only strip non-sign-changing conversions. */ |
10573 if (integer_all_onesp (arg1)) | 10955 if (integer_all_onesp (arg1)) |
10574 return fold_convert (type, negate_expr (op0)); | 10956 return fold_convert_loc (loc, type, negate_expr (op0)); |
10575 /* Transform x * -C into -x * C if x is easily negatable. */ | 10957 /* Transform x * -C into -x * C if x is easily negatable. */ |
10576 if (TREE_CODE (arg1) == INTEGER_CST | 10958 if (TREE_CODE (arg1) == INTEGER_CST |
10577 && tree_int_cst_sgn (arg1) == -1 | 10959 && tree_int_cst_sgn (arg1) == -1 |
10578 && negate_expr_p (arg0) | 10960 && negate_expr_p (arg0) |
10579 && (tem = negate_expr (arg1)) != arg1 | 10961 && (tem = negate_expr (arg1)) != arg1 |
10580 && !TREE_OVERFLOW (tem)) | 10962 && !TREE_OVERFLOW (tem)) |
10581 return fold_build2 (MULT_EXPR, type, | 10963 return fold_build2_loc (loc, MULT_EXPR, type, |
10582 fold_convert (type, negate_expr (arg0)), tem); | 10964 fold_convert_loc (loc, type, |
10965 negate_expr (arg0)), | |
10966 tem); | |
10583 | 10967 |
10584 /* (a * (1 << b)) is (a << b) */ | 10968 /* (a * (1 << b)) is (a << b) */ |
10585 if (TREE_CODE (arg1) == LSHIFT_EXPR | 10969 if (TREE_CODE (arg1) == LSHIFT_EXPR |
10586 && integer_onep (TREE_OPERAND (arg1, 0))) | 10970 && integer_onep (TREE_OPERAND (arg1, 0))) |
10587 return fold_build2 (LSHIFT_EXPR, type, op0, | 10971 return fold_build2_loc (loc, LSHIFT_EXPR, type, op0, |
10588 TREE_OPERAND (arg1, 1)); | 10972 TREE_OPERAND (arg1, 1)); |
10589 if (TREE_CODE (arg0) == LSHIFT_EXPR | 10973 if (TREE_CODE (arg0) == LSHIFT_EXPR |
10590 && integer_onep (TREE_OPERAND (arg0, 0))) | 10974 && integer_onep (TREE_OPERAND (arg0, 0))) |
10591 return fold_build2 (LSHIFT_EXPR, type, op1, | 10975 return fold_build2_loc (loc, LSHIFT_EXPR, type, op1, |
10592 TREE_OPERAND (arg0, 1)); | 10976 TREE_OPERAND (arg0, 1)); |
10593 | 10977 |
10594 /* (A + A) * C -> A * 2 * C */ | 10978 /* (A + A) * C -> A * 2 * C */ |
10595 if (TREE_CODE (arg0) == PLUS_EXPR | 10979 if (TREE_CODE (arg0) == PLUS_EXPR |
10596 && TREE_CODE (arg1) == INTEGER_CST | 10980 && TREE_CODE (arg1) == INTEGER_CST |
10597 && operand_equal_p (TREE_OPERAND (arg0, 0), | 10981 && operand_equal_p (TREE_OPERAND (arg0, 0), |
10598 TREE_OPERAND (arg0, 1), 0)) | 10982 TREE_OPERAND (arg0, 1), 0)) |
10599 return fold_build2 (MULT_EXPR, type, | 10983 return fold_build2_loc (loc, MULT_EXPR, type, |
10600 omit_one_operand (type, TREE_OPERAND (arg0, 0), | 10984 omit_one_operand_loc (loc, type, |
10985 TREE_OPERAND (arg0, 0), | |
10601 TREE_OPERAND (arg0, 1)), | 10986 TREE_OPERAND (arg0, 1)), |
10602 fold_build2 (MULT_EXPR, type, | 10987 fold_build2_loc (loc, MULT_EXPR, type, |
10603 build_int_cst (type, 2) , arg1)); | 10988 build_int_cst (type, 2) , arg1)); |
10604 | 10989 |
10605 strict_overflow_p = false; | 10990 strict_overflow_p = false; |
10606 if (TREE_CODE (arg1) == INTEGER_CST | 10991 if (TREE_CODE (arg1) == INTEGER_CST |
10607 && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, | 10992 && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, |
10610 if (strict_overflow_p) | 10995 if (strict_overflow_p) |
10611 fold_overflow_warning (("assuming signed overflow does not " | 10996 fold_overflow_warning (("assuming signed overflow does not " |
10612 "occur when simplifying " | 10997 "occur when simplifying " |
10613 "multiplication"), | 10998 "multiplication"), |
10614 WARN_STRICT_OVERFLOW_MISC); | 10999 WARN_STRICT_OVERFLOW_MISC); |
10615 return fold_convert (type, tem); | 11000 return fold_convert_loc (loc, type, tem); |
10616 } | 11001 } |
10617 | 11002 |
10618 /* Optimize z * conj(z) for integer complex numbers. */ | 11003 /* Optimize z * conj(z) for integer complex numbers. */ |
10619 if (TREE_CODE (arg0) == CONJ_EXPR | 11004 if (TREE_CODE (arg0) == CONJ_EXPR |
10620 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 11005 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
10621 return fold_mult_zconjz (type, arg1); | 11006 return fold_mult_zconjz (loc, type, arg1); |
10622 if (TREE_CODE (arg1) == CONJ_EXPR | 11007 if (TREE_CODE (arg1) == CONJ_EXPR |
10623 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 11008 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
10624 return fold_mult_zconjz (type, arg0); | 11009 return fold_mult_zconjz (loc, type, arg0); |
10625 } | 11010 } |
10626 else | 11011 else |
10627 { | 11012 { |
10628 /* Maybe fold x * 0 to 0. The expressions aren't the same | 11013 /* Maybe fold x * 0 to 0. The expressions aren't the same |
10629 when x is NaN, since x * 0 is also NaN. Nor are they the | 11014 when x is NaN, since x * 0 is also NaN. Nor are they the |
10630 same in modes with signed zeros, since multiplying a | 11015 same in modes with signed zeros, since multiplying a |
10631 negative value by 0 gives -0, not +0. */ | 11016 negative value by 0 gives -0, not +0. */ |
10632 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))) | 11017 if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))) |
10633 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))) | 11018 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))) |
10634 && real_zerop (arg1)) | 11019 && real_zerop (arg1)) |
10635 return omit_one_operand (type, arg1, arg0); | 11020 return omit_one_operand_loc (loc, type, arg1, arg0); |
10636 /* In IEEE floating point, x*1 is not equivalent to x for snans. */ | 11021 /* In IEEE floating point, x*1 is not equivalent to x for snans. |
11022 Likewise for complex arithmetic with signed zeros. */ | |
10637 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) | 11023 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) |
11024 && (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))) | |
11025 || !COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))) | |
10638 && real_onep (arg1)) | 11026 && real_onep (arg1)) |
10639 return non_lvalue (fold_convert (type, arg0)); | 11027 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
10640 | 11028 |
10641 /* Transform x * -1.0 into -x. */ | 11029 /* Transform x * -1.0 into -x. */ |
10642 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) | 11030 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) |
11031 && (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))) | |
11032 || !COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))) | |
10643 && real_minus_onep (arg1)) | 11033 && real_minus_onep (arg1)) |
10644 return fold_convert (type, negate_expr (arg0)); | 11034 return fold_convert_loc (loc, type, negate_expr (arg0)); |
10645 | 11035 |
10646 /* Convert (C1/X)*C2 into (C1*C2)/X. This transformation may change | 11036 /* Convert (C1/X)*C2 into (C1*C2)/X. This transformation may change |
10647 the result for floating point types due to rounding so it is applied | 11037 the result for floating point types due to rounding so it is applied |
10648 only if -fassociative-math was specify. */ | 11038 only if -fassociative-math was specify. */ |
10649 if (flag_associative_math | 11039 if (flag_associative_math |
10652 && TREE_CODE (TREE_OPERAND (arg0, 0)) == REAL_CST) | 11042 && TREE_CODE (TREE_OPERAND (arg0, 0)) == REAL_CST) |
10653 { | 11043 { |
10654 tree tem = const_binop (MULT_EXPR, TREE_OPERAND (arg0, 0), | 11044 tree tem = const_binop (MULT_EXPR, TREE_OPERAND (arg0, 0), |
10655 arg1, 0); | 11045 arg1, 0); |
10656 if (tem) | 11046 if (tem) |
10657 return fold_build2 (RDIV_EXPR, type, tem, | 11047 return fold_build2_loc (loc, RDIV_EXPR, type, tem, |
10658 TREE_OPERAND (arg0, 1)); | 11048 TREE_OPERAND (arg0, 1)); |
10659 } | 11049 } |
10660 | 11050 |
10661 /* Strip sign operations from X in X*X, i.e. -Y*-Y -> Y*Y. */ | 11051 /* Strip sign operations from X in X*X, i.e. -Y*-Y -> Y*Y. */ |
10662 if (operand_equal_p (arg0, arg1, 0)) | 11052 if (operand_equal_p (arg0, arg1, 0)) |
10663 { | 11053 { |
10664 tree tem = fold_strip_sign_ops (arg0); | 11054 tree tem = fold_strip_sign_ops (arg0); |
10665 if (tem != NULL_TREE) | 11055 if (tem != NULL_TREE) |
10666 { | 11056 { |
10667 tem = fold_convert (type, tem); | 11057 tem = fold_convert_loc (loc, type, tem); |
10668 return fold_build2 (MULT_EXPR, type, tem, tem); | 11058 return fold_build2_loc (loc, MULT_EXPR, type, tem, tem); |
10669 } | 11059 } |
10670 } | 11060 } |
10671 | 11061 |
10672 /* Fold z * +-I to __complex__ (-+__imag z, +-__real z). | 11062 /* Fold z * +-I to __complex__ (-+__imag z, +-__real z). |
10673 This is not the same for NaNs or if signed zeros are | 11063 This is not the same for NaNs or if signed zeros are |
10678 && TREE_CODE (arg1) == COMPLEX_CST | 11068 && TREE_CODE (arg1) == COMPLEX_CST |
10679 && real_zerop (TREE_REALPART (arg1))) | 11069 && real_zerop (TREE_REALPART (arg1))) |
10680 { | 11070 { |
10681 tree rtype = TREE_TYPE (TREE_TYPE (arg0)); | 11071 tree rtype = TREE_TYPE (TREE_TYPE (arg0)); |
10682 if (real_onep (TREE_IMAGPART (arg1))) | 11072 if (real_onep (TREE_IMAGPART (arg1))) |
10683 return fold_build2 (COMPLEX_EXPR, type, | 11073 return |
10684 negate_expr (fold_build1 (IMAGPART_EXPR, | 11074 fold_build2_loc (loc, COMPLEX_EXPR, type, |
10685 rtype, arg0)), | 11075 negate_expr (fold_build1_loc (loc, IMAGPART_EXPR, |
10686 fold_build1 (REALPART_EXPR, rtype, arg0)); | 11076 rtype, arg0)), |
11077 fold_build1_loc (loc, REALPART_EXPR, rtype, arg0)); | |
10687 else if (real_minus_onep (TREE_IMAGPART (arg1))) | 11078 else if (real_minus_onep (TREE_IMAGPART (arg1))) |
10688 return fold_build2 (COMPLEX_EXPR, type, | 11079 return |
10689 fold_build1 (IMAGPART_EXPR, rtype, arg0), | 11080 fold_build2_loc (loc, COMPLEX_EXPR, type, |
10690 negate_expr (fold_build1 (REALPART_EXPR, | 11081 fold_build1_loc (loc, IMAGPART_EXPR, rtype, arg0), |
10691 rtype, arg0))); | 11082 negate_expr (fold_build1_loc (loc, REALPART_EXPR, |
11083 rtype, arg0))); | |
10692 } | 11084 } |
10693 | 11085 |
10694 /* Optimize z * conj(z) for floating point complex numbers. | 11086 /* Optimize z * conj(z) for floating point complex numbers. |
10695 Guarded by flag_unsafe_math_optimizations as non-finite | 11087 Guarded by flag_unsafe_math_optimizations as non-finite |
10696 imaginary components don't produce scalar results. */ | 11088 imaginary components don't produce scalar results. */ |
10697 if (flag_unsafe_math_optimizations | 11089 if (flag_unsafe_math_optimizations |
10698 && TREE_CODE (arg0) == CONJ_EXPR | 11090 && TREE_CODE (arg0) == CONJ_EXPR |
10699 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 11091 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
10700 return fold_mult_zconjz (type, arg1); | 11092 return fold_mult_zconjz (loc, type, arg1); |
10701 if (flag_unsafe_math_optimizations | 11093 if (flag_unsafe_math_optimizations |
10702 && TREE_CODE (arg1) == CONJ_EXPR | 11094 && TREE_CODE (arg1) == CONJ_EXPR |
10703 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 11095 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
10704 return fold_mult_zconjz (type, arg0); | 11096 return fold_mult_zconjz (loc, type, arg0); |
10705 | 11097 |
10706 if (flag_unsafe_math_optimizations) | 11098 if (flag_unsafe_math_optimizations) |
10707 { | 11099 { |
10708 enum built_in_function fcode0 = builtin_mathfn_code (arg0); | 11100 enum built_in_function fcode0 = builtin_mathfn_code (arg0); |
10709 enum built_in_function fcode1 = builtin_mathfn_code (arg1); | 11101 enum built_in_function fcode1 = builtin_mathfn_code (arg1); |
10721 && ! HONOR_SNANS (TYPE_MODE (type))) | 11113 && ! HONOR_SNANS (TYPE_MODE (type))) |
10722 return arg00; | 11114 return arg00; |
10723 | 11115 |
10724 /* Optimize root(x)*root(y) as root(x*y). */ | 11116 /* Optimize root(x)*root(y) as root(x*y). */ |
10725 rootfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); | 11117 rootfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); |
10726 arg = fold_build2 (MULT_EXPR, type, arg00, arg10); | 11118 arg = fold_build2_loc (loc, MULT_EXPR, type, arg00, arg10); |
10727 return build_call_expr (rootfn, 1, arg); | 11119 return build_call_expr_loc (loc, rootfn, 1, arg); |
10728 } | 11120 } |
10729 | 11121 |
10730 /* Optimize expN(x)*expN(y) as expN(x+y). */ | 11122 /* Optimize expN(x)*expN(y) as expN(x+y). */ |
10731 if (fcode0 == fcode1 && BUILTIN_EXPONENT_P (fcode0)) | 11123 if (fcode0 == fcode1 && BUILTIN_EXPONENT_P (fcode0)) |
10732 { | 11124 { |
10733 tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); | 11125 tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); |
10734 tree arg = fold_build2 (PLUS_EXPR, type, | 11126 tree arg = fold_build2_loc (loc, PLUS_EXPR, type, |
10735 CALL_EXPR_ARG (arg0, 0), | 11127 CALL_EXPR_ARG (arg0, 0), |
10736 CALL_EXPR_ARG (arg1, 0)); | 11128 CALL_EXPR_ARG (arg1, 0)); |
10737 return build_call_expr (expfn, 1, arg); | 11129 return build_call_expr_loc (loc, expfn, 1, arg); |
10738 } | 11130 } |
10739 | 11131 |
10740 /* Optimizations of pow(...)*pow(...). */ | 11132 /* Optimizations of pow(...)*pow(...). */ |
10741 if ((fcode0 == BUILT_IN_POW && fcode1 == BUILT_IN_POW) | 11133 if ((fcode0 == BUILT_IN_POW && fcode1 == BUILT_IN_POW) |
10742 || (fcode0 == BUILT_IN_POWF && fcode1 == BUILT_IN_POWF) | 11134 || (fcode0 == BUILT_IN_POWF && fcode1 == BUILT_IN_POWF) |
10749 | 11141 |
10750 /* Optimize pow(x,y)*pow(z,y) as pow(x*z,y). */ | 11142 /* Optimize pow(x,y)*pow(z,y) as pow(x*z,y). */ |
10751 if (operand_equal_p (arg01, arg11, 0)) | 11143 if (operand_equal_p (arg01, arg11, 0)) |
10752 { | 11144 { |
10753 tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); | 11145 tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); |
10754 tree arg = fold_build2 (MULT_EXPR, type, arg00, arg10); | 11146 tree arg = fold_build2_loc (loc, MULT_EXPR, type, |
10755 return build_call_expr (powfn, 2, arg, arg01); | 11147 arg00, arg10); |
11148 return build_call_expr_loc (loc, powfn, 2, arg, arg01); | |
10756 } | 11149 } |
10757 | 11150 |
10758 /* Optimize pow(x,y)*pow(x,z) as pow(x,y+z). */ | 11151 /* Optimize pow(x,y)*pow(x,z) as pow(x,y+z). */ |
10759 if (operand_equal_p (arg00, arg10, 0)) | 11152 if (operand_equal_p (arg00, arg10, 0)) |
10760 { | 11153 { |
10761 tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); | 11154 tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); |
10762 tree arg = fold_build2 (PLUS_EXPR, type, arg01, arg11); | 11155 tree arg = fold_build2_loc (loc, PLUS_EXPR, type, |
10763 return build_call_expr (powfn, 2, arg00, arg); | 11156 arg01, arg11); |
11157 return build_call_expr_loc (loc, powfn, 2, arg00, arg); | |
10764 } | 11158 } |
10765 } | 11159 } |
10766 | 11160 |
10767 /* Optimize tan(x)*cos(x) as sin(x). */ | 11161 /* Optimize tan(x)*cos(x) as sin(x). */ |
10768 if (((fcode0 == BUILT_IN_TAN && fcode1 == BUILT_IN_COS) | 11162 if (((fcode0 == BUILT_IN_TAN && fcode1 == BUILT_IN_COS) |
10775 CALL_EXPR_ARG (arg1, 0), 0)) | 11169 CALL_EXPR_ARG (arg1, 0), 0)) |
10776 { | 11170 { |
10777 tree sinfn = mathfn_built_in (type, BUILT_IN_SIN); | 11171 tree sinfn = mathfn_built_in (type, BUILT_IN_SIN); |
10778 | 11172 |
10779 if (sinfn != NULL_TREE) | 11173 if (sinfn != NULL_TREE) |
10780 return build_call_expr (sinfn, 1, CALL_EXPR_ARG (arg0, 0)); | 11174 return build_call_expr_loc (loc, sinfn, 1, |
11175 CALL_EXPR_ARG (arg0, 0)); | |
10781 } | 11176 } |
10782 | 11177 |
10783 /* Optimize x*pow(x,c) as pow(x,c+1). */ | 11178 /* Optimize x*pow(x,c) as pow(x,c+1). */ |
10784 if (fcode1 == BUILT_IN_POW | 11179 if (fcode1 == BUILT_IN_POW |
10785 || fcode1 == BUILT_IN_POWF | 11180 || fcode1 == BUILT_IN_POWF |
10796 tree arg; | 11191 tree arg; |
10797 | 11192 |
10798 c = TREE_REAL_CST (arg11); | 11193 c = TREE_REAL_CST (arg11); |
10799 real_arithmetic (&c, PLUS_EXPR, &c, &dconst1); | 11194 real_arithmetic (&c, PLUS_EXPR, &c, &dconst1); |
10800 arg = build_real (type, c); | 11195 arg = build_real (type, c); |
10801 return build_call_expr (powfn, 2, arg0, arg); | 11196 return build_call_expr_loc (loc, powfn, 2, arg0, arg); |
10802 } | 11197 } |
10803 } | 11198 } |
10804 | 11199 |
10805 /* Optimize pow(x,c)*x as pow(x,c+1). */ | 11200 /* Optimize pow(x,c)*x as pow(x,c+1). */ |
10806 if (fcode0 == BUILT_IN_POW | 11201 if (fcode0 == BUILT_IN_POW |
10818 tree arg; | 11213 tree arg; |
10819 | 11214 |
10820 c = TREE_REAL_CST (arg01); | 11215 c = TREE_REAL_CST (arg01); |
10821 real_arithmetic (&c, PLUS_EXPR, &c, &dconst1); | 11216 real_arithmetic (&c, PLUS_EXPR, &c, &dconst1); |
10822 arg = build_real (type, c); | 11217 arg = build_real (type, c); |
10823 return build_call_expr (powfn, 2, arg1, arg); | 11218 return build_call_expr_loc (loc, powfn, 2, arg1, arg); |
10824 } | 11219 } |
10825 } | 11220 } |
10826 | 11221 |
10827 /* Optimize x*x as pow(x,2.0), which is expanded as x*x. */ | 11222 /* Optimize x*x as pow(x,2.0), which is expanded as x*x. */ |
10828 if (optimize_function_for_speed_p (cfun) | 11223 if (optimize_function_for_speed_p (cfun) |
10831 tree powfn = mathfn_built_in (type, BUILT_IN_POW); | 11226 tree powfn = mathfn_built_in (type, BUILT_IN_POW); |
10832 | 11227 |
10833 if (powfn) | 11228 if (powfn) |
10834 { | 11229 { |
10835 tree arg = build_real (type, dconst2); | 11230 tree arg = build_real (type, dconst2); |
10836 return build_call_expr (powfn, 2, arg0, arg); | 11231 return build_call_expr_loc (loc, powfn, 2, arg0, arg); |
10837 } | 11232 } |
10838 } | 11233 } |
10839 } | 11234 } |
10840 } | 11235 } |
10841 goto associate; | 11236 goto associate; |
10842 | 11237 |
10843 case BIT_IOR_EXPR: | 11238 case BIT_IOR_EXPR: |
10844 bit_ior: | 11239 bit_ior: |
10845 if (integer_all_onesp (arg1)) | 11240 if (integer_all_onesp (arg1)) |
10846 return omit_one_operand (type, arg1, arg0); | 11241 return omit_one_operand_loc (loc, type, arg1, arg0); |
10847 if (integer_zerop (arg1)) | 11242 if (integer_zerop (arg1)) |
10848 return non_lvalue (fold_convert (type, arg0)); | 11243 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
10849 if (operand_equal_p (arg0, arg1, 0)) | 11244 if (operand_equal_p (arg0, arg1, 0)) |
10850 return non_lvalue (fold_convert (type, arg0)); | 11245 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
10851 | 11246 |
10852 /* ~X | X is -1. */ | 11247 /* ~X | X is -1. */ |
10853 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 11248 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
10854 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 11249 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
10855 { | 11250 { |
10856 t1 = fold_convert (type, integer_zero_node); | 11251 t1 = fold_convert_loc (loc, type, integer_zero_node); |
10857 t1 = fold_unary (BIT_NOT_EXPR, type, t1); | 11252 t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1); |
10858 return omit_one_operand (type, t1, arg1); | 11253 return omit_one_operand_loc (loc, type, t1, arg1); |
10859 } | 11254 } |
10860 | 11255 |
10861 /* X | ~X is -1. */ | 11256 /* X | ~X is -1. */ |
10862 if (TREE_CODE (arg1) == BIT_NOT_EXPR | 11257 if (TREE_CODE (arg1) == BIT_NOT_EXPR |
10863 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 11258 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
10864 { | 11259 { |
10865 t1 = fold_convert (type, integer_zero_node); | 11260 t1 = fold_convert_loc (loc, type, integer_zero_node); |
10866 t1 = fold_unary (BIT_NOT_EXPR, type, t1); | 11261 t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1); |
10867 return omit_one_operand (type, t1, arg0); | 11262 return omit_one_operand_loc (loc, type, t1, arg0); |
10868 } | 11263 } |
10869 | 11264 |
10870 /* Canonicalize (X & C1) | C2. */ | 11265 /* Canonicalize (X & C1) | C2. */ |
10871 if (TREE_CODE (arg0) == BIT_AND_EXPR | 11266 if (TREE_CODE (arg0) == BIT_AND_EXPR |
10872 && TREE_CODE (arg1) == INTEGER_CST | 11267 && TREE_CODE (arg1) == INTEGER_CST |
10879 hi2 = TREE_INT_CST_HIGH (arg1); | 11274 hi2 = TREE_INT_CST_HIGH (arg1); |
10880 lo2 = TREE_INT_CST_LOW (arg1); | 11275 lo2 = TREE_INT_CST_LOW (arg1); |
10881 | 11276 |
10882 /* If (C1&C2) == C1, then (X&C1)|C2 becomes (X,C2). */ | 11277 /* If (C1&C2) == C1, then (X&C1)|C2 becomes (X,C2). */ |
10883 if ((hi1 & hi2) == hi1 && (lo1 & lo2) == lo1) | 11278 if ((hi1 & hi2) == hi1 && (lo1 & lo2) == lo1) |
10884 return omit_one_operand (type, arg1, TREE_OPERAND (arg0, 0)); | 11279 return omit_one_operand_loc (loc, type, arg1, |
11280 TREE_OPERAND (arg0, 0)); | |
10885 | 11281 |
10886 if (width > HOST_BITS_PER_WIDE_INT) | 11282 if (width > HOST_BITS_PER_WIDE_INT) |
10887 { | 11283 { |
10888 mhi = (unsigned HOST_WIDE_INT) -1 | 11284 mhi = (unsigned HOST_WIDE_INT) -1 |
10889 >> (2 * HOST_BITS_PER_WIDE_INT - width); | 11285 >> (2 * HOST_BITS_PER_WIDE_INT - width); |
10890 mlo = -1; | 11286 mlo = -1; |
10891 } | 11287 } |
10892 else | 11288 else |
10893 { | 11289 { |
10896 >> (HOST_BITS_PER_WIDE_INT - width); | 11292 >> (HOST_BITS_PER_WIDE_INT - width); |
10897 } | 11293 } |
10898 | 11294 |
10899 /* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2. */ | 11295 /* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2. */ |
10900 if ((~(hi1 | hi2) & mhi) == 0 && (~(lo1 | lo2) & mlo) == 0) | 11296 if ((~(hi1 | hi2) & mhi) == 0 && (~(lo1 | lo2) & mlo) == 0) |
10901 return fold_build2 (BIT_IOR_EXPR, type, | 11297 return fold_build2_loc (loc, BIT_IOR_EXPR, type, |
10902 TREE_OPERAND (arg0, 0), arg1); | 11298 TREE_OPERAND (arg0, 0), arg1); |
10903 | 11299 |
10904 /* Minimize the number of bits set in C1, i.e. C1 := C1 & ~C2, | 11300 /* Minimize the number of bits set in C1, i.e. C1 := C1 & ~C2, |
10905 unless (C1 & ~C2) | (C2 & C3) for some C3 is a mask of some | 11301 unless (C1 & ~C2) | (C2 & C3) for some C3 is a mask of some |
10906 mode which allows further optimizations. */ | 11302 mode which allows further optimizations. */ |
10923 lo3 = mask; | 11319 lo3 = mask; |
10924 break; | 11320 break; |
10925 } | 11321 } |
10926 } | 11322 } |
10927 if (hi3 != hi1 || lo3 != lo1) | 11323 if (hi3 != hi1 || lo3 != lo1) |
10928 return fold_build2 (BIT_IOR_EXPR, type, | 11324 return fold_build2_loc (loc, BIT_IOR_EXPR, type, |
10929 fold_build2 (BIT_AND_EXPR, type, | 11325 fold_build2_loc (loc, BIT_AND_EXPR, type, |
10930 TREE_OPERAND (arg0, 0), | 11326 TREE_OPERAND (arg0, 0), |
10931 build_int_cst_wide (type, | 11327 build_int_cst_wide (type, |
10932 lo3, hi3)), | 11328 lo3, hi3)), |
10933 arg1); | 11329 arg1); |
10934 } | 11330 } |
10935 | 11331 |
10936 /* (X & Y) | Y is (X, Y). */ | 11332 /* (X & Y) | Y is (X, Y). */ |
10937 if (TREE_CODE (arg0) == BIT_AND_EXPR | 11333 if (TREE_CODE (arg0) == BIT_AND_EXPR |
10938 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) | 11334 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) |
10939 return omit_one_operand (type, arg1, TREE_OPERAND (arg0, 0)); | 11335 return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 0)); |
10940 /* (X & Y) | X is (Y, X). */ | 11336 /* (X & Y) | X is (Y, X). */ |
10941 if (TREE_CODE (arg0) == BIT_AND_EXPR | 11337 if (TREE_CODE (arg0) == BIT_AND_EXPR |
10942 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) | 11338 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) |
10943 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) | 11339 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) |
10944 return omit_one_operand (type, arg1, TREE_OPERAND (arg0, 1)); | 11340 return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 1)); |
10945 /* X | (X & Y) is (Y, X). */ | 11341 /* X | (X & Y) is (Y, X). */ |
10946 if (TREE_CODE (arg1) == BIT_AND_EXPR | 11342 if (TREE_CODE (arg1) == BIT_AND_EXPR |
10947 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0) | 11343 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0) |
10948 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 1))) | 11344 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 1))) |
10949 return omit_one_operand (type, arg0, TREE_OPERAND (arg1, 1)); | 11345 return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 1)); |
10950 /* X | (Y & X) is (Y, X). */ | 11346 /* X | (Y & X) is (Y, X). */ |
10951 if (TREE_CODE (arg1) == BIT_AND_EXPR | 11347 if (TREE_CODE (arg1) == BIT_AND_EXPR |
10952 && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0) | 11348 && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0) |
10953 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) | 11349 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) |
10954 return omit_one_operand (type, arg0, TREE_OPERAND (arg1, 0)); | 11350 return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 0)); |
10955 | 11351 |
10956 t1 = distribute_bit_expr (code, type, arg0, arg1); | 11352 t1 = distribute_bit_expr (loc, code, type, arg0, arg1); |
10957 if (t1 != NULL_TREE) | 11353 if (t1 != NULL_TREE) |
10958 return t1; | 11354 return t1; |
10959 | 11355 |
10960 /* Convert (or (not arg0) (not arg1)) to (not (and (arg0) (arg1))). | 11356 /* Convert (or (not arg0) (not arg1)) to (not (and (arg0) (arg1))). |
10961 | 11357 |
10964 which will allow use of NAND instructions provided by the | 11360 which will allow use of NAND instructions provided by the |
10965 backend if they exist. */ | 11361 backend if they exist. */ |
10966 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 11362 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
10967 && TREE_CODE (arg1) == BIT_NOT_EXPR) | 11363 && TREE_CODE (arg1) == BIT_NOT_EXPR) |
10968 { | 11364 { |
10969 return fold_build1 (BIT_NOT_EXPR, type, | 11365 return |
10970 build2 (BIT_AND_EXPR, type, | 11366 fold_build1_loc (loc, BIT_NOT_EXPR, type, |
10971 fold_convert (type, | 11367 build2 (BIT_AND_EXPR, type, |
10972 TREE_OPERAND (arg0, 0)), | 11368 fold_convert_loc (loc, type, |
10973 fold_convert (type, | 11369 TREE_OPERAND (arg0, 0)), |
10974 TREE_OPERAND (arg1, 0)))); | 11370 fold_convert_loc (loc, type, |
11371 TREE_OPERAND (arg1, 0)))); | |
10975 } | 11372 } |
10976 | 11373 |
10977 /* See if this can be simplified into a rotate first. If that | 11374 /* See if this can be simplified into a rotate first. If that |
10978 is unsuccessful continue in the association code. */ | 11375 is unsuccessful continue in the association code. */ |
10979 goto bit_rotate; | 11376 goto bit_rotate; |
10980 | 11377 |
10981 case BIT_XOR_EXPR: | 11378 case BIT_XOR_EXPR: |
10982 if (integer_zerop (arg1)) | 11379 if (integer_zerop (arg1)) |
10983 return non_lvalue (fold_convert (type, arg0)); | 11380 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
10984 if (integer_all_onesp (arg1)) | 11381 if (integer_all_onesp (arg1)) |
10985 return fold_build1 (BIT_NOT_EXPR, type, op0); | 11382 return fold_build1_loc (loc, BIT_NOT_EXPR, type, op0); |
10986 if (operand_equal_p (arg0, arg1, 0)) | 11383 if (operand_equal_p (arg0, arg1, 0)) |
10987 return omit_one_operand (type, integer_zero_node, arg0); | 11384 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
10988 | 11385 |
10989 /* ~X ^ X is -1. */ | 11386 /* ~X ^ X is -1. */ |
10990 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 11387 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
10991 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 11388 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
10992 { | 11389 { |
10993 t1 = fold_convert (type, integer_zero_node); | 11390 t1 = fold_convert_loc (loc, type, integer_zero_node); |
10994 t1 = fold_unary (BIT_NOT_EXPR, type, t1); | 11391 t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1); |
10995 return omit_one_operand (type, t1, arg1); | 11392 return omit_one_operand_loc (loc, type, t1, arg1); |
10996 } | 11393 } |
10997 | 11394 |
10998 /* X ^ ~X is -1. */ | 11395 /* X ^ ~X is -1. */ |
10999 if (TREE_CODE (arg1) == BIT_NOT_EXPR | 11396 if (TREE_CODE (arg1) == BIT_NOT_EXPR |
11000 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 11397 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
11001 { | 11398 { |
11002 t1 = fold_convert (type, integer_zero_node); | 11399 t1 = fold_convert_loc (loc, type, integer_zero_node); |
11003 t1 = fold_unary (BIT_NOT_EXPR, type, t1); | 11400 t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1); |
11004 return omit_one_operand (type, t1, arg0); | 11401 return omit_one_operand_loc (loc, type, t1, arg0); |
11005 } | 11402 } |
11006 | 11403 |
11007 /* If we are XORing two BIT_AND_EXPR's, both of which are and'ing | 11404 /* If we are XORing two BIT_AND_EXPR's, both of which are and'ing |
11008 with a constant, and the two constants have no bits in common, | 11405 with a constant, and the two constants have no bits in common, |
11009 we should treat this as a BIT_IOR_EXPR since this may produce more | 11406 we should treat this as a BIT_IOR_EXPR since this may produce more |
11023 /* (X | Y) ^ X -> Y & ~ X*/ | 11420 /* (X | Y) ^ X -> Y & ~ X*/ |
11024 if (TREE_CODE (arg0) == BIT_IOR_EXPR | 11421 if (TREE_CODE (arg0) == BIT_IOR_EXPR |
11025 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 11422 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
11026 { | 11423 { |
11027 tree t2 = TREE_OPERAND (arg0, 1); | 11424 tree t2 = TREE_OPERAND (arg0, 1); |
11028 t1 = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), | 11425 t1 = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg1), |
11029 arg1); | 11426 arg1); |
11030 t1 = fold_build2 (BIT_AND_EXPR, type, fold_convert (type, t2), | 11427 t1 = fold_build2_loc (loc, BIT_AND_EXPR, type, |
11031 fold_convert (type, t1)); | 11428 fold_convert_loc (loc, type, t2), |
11429 fold_convert_loc (loc, type, t1)); | |
11032 return t1; | 11430 return t1; |
11033 } | 11431 } |
11034 | 11432 |
11035 /* (Y | X) ^ X -> Y & ~ X*/ | 11433 /* (Y | X) ^ X -> Y & ~ X*/ |
11036 if (TREE_CODE (arg0) == BIT_IOR_EXPR | 11434 if (TREE_CODE (arg0) == BIT_IOR_EXPR |
11037 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) | 11435 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) |
11038 { | 11436 { |
11039 tree t2 = TREE_OPERAND (arg0, 0); | 11437 tree t2 = TREE_OPERAND (arg0, 0); |
11040 t1 = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), | 11438 t1 = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg1), |
11041 arg1); | 11439 arg1); |
11042 t1 = fold_build2 (BIT_AND_EXPR, type, fold_convert (type, t2), | 11440 t1 = fold_build2_loc (loc, BIT_AND_EXPR, type, |
11043 fold_convert (type, t1)); | 11441 fold_convert_loc (loc, type, t2), |
11442 fold_convert_loc (loc, type, t1)); | |
11044 return t1; | 11443 return t1; |
11045 } | 11444 } |
11046 | 11445 |
11047 /* X ^ (X | Y) -> Y & ~ X*/ | 11446 /* X ^ (X | Y) -> Y & ~ X*/ |
11048 if (TREE_CODE (arg1) == BIT_IOR_EXPR | 11447 if (TREE_CODE (arg1) == BIT_IOR_EXPR |
11049 && operand_equal_p (TREE_OPERAND (arg1, 0), arg0, 0)) | 11448 && operand_equal_p (TREE_OPERAND (arg1, 0), arg0, 0)) |
11050 { | 11449 { |
11051 tree t2 = TREE_OPERAND (arg1, 1); | 11450 tree t2 = TREE_OPERAND (arg1, 1); |
11052 t1 = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg0), | 11451 t1 = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg0), |
11053 arg0); | 11452 arg0); |
11054 t1 = fold_build2 (BIT_AND_EXPR, type, fold_convert (type, t2), | 11453 t1 = fold_build2_loc (loc, BIT_AND_EXPR, type, |
11055 fold_convert (type, t1)); | 11454 fold_convert_loc (loc, type, t2), |
11455 fold_convert_loc (loc, type, t1)); | |
11056 return t1; | 11456 return t1; |
11057 } | 11457 } |
11058 | 11458 |
11059 /* X ^ (Y | X) -> Y & ~ X*/ | 11459 /* X ^ (Y | X) -> Y & ~ X*/ |
11060 if (TREE_CODE (arg1) == BIT_IOR_EXPR | 11460 if (TREE_CODE (arg1) == BIT_IOR_EXPR |
11061 && operand_equal_p (TREE_OPERAND (arg1, 1), arg0, 0)) | 11461 && operand_equal_p (TREE_OPERAND (arg1, 1), arg0, 0)) |
11062 { | 11462 { |
11063 tree t2 = TREE_OPERAND (arg1, 0); | 11463 tree t2 = TREE_OPERAND (arg1, 0); |
11064 t1 = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg0), | 11464 t1 = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg0), |
11065 arg0); | 11465 arg0); |
11066 t1 = fold_build2 (BIT_AND_EXPR, type, fold_convert (type, t2), | 11466 t1 = fold_build2_loc (loc, BIT_AND_EXPR, type, |
11067 fold_convert (type, t1)); | 11467 fold_convert_loc (loc, type, t2), |
11468 fold_convert_loc (loc, type, t1)); | |
11068 return t1; | 11469 return t1; |
11069 } | 11470 } |
11070 | 11471 |
11071 /* Convert ~X ^ ~Y to X ^ Y. */ | 11472 /* Convert ~X ^ ~Y to X ^ Y. */ |
11072 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 11473 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
11073 && TREE_CODE (arg1) == BIT_NOT_EXPR) | 11474 && TREE_CODE (arg1) == BIT_NOT_EXPR) |
11074 return fold_build2 (code, type, | 11475 return fold_build2_loc (loc, code, type, |
11075 fold_convert (type, TREE_OPERAND (arg0, 0)), | 11476 fold_convert_loc (loc, type, |
11076 fold_convert (type, TREE_OPERAND (arg1, 0))); | 11477 TREE_OPERAND (arg0, 0)), |
11478 fold_convert_loc (loc, type, | |
11479 TREE_OPERAND (arg1, 0))); | |
11077 | 11480 |
11078 /* Convert ~X ^ C to X ^ ~C. */ | 11481 /* Convert ~X ^ C to X ^ ~C. */ |
11079 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 11482 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
11080 && TREE_CODE (arg1) == INTEGER_CST) | 11483 && TREE_CODE (arg1) == INTEGER_CST) |
11081 return fold_build2 (code, type, | 11484 return fold_build2_loc (loc, code, type, |
11082 fold_convert (type, TREE_OPERAND (arg0, 0)), | 11485 fold_convert_loc (loc, type, |
11083 fold_build1 (BIT_NOT_EXPR, type, arg1)); | 11486 TREE_OPERAND (arg0, 0)), |
11487 fold_build1_loc (loc, BIT_NOT_EXPR, type, arg1)); | |
11084 | 11488 |
11085 /* Fold (X & 1) ^ 1 as (X & 1) == 0. */ | 11489 /* Fold (X & 1) ^ 1 as (X & 1) == 0. */ |
11086 if (TREE_CODE (arg0) == BIT_AND_EXPR | 11490 if (TREE_CODE (arg0) == BIT_AND_EXPR |
11087 && integer_onep (TREE_OPERAND (arg0, 1)) | 11491 && integer_onep (TREE_OPERAND (arg0, 1)) |
11088 && integer_onep (arg1)) | 11492 && integer_onep (arg1)) |
11089 return fold_build2 (EQ_EXPR, type, arg0, | 11493 return fold_build2_loc (loc, EQ_EXPR, type, arg0, |
11090 build_int_cst (TREE_TYPE (arg0), 0)); | 11494 build_int_cst (TREE_TYPE (arg0), 0)); |
11091 | 11495 |
11092 /* Fold (X & Y) ^ Y as ~X & Y. */ | 11496 /* Fold (X & Y) ^ Y as ~X & Y. */ |
11093 if (TREE_CODE (arg0) == BIT_AND_EXPR | 11497 if (TREE_CODE (arg0) == BIT_AND_EXPR |
11094 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) | 11498 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) |
11095 { | 11499 { |
11096 tem = fold_convert (type, TREE_OPERAND (arg0, 0)); | 11500 tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); |
11097 return fold_build2 (BIT_AND_EXPR, type, | 11501 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11098 fold_build1 (BIT_NOT_EXPR, type, tem), | 11502 fold_build1_loc (loc, BIT_NOT_EXPR, type, tem), |
11099 fold_convert (type, arg1)); | 11503 fold_convert_loc (loc, type, arg1)); |
11100 } | 11504 } |
11101 /* Fold (X & Y) ^ X as ~Y & X. */ | 11505 /* Fold (X & Y) ^ X as ~Y & X. */ |
11102 if (TREE_CODE (arg0) == BIT_AND_EXPR | 11506 if (TREE_CODE (arg0) == BIT_AND_EXPR |
11103 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) | 11507 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) |
11104 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) | 11508 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) |
11105 { | 11509 { |
11106 tem = fold_convert (type, TREE_OPERAND (arg0, 1)); | 11510 tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1)); |
11107 return fold_build2 (BIT_AND_EXPR, type, | 11511 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11108 fold_build1 (BIT_NOT_EXPR, type, tem), | 11512 fold_build1_loc (loc, BIT_NOT_EXPR, type, tem), |
11109 fold_convert (type, arg1)); | 11513 fold_convert_loc (loc, type, arg1)); |
11110 } | 11514 } |
11111 /* Fold X ^ (X & Y) as X & ~Y. */ | 11515 /* Fold X ^ (X & Y) as X & ~Y. */ |
11112 if (TREE_CODE (arg1) == BIT_AND_EXPR | 11516 if (TREE_CODE (arg1) == BIT_AND_EXPR |
11113 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 11517 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
11114 { | 11518 { |
11115 tem = fold_convert (type, TREE_OPERAND (arg1, 1)); | 11519 tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1)); |
11116 return fold_build2 (BIT_AND_EXPR, type, | 11520 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11117 fold_convert (type, arg0), | 11521 fold_convert_loc (loc, type, arg0), |
11118 fold_build1 (BIT_NOT_EXPR, type, tem)); | 11522 fold_build1_loc (loc, BIT_NOT_EXPR, type, tem)); |
11119 } | 11523 } |
11120 /* Fold X ^ (Y & X) as ~Y & X. */ | 11524 /* Fold X ^ (Y & X) as ~Y & X. */ |
11121 if (TREE_CODE (arg1) == BIT_AND_EXPR | 11525 if (TREE_CODE (arg1) == BIT_AND_EXPR |
11122 && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0) | 11526 && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0) |
11123 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) | 11527 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) |
11124 { | 11528 { |
11125 tem = fold_convert (type, TREE_OPERAND (arg1, 0)); | 11529 tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0)); |
11126 return fold_build2 (BIT_AND_EXPR, type, | 11530 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11127 fold_build1 (BIT_NOT_EXPR, type, tem), | 11531 fold_build1_loc (loc, BIT_NOT_EXPR, type, tem), |
11128 fold_convert (type, arg0)); | 11532 fold_convert_loc (loc, type, arg0)); |
11129 } | 11533 } |
11130 | 11534 |
11131 /* See if this can be simplified into a rotate first. If that | 11535 /* See if this can be simplified into a rotate first. If that |
11132 is unsuccessful continue in the association code. */ | 11536 is unsuccessful continue in the association code. */ |
11133 goto bit_rotate; | 11537 goto bit_rotate; |
11134 | 11538 |
11135 case BIT_AND_EXPR: | 11539 case BIT_AND_EXPR: |
11136 if (integer_all_onesp (arg1)) | 11540 if (integer_all_onesp (arg1)) |
11137 return non_lvalue (fold_convert (type, arg0)); | 11541 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
11138 if (integer_zerop (arg1)) | 11542 if (integer_zerop (arg1)) |
11139 return omit_one_operand (type, arg1, arg0); | 11543 return omit_one_operand_loc (loc, type, arg1, arg0); |
11140 if (operand_equal_p (arg0, arg1, 0)) | 11544 if (operand_equal_p (arg0, arg1, 0)) |
11141 return non_lvalue (fold_convert (type, arg0)); | 11545 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
11142 | 11546 |
11143 /* ~X & X is always zero. */ | 11547 /* ~X & X is always zero. */ |
11144 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 11548 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
11145 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 11549 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
11146 return omit_one_operand (type, integer_zero_node, arg1); | 11550 return omit_one_operand_loc (loc, type, integer_zero_node, arg1); |
11147 | 11551 |
11148 /* X & ~X is always zero. */ | 11552 /* X & ~X is always zero. */ |
11149 if (TREE_CODE (arg1) == BIT_NOT_EXPR | 11553 if (TREE_CODE (arg1) == BIT_NOT_EXPR |
11150 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 11554 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
11151 return omit_one_operand (type, integer_zero_node, arg0); | 11555 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
11152 | 11556 |
11153 /* Canonicalize (X | C1) & C2 as (X & C2) | (C1 & C2). */ | 11557 /* Canonicalize (X | C1) & C2 as (X & C2) | (C1 & C2). */ |
11154 if (TREE_CODE (arg0) == BIT_IOR_EXPR | 11558 if (TREE_CODE (arg0) == BIT_IOR_EXPR |
11155 && TREE_CODE (arg1) == INTEGER_CST | 11559 && TREE_CODE (arg1) == INTEGER_CST |
11156 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) | 11560 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) |
11157 { | 11561 { |
11158 tree tmp1 = fold_convert (type, arg1); | 11562 tree tmp1 = fold_convert_loc (loc, type, arg1); |
11159 tree tmp2 = fold_convert (type, TREE_OPERAND (arg0, 0)); | 11563 tree tmp2 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); |
11160 tree tmp3 = fold_convert (type, TREE_OPERAND (arg0, 1)); | 11564 tree tmp3 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1)); |
11161 tmp2 = fold_build2 (BIT_AND_EXPR, type, tmp2, tmp1); | 11565 tmp2 = fold_build2_loc (loc, BIT_AND_EXPR, type, tmp2, tmp1); |
11162 tmp3 = fold_build2 (BIT_AND_EXPR, type, tmp3, tmp1); | 11566 tmp3 = fold_build2_loc (loc, BIT_AND_EXPR, type, tmp3, tmp1); |
11163 return fold_convert (type, | 11567 return |
11164 fold_build2 (BIT_IOR_EXPR, type, tmp2, tmp3)); | 11568 fold_convert_loc (loc, type, |
11569 fold_build2_loc (loc, BIT_IOR_EXPR, | |
11570 type, tmp2, tmp3)); | |
11165 } | 11571 } |
11166 | 11572 |
11167 /* (X | Y) & Y is (X, Y). */ | 11573 /* (X | Y) & Y is (X, Y). */ |
11168 if (TREE_CODE (arg0) == BIT_IOR_EXPR | 11574 if (TREE_CODE (arg0) == BIT_IOR_EXPR |
11169 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) | 11575 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) |
11170 return omit_one_operand (type, arg1, TREE_OPERAND (arg0, 0)); | 11576 return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 0)); |
11171 /* (X | Y) & X is (Y, X). */ | 11577 /* (X | Y) & X is (Y, X). */ |
11172 if (TREE_CODE (arg0) == BIT_IOR_EXPR | 11578 if (TREE_CODE (arg0) == BIT_IOR_EXPR |
11173 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) | 11579 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) |
11174 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) | 11580 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) |
11175 return omit_one_operand (type, arg1, TREE_OPERAND (arg0, 1)); | 11581 return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 1)); |
11176 /* X & (X | Y) is (Y, X). */ | 11582 /* X & (X | Y) is (Y, X). */ |
11177 if (TREE_CODE (arg1) == BIT_IOR_EXPR | 11583 if (TREE_CODE (arg1) == BIT_IOR_EXPR |
11178 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0) | 11584 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0) |
11179 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 1))) | 11585 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 1))) |
11180 return omit_one_operand (type, arg0, TREE_OPERAND (arg1, 1)); | 11586 return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 1)); |
11181 /* X & (Y | X) is (Y, X). */ | 11587 /* X & (Y | X) is (Y, X). */ |
11182 if (TREE_CODE (arg1) == BIT_IOR_EXPR | 11588 if (TREE_CODE (arg1) == BIT_IOR_EXPR |
11183 && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0) | 11589 && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0) |
11184 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) | 11590 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) |
11185 return omit_one_operand (type, arg0, TREE_OPERAND (arg1, 0)); | 11591 return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 0)); |
11186 | 11592 |
11187 /* Fold (X ^ 1) & 1 as (X & 1) == 0. */ | 11593 /* Fold (X ^ 1) & 1 as (X & 1) == 0. */ |
11188 if (TREE_CODE (arg0) == BIT_XOR_EXPR | 11594 if (TREE_CODE (arg0) == BIT_XOR_EXPR |
11189 && integer_onep (TREE_OPERAND (arg0, 1)) | 11595 && integer_onep (TREE_OPERAND (arg0, 1)) |
11190 && integer_onep (arg1)) | 11596 && integer_onep (arg1)) |
11191 { | 11597 { |
11192 tem = TREE_OPERAND (arg0, 0); | 11598 tem = TREE_OPERAND (arg0, 0); |
11193 return fold_build2 (EQ_EXPR, type, | 11599 return fold_build2_loc (loc, EQ_EXPR, type, |
11194 fold_build2 (BIT_AND_EXPR, TREE_TYPE (tem), tem, | 11600 fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (tem), tem, |
11195 build_int_cst (TREE_TYPE (tem), 1)), | 11601 build_int_cst (TREE_TYPE (tem), 1)), |
11196 build_int_cst (TREE_TYPE (tem), 0)); | 11602 build_int_cst (TREE_TYPE (tem), 0)); |
11197 } | 11603 } |
11198 /* Fold ~X & 1 as (X & 1) == 0. */ | 11604 /* Fold ~X & 1 as (X & 1) == 0. */ |
11199 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 11605 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
11200 && integer_onep (arg1)) | 11606 && integer_onep (arg1)) |
11201 { | 11607 { |
11202 tem = TREE_OPERAND (arg0, 0); | 11608 tem = TREE_OPERAND (arg0, 0); |
11203 return fold_build2 (EQ_EXPR, type, | 11609 return fold_build2_loc (loc, EQ_EXPR, type, |
11204 fold_build2 (BIT_AND_EXPR, TREE_TYPE (tem), tem, | 11610 fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (tem), tem, |
11205 build_int_cst (TREE_TYPE (tem), 1)), | 11611 build_int_cst (TREE_TYPE (tem), 1)), |
11206 build_int_cst (TREE_TYPE (tem), 0)); | 11612 build_int_cst (TREE_TYPE (tem), 0)); |
11207 } | 11613 } |
11208 | 11614 |
11209 /* Fold (X ^ Y) & Y as ~X & Y. */ | 11615 /* Fold (X ^ Y) & Y as ~X & Y. */ |
11210 if (TREE_CODE (arg0) == BIT_XOR_EXPR | 11616 if (TREE_CODE (arg0) == BIT_XOR_EXPR |
11211 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) | 11617 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) |
11212 { | 11618 { |
11213 tem = fold_convert (type, TREE_OPERAND (arg0, 0)); | 11619 tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); |
11214 return fold_build2 (BIT_AND_EXPR, type, | 11620 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11215 fold_build1 (BIT_NOT_EXPR, type, tem), | 11621 fold_build1_loc (loc, BIT_NOT_EXPR, type, tem), |
11216 fold_convert (type, arg1)); | 11622 fold_convert_loc (loc, type, arg1)); |
11217 } | 11623 } |
11218 /* Fold (X ^ Y) & X as ~Y & X. */ | 11624 /* Fold (X ^ Y) & X as ~Y & X. */ |
11219 if (TREE_CODE (arg0) == BIT_XOR_EXPR | 11625 if (TREE_CODE (arg0) == BIT_XOR_EXPR |
11220 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) | 11626 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) |
11221 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) | 11627 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) |
11222 { | 11628 { |
11223 tem = fold_convert (type, TREE_OPERAND (arg0, 1)); | 11629 tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1)); |
11224 return fold_build2 (BIT_AND_EXPR, type, | 11630 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11225 fold_build1 (BIT_NOT_EXPR, type, tem), | 11631 fold_build1_loc (loc, BIT_NOT_EXPR, type, tem), |
11226 fold_convert (type, arg1)); | 11632 fold_convert_loc (loc, type, arg1)); |
11227 } | 11633 } |
11228 /* Fold X & (X ^ Y) as X & ~Y. */ | 11634 /* Fold X & (X ^ Y) as X & ~Y. */ |
11229 if (TREE_CODE (arg1) == BIT_XOR_EXPR | 11635 if (TREE_CODE (arg1) == BIT_XOR_EXPR |
11230 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 11636 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
11231 { | 11637 { |
11232 tem = fold_convert (type, TREE_OPERAND (arg1, 1)); | 11638 tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1)); |
11233 return fold_build2 (BIT_AND_EXPR, type, | 11639 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11234 fold_convert (type, arg0), | 11640 fold_convert_loc (loc, type, arg0), |
11235 fold_build1 (BIT_NOT_EXPR, type, tem)); | 11641 fold_build1_loc (loc, BIT_NOT_EXPR, type, tem)); |
11236 } | 11642 } |
11237 /* Fold X & (Y ^ X) as ~Y & X. */ | 11643 /* Fold X & (Y ^ X) as ~Y & X. */ |
11238 if (TREE_CODE (arg1) == BIT_XOR_EXPR | 11644 if (TREE_CODE (arg1) == BIT_XOR_EXPR |
11239 && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0) | 11645 && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0) |
11240 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) | 11646 && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0))) |
11241 { | 11647 { |
11242 tem = fold_convert (type, TREE_OPERAND (arg1, 0)); | 11648 tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0)); |
11243 return fold_build2 (BIT_AND_EXPR, type, | 11649 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11244 fold_build1 (BIT_NOT_EXPR, type, tem), | 11650 fold_build1_loc (loc, BIT_NOT_EXPR, type, tem), |
11245 fold_convert (type, arg0)); | 11651 fold_convert_loc (loc, type, arg0)); |
11246 } | 11652 } |
11247 | 11653 |
11248 t1 = distribute_bit_expr (code, type, arg0, arg1); | 11654 t1 = distribute_bit_expr (loc, code, type, arg0, arg1); |
11249 if (t1 != NULL_TREE) | 11655 if (t1 != NULL_TREE) |
11250 return t1; | 11656 return t1; |
11251 /* Simplify ((int)c & 0377) into (int)c, if c is unsigned char. */ | 11657 /* Simplify ((int)c & 0377) into (int)c, if c is unsigned char. */ |
11252 if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) == NOP_EXPR | 11658 if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) == NOP_EXPR |
11253 && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0)))) | 11659 && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0)))) |
11256 = TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0))); | 11662 = TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0))); |
11257 | 11663 |
11258 if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_WIDE_INT | 11664 if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_WIDE_INT |
11259 && (~TREE_INT_CST_LOW (arg1) | 11665 && (~TREE_INT_CST_LOW (arg1) |
11260 & (((HOST_WIDE_INT) 1 << prec) - 1)) == 0) | 11666 & (((HOST_WIDE_INT) 1 << prec) - 1)) == 0) |
11261 return fold_convert (type, TREE_OPERAND (arg0, 0)); | 11667 return |
11668 fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); | |
11262 } | 11669 } |
11263 | 11670 |
11264 /* Convert (and (not arg0) (not arg1)) to (not (or (arg0) (arg1))). | 11671 /* Convert (and (not arg0) (not arg1)) to (not (or (arg0) (arg1))). |
11265 | 11672 |
11266 This results in more efficient code for machines without a NOR | 11673 This results in more efficient code for machines without a NOR |
11268 which will allow use of NOR instructions provided by the | 11675 which will allow use of NOR instructions provided by the |
11269 backend if they exist. */ | 11676 backend if they exist. */ |
11270 if (TREE_CODE (arg0) == BIT_NOT_EXPR | 11677 if (TREE_CODE (arg0) == BIT_NOT_EXPR |
11271 && TREE_CODE (arg1) == BIT_NOT_EXPR) | 11678 && TREE_CODE (arg1) == BIT_NOT_EXPR) |
11272 { | 11679 { |
11273 return fold_build1 (BIT_NOT_EXPR, type, | 11680 return fold_build1_loc (loc, BIT_NOT_EXPR, type, |
11274 build2 (BIT_IOR_EXPR, type, | 11681 build2 (BIT_IOR_EXPR, type, |
11275 fold_convert (type, | 11682 fold_convert_loc (loc, type, |
11276 TREE_OPERAND (arg0, 0)), | 11683 TREE_OPERAND (arg0, 0)), |
11277 fold_convert (type, | 11684 fold_convert_loc (loc, type, |
11278 TREE_OPERAND (arg1, 0)))); | 11685 TREE_OPERAND (arg1, 0)))); |
11279 } | 11686 } |
11280 | 11687 |
11281 /* If arg0 is derived from the address of an object or function, we may | 11688 /* If arg0 is derived from the address of an object or function, we may |
11282 be able to fold this expression using the object or function's | 11689 be able to fold this expression using the object or function's |
11283 alignment. */ | 11690 alignment. */ |
11284 if (POINTER_TYPE_P (TREE_TYPE (arg0)) && host_integerp (arg1, 1)) | 11691 if (POINTER_TYPE_P (TREE_TYPE (arg0)) && host_integerp (arg1, 1)) |
11285 { | 11692 { |
11286 unsigned HOST_WIDE_INT modulus, residue; | 11693 unsigned HOST_WIDE_INT modulus, residue; |
11287 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (arg1); | 11694 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (arg1); |
11288 | 11695 |
11289 modulus = get_pointer_modulus_and_residue (arg0, &residue); | 11696 modulus = get_pointer_modulus_and_residue (arg0, &residue, |
11697 integer_onep (arg1)); | |
11290 | 11698 |
11291 /* This works because modulus is a power of 2. If this weren't the | 11699 /* This works because modulus is a power of 2. If this weren't the |
11292 case, we'd have to replace it by its greatest power-of-2 | 11700 case, we'd have to replace it by its greatest power-of-2 |
11293 divisor: modulus & -modulus. */ | 11701 divisor: modulus & -modulus. */ |
11294 if (low < modulus) | 11702 if (low < modulus) |
11354 } | 11762 } |
11355 } | 11763 } |
11356 | 11764 |
11357 /* ((X << 16) & 0xff00) is (X, 0). */ | 11765 /* ((X << 16) & 0xff00) is (X, 0). */ |
11358 if ((mask & zerobits) == mask) | 11766 if ((mask & zerobits) == mask) |
11359 return omit_one_operand (type, build_int_cst (type, 0), arg0); | 11767 return omit_one_operand_loc (loc, type, |
11768 build_int_cst (type, 0), arg0); | |
11360 | 11769 |
11361 newmask = mask | zerobits; | 11770 newmask = mask | zerobits; |
11362 if (newmask != mask && (newmask & (newmask + 1)) == 0) | 11771 if (newmask != mask && (newmask & (newmask + 1)) == 0) |
11363 { | 11772 { |
11364 unsigned int prec; | 11773 unsigned int prec; |
11374 { | 11783 { |
11375 tree newmaskt; | 11784 tree newmaskt; |
11376 | 11785 |
11377 if (shift_type != TREE_TYPE (arg0)) | 11786 if (shift_type != TREE_TYPE (arg0)) |
11378 { | 11787 { |
11379 tem = fold_build2 (TREE_CODE (arg0), shift_type, | 11788 tem = fold_build2_loc (loc, TREE_CODE (arg0), shift_type, |
11380 fold_convert (shift_type, | 11789 fold_convert_loc (loc, shift_type, |
11381 TREE_OPERAND (arg0, 0)), | 11790 TREE_OPERAND (arg0, 0)), |
11382 TREE_OPERAND (arg0, 1)); | 11791 TREE_OPERAND (arg0, 1)); |
11383 tem = fold_convert (type, tem); | 11792 tem = fold_convert_loc (loc, type, tem); |
11384 } | 11793 } |
11385 else | 11794 else |
11386 tem = op0; | 11795 tem = op0; |
11387 newmaskt = build_int_cst_type (TREE_TYPE (op1), newmask); | 11796 newmaskt = build_int_cst_type (TREE_TYPE (op1), newmask); |
11388 if (!tree_int_cst_equal (newmaskt, arg1)) | 11797 if (!tree_int_cst_equal (newmaskt, arg1)) |
11389 return fold_build2 (BIT_AND_EXPR, type, tem, newmaskt); | 11798 return fold_build2_loc (loc, BIT_AND_EXPR, type, tem, newmaskt); |
11390 } | 11799 } |
11391 } | 11800 } |
11392 } | 11801 } |
11393 | 11802 |
11394 goto associate; | 11803 goto associate; |
11409 && ! HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg0))) | 11818 && ! HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg0))) |
11410 && operand_equal_p (arg0, arg1, 0)) | 11819 && operand_equal_p (arg0, arg1, 0)) |
11411 { | 11820 { |
11412 tree r = build_real (TREE_TYPE (arg0), dconst1); | 11821 tree r = build_real (TREE_TYPE (arg0), dconst1); |
11413 | 11822 |
11414 return omit_two_operands (type, r, arg0, arg1); | 11823 return omit_two_operands_loc (loc, type, r, arg0, arg1); |
11415 } | 11824 } |
11416 | 11825 |
11417 /* The complex version of the above A / A optimization. */ | 11826 /* The complex version of the above A / A optimization. */ |
11418 if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0)) | 11827 if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0)) |
11419 && operand_equal_p (arg0, arg1, 0)) | 11828 && operand_equal_p (arg0, arg1, 0)) |
11422 if (! HONOR_NANS (TYPE_MODE (elem_type)) | 11831 if (! HONOR_NANS (TYPE_MODE (elem_type)) |
11423 && ! HONOR_INFINITIES (TYPE_MODE (elem_type))) | 11832 && ! HONOR_INFINITIES (TYPE_MODE (elem_type))) |
11424 { | 11833 { |
11425 tree r = build_real (elem_type, dconst1); | 11834 tree r = build_real (elem_type, dconst1); |
11426 /* omit_two_operands will call fold_convert for us. */ | 11835 /* omit_two_operands will call fold_convert for us. */ |
11427 return omit_two_operands (type, r, arg0, arg1); | 11836 return omit_two_operands_loc (loc, type, r, arg0, arg1); |
11428 } | 11837 } |
11429 } | 11838 } |
11430 | 11839 |
11431 /* (-A) / (-B) -> A / B */ | 11840 /* (-A) / (-B) -> A / B */ |
11432 if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1)) | 11841 if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1)) |
11433 return fold_build2 (RDIV_EXPR, type, | 11842 return fold_build2_loc (loc, RDIV_EXPR, type, |
11434 TREE_OPERAND (arg0, 0), | 11843 TREE_OPERAND (arg0, 0), |
11435 negate_expr (arg1)); | 11844 negate_expr (arg1)); |
11436 if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0)) | 11845 if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0)) |
11437 return fold_build2 (RDIV_EXPR, type, | 11846 return fold_build2_loc (loc, RDIV_EXPR, type, |
11438 negate_expr (arg0), | 11847 negate_expr (arg0), |
11439 TREE_OPERAND (arg1, 0)); | 11848 TREE_OPERAND (arg1, 0)); |
11440 | 11849 |
11441 /* In IEEE floating point, x/1 is not equivalent to x for snans. */ | 11850 /* In IEEE floating point, x/1 is not equivalent to x for snans. */ |
11442 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) | 11851 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) |
11443 && real_onep (arg1)) | 11852 && real_onep (arg1)) |
11444 return non_lvalue (fold_convert (type, arg0)); | 11853 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
11445 | 11854 |
11446 /* In IEEE floating point, x/-1 is not equivalent to -x for snans. */ | 11855 /* In IEEE floating point, x/-1 is not equivalent to -x for snans. */ |
11447 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) | 11856 if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))) |
11448 && real_minus_onep (arg1)) | 11857 && real_minus_onep (arg1)) |
11449 return non_lvalue (fold_convert (type, negate_expr (arg0))); | 11858 return non_lvalue_loc (loc, fold_convert_loc (loc, type, |
11859 negate_expr (arg0))); | |
11450 | 11860 |
11451 /* If ARG1 is a constant, we can convert this to a multiply by the | 11861 /* If ARG1 is a constant, we can convert this to a multiply by the |
11452 reciprocal. This does not have the same rounding properties, | 11862 reciprocal. This does not have the same rounding properties, |
11453 so only do this if -freciprocal-math. We can actually | 11863 so only do this if -freciprocal-math. We can actually |
11454 always safely do it if ARG1 is a power of two, but it's hard to | 11864 always safely do it if ARG1 is a power of two, but it's hard to |
11456 if (TREE_CODE (arg1) == REAL_CST) | 11866 if (TREE_CODE (arg1) == REAL_CST) |
11457 { | 11867 { |
11458 if (flag_reciprocal_math | 11868 if (flag_reciprocal_math |
11459 && 0 != (tem = const_binop (code, build_real (type, dconst1), | 11869 && 0 != (tem = const_binop (code, build_real (type, dconst1), |
11460 arg1, 0))) | 11870 arg1, 0))) |
11461 return fold_build2 (MULT_EXPR, type, arg0, tem); | 11871 return fold_build2_loc (loc, MULT_EXPR, type, arg0, tem); |
11462 /* Find the reciprocal if optimizing and the result is exact. */ | 11872 /* Find the reciprocal if optimizing and the result is exact. */ |
11463 if (optimize) | 11873 if (optimize) |
11464 { | 11874 { |
11465 REAL_VALUE_TYPE r; | 11875 REAL_VALUE_TYPE r; |
11466 r = TREE_REAL_CST (arg1); | 11876 r = TREE_REAL_CST (arg1); |
11467 if (exact_real_inverse (TYPE_MODE(TREE_TYPE(arg0)), &r)) | 11877 if (exact_real_inverse (TYPE_MODE(TREE_TYPE(arg0)), &r)) |
11468 { | 11878 { |
11469 tem = build_real (type, r); | 11879 tem = build_real (type, r); |
11470 return fold_build2 (MULT_EXPR, type, | 11880 return fold_build2_loc (loc, MULT_EXPR, type, |
11471 fold_convert (type, arg0), tem); | 11881 fold_convert_loc (loc, type, arg0), tem); |
11472 } | 11882 } |
11473 } | 11883 } |
11474 } | 11884 } |
11475 /* Convert A/B/C to A/(B*C). */ | 11885 /* Convert A/B/C to A/(B*C). */ |
11476 if (flag_reciprocal_math | 11886 if (flag_reciprocal_math |
11477 && TREE_CODE (arg0) == RDIV_EXPR) | 11887 && TREE_CODE (arg0) == RDIV_EXPR) |
11478 return fold_build2 (RDIV_EXPR, type, TREE_OPERAND (arg0, 0), | 11888 return fold_build2_loc (loc, RDIV_EXPR, type, TREE_OPERAND (arg0, 0), |
11479 fold_build2 (MULT_EXPR, type, | 11889 fold_build2_loc (loc, MULT_EXPR, type, |
11480 TREE_OPERAND (arg0, 1), arg1)); | 11890 TREE_OPERAND (arg0, 1), arg1)); |
11481 | 11891 |
11482 /* Convert A/(B/C) to (A/B)*C. */ | 11892 /* Convert A/(B/C) to (A/B)*C. */ |
11483 if (flag_reciprocal_math | 11893 if (flag_reciprocal_math |
11484 && TREE_CODE (arg1) == RDIV_EXPR) | 11894 && TREE_CODE (arg1) == RDIV_EXPR) |
11485 return fold_build2 (MULT_EXPR, type, | 11895 return fold_build2_loc (loc, MULT_EXPR, type, |
11486 fold_build2 (RDIV_EXPR, type, arg0, | 11896 fold_build2_loc (loc, RDIV_EXPR, type, arg0, |
11487 TREE_OPERAND (arg1, 0)), | 11897 TREE_OPERAND (arg1, 0)), |
11488 TREE_OPERAND (arg1, 1)); | 11898 TREE_OPERAND (arg1, 1)); |
11489 | 11899 |
11490 /* Convert C1/(X*C2) into (C1/C2)/X. */ | 11900 /* Convert C1/(X*C2) into (C1/C2)/X. */ |
11491 if (flag_reciprocal_math | 11901 if (flag_reciprocal_math |
11494 && TREE_CODE (TREE_OPERAND (arg1, 1)) == REAL_CST) | 11904 && TREE_CODE (TREE_OPERAND (arg1, 1)) == REAL_CST) |
11495 { | 11905 { |
11496 tree tem = const_binop (RDIV_EXPR, arg0, | 11906 tree tem = const_binop (RDIV_EXPR, arg0, |
11497 TREE_OPERAND (arg1, 1), 0); | 11907 TREE_OPERAND (arg1, 1), 0); |
11498 if (tem) | 11908 if (tem) |
11499 return fold_build2 (RDIV_EXPR, type, tem, | 11909 return fold_build2_loc (loc, RDIV_EXPR, type, tem, |
11500 TREE_OPERAND (arg1, 0)); | 11910 TREE_OPERAND (arg1, 0)); |
11501 } | 11911 } |
11502 | 11912 |
11503 if (flag_unsafe_math_optimizations) | 11913 if (flag_unsafe_math_optimizations) |
11504 { | 11914 { |
11513 CALL_EXPR_ARG (arg1, 0), 0)) | 11923 CALL_EXPR_ARG (arg1, 0), 0)) |
11514 { | 11924 { |
11515 tree tanfn = mathfn_built_in (type, BUILT_IN_TAN); | 11925 tree tanfn = mathfn_built_in (type, BUILT_IN_TAN); |
11516 | 11926 |
11517 if (tanfn != NULL_TREE) | 11927 if (tanfn != NULL_TREE) |
11518 return build_call_expr (tanfn, 1, CALL_EXPR_ARG (arg0, 0)); | 11928 return build_call_expr_loc (loc, tanfn, 1, CALL_EXPR_ARG (arg0, 0)); |
11519 } | 11929 } |
11520 | 11930 |
11521 /* Optimize cos(x)/sin(x) as 1.0/tan(x). */ | 11931 /* Optimize cos(x)/sin(x) as 1.0/tan(x). */ |
11522 if (((fcode0 == BUILT_IN_COS && fcode1 == BUILT_IN_SIN) | 11932 if (((fcode0 == BUILT_IN_COS && fcode1 == BUILT_IN_SIN) |
11523 || (fcode0 == BUILT_IN_COSF && fcode1 == BUILT_IN_SINF) | 11933 || (fcode0 == BUILT_IN_COSF && fcode1 == BUILT_IN_SINF) |
11527 { | 11937 { |
11528 tree tanfn = mathfn_built_in (type, BUILT_IN_TAN); | 11938 tree tanfn = mathfn_built_in (type, BUILT_IN_TAN); |
11529 | 11939 |
11530 if (tanfn != NULL_TREE) | 11940 if (tanfn != NULL_TREE) |
11531 { | 11941 { |
11532 tree tmp = build_call_expr (tanfn, 1, CALL_EXPR_ARG (arg0, 0)); | 11942 tree tmp = build_call_expr_loc (loc, tanfn, 1, |
11533 return fold_build2 (RDIV_EXPR, type, | 11943 CALL_EXPR_ARG (arg0, 0)); |
11944 return fold_build2_loc (loc, RDIV_EXPR, type, | |
11534 build_real (type, dconst1), tmp); | 11945 build_real (type, dconst1), tmp); |
11535 } | 11946 } |
11536 } | 11947 } |
11537 | 11948 |
11538 /* Optimize sin(x)/tan(x) as cos(x) if we don't care about | 11949 /* Optimize sin(x)/tan(x) as cos(x) if we don't care about |
11549 && operand_equal_p (arg00, arg01, 0)) | 11960 && operand_equal_p (arg00, arg01, 0)) |
11550 { | 11961 { |
11551 tree cosfn = mathfn_built_in (type, BUILT_IN_COS); | 11962 tree cosfn = mathfn_built_in (type, BUILT_IN_COS); |
11552 | 11963 |
11553 if (cosfn != NULL_TREE) | 11964 if (cosfn != NULL_TREE) |
11554 return build_call_expr (cosfn, 1, arg00); | 11965 return build_call_expr_loc (loc, cosfn, 1, arg00); |
11555 } | 11966 } |
11556 } | 11967 } |
11557 | 11968 |
11558 /* Optimize tan(x)/sin(x) as 1.0/cos(x) if we don't care about | 11969 /* Optimize tan(x)/sin(x) as 1.0/cos(x) if we don't care about |
11559 NaNs or Infinities. */ | 11970 NaNs or Infinities. */ |
11570 { | 11981 { |
11571 tree cosfn = mathfn_built_in (type, BUILT_IN_COS); | 11982 tree cosfn = mathfn_built_in (type, BUILT_IN_COS); |
11572 | 11983 |
11573 if (cosfn != NULL_TREE) | 11984 if (cosfn != NULL_TREE) |
11574 { | 11985 { |
11575 tree tmp = build_call_expr (cosfn, 1, arg00); | 11986 tree tmp = build_call_expr_loc (loc, cosfn, 1, arg00); |
11576 return fold_build2 (RDIV_EXPR, type, | 11987 return fold_build2_loc (loc, RDIV_EXPR, type, |
11577 build_real (type, dconst1), | 11988 build_real (type, dconst1), |
11578 tmp); | 11989 tmp); |
11579 } | 11990 } |
11580 } | 11991 } |
11581 } | 11992 } |
11596 tree arg; | 12007 tree arg; |
11597 | 12008 |
11598 c = TREE_REAL_CST (arg01); | 12009 c = TREE_REAL_CST (arg01); |
11599 real_arithmetic (&c, MINUS_EXPR, &c, &dconst1); | 12010 real_arithmetic (&c, MINUS_EXPR, &c, &dconst1); |
11600 arg = build_real (type, c); | 12011 arg = build_real (type, c); |
11601 return build_call_expr (powfn, 2, arg1, arg); | 12012 return build_call_expr_loc (loc, powfn, 2, arg1, arg); |
11602 } | 12013 } |
11603 } | 12014 } |
11604 | 12015 |
11605 /* Optimize a/root(b/c) into a*root(c/b). */ | 12016 /* Optimize a/root(b/c) into a*root(c/b). */ |
11606 if (BUILTIN_ROOT_P (fcode1)) | 12017 if (BUILTIN_ROOT_P (fcode1)) |
11611 { | 12022 { |
11612 tree rootfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0); | 12023 tree rootfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0); |
11613 tree b = TREE_OPERAND (rootarg, 0); | 12024 tree b = TREE_OPERAND (rootarg, 0); |
11614 tree c = TREE_OPERAND (rootarg, 1); | 12025 tree c = TREE_OPERAND (rootarg, 1); |
11615 | 12026 |
11616 tree tmp = fold_build2 (RDIV_EXPR, type, c, b); | 12027 tree tmp = fold_build2_loc (loc, RDIV_EXPR, type, c, b); |
11617 | 12028 |
11618 tmp = build_call_expr (rootfn, 1, tmp); | 12029 tmp = build_call_expr_loc (loc, rootfn, 1, tmp); |
11619 return fold_build2 (MULT_EXPR, type, arg0, tmp); | 12030 return fold_build2_loc (loc, MULT_EXPR, type, arg0, tmp); |
11620 } | 12031 } |
11621 } | 12032 } |
11622 | 12033 |
11623 /* Optimize x/expN(y) into x*expN(-y). */ | 12034 /* Optimize x/expN(y) into x*expN(-y). */ |
11624 if (BUILTIN_EXPONENT_P (fcode1)) | 12035 if (BUILTIN_EXPONENT_P (fcode1)) |
11625 { | 12036 { |
11626 tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0); | 12037 tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0); |
11627 tree arg = negate_expr (CALL_EXPR_ARG (arg1, 0)); | 12038 tree arg = negate_expr (CALL_EXPR_ARG (arg1, 0)); |
11628 arg1 = build_call_expr (expfn, 1, fold_convert (type, arg)); | 12039 arg1 = build_call_expr_loc (loc, |
11629 return fold_build2 (MULT_EXPR, type, arg0, arg1); | 12040 expfn, 1, |
12041 fold_convert_loc (loc, type, arg)); | |
12042 return fold_build2_loc (loc, MULT_EXPR, type, arg0, arg1); | |
11630 } | 12043 } |
11631 | 12044 |
11632 /* Optimize x/pow(y,z) into x*pow(y,-z). */ | 12045 /* Optimize x/pow(y,z) into x*pow(y,-z). */ |
11633 if (fcode1 == BUILT_IN_POW | 12046 if (fcode1 == BUILT_IN_POW |
11634 || fcode1 == BUILT_IN_POWF | 12047 || fcode1 == BUILT_IN_POWF |
11635 || fcode1 == BUILT_IN_POWL) | 12048 || fcode1 == BUILT_IN_POWL) |
11636 { | 12049 { |
11637 tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0); | 12050 tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0); |
11638 tree arg10 = CALL_EXPR_ARG (arg1, 0); | 12051 tree arg10 = CALL_EXPR_ARG (arg1, 0); |
11639 tree arg11 = CALL_EXPR_ARG (arg1, 1); | 12052 tree arg11 = CALL_EXPR_ARG (arg1, 1); |
11640 tree neg11 = fold_convert (type, negate_expr (arg11)); | 12053 tree neg11 = fold_convert_loc (loc, type, |
11641 arg1 = build_call_expr (powfn, 2, arg10, neg11); | 12054 negate_expr (arg11)); |
11642 return fold_build2 (MULT_EXPR, type, arg0, arg1); | 12055 arg1 = build_call_expr_loc (loc, powfn, 2, arg10, neg11); |
12056 return fold_build2_loc (loc, MULT_EXPR, type, arg0, arg1); | |
11643 } | 12057 } |
11644 } | 12058 } |
11645 return NULL_TREE; | 12059 return NULL_TREE; |
11646 | 12060 |
11647 case TRUNC_DIV_EXPR: | 12061 case TRUNC_DIV_EXPR: |
11662 if (strict_overflow_p) | 12076 if (strict_overflow_p) |
11663 fold_overflow_warning (("assuming signed overflow does not " | 12077 fold_overflow_warning (("assuming signed overflow does not " |
11664 "occur when simplifying A / (B << N)"), | 12078 "occur when simplifying A / (B << N)"), |
11665 WARN_STRICT_OVERFLOW_MISC); | 12079 WARN_STRICT_OVERFLOW_MISC); |
11666 | 12080 |
11667 sh_cnt = fold_build2 (PLUS_EXPR, TREE_TYPE (sh_cnt), | 12081 sh_cnt = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (sh_cnt), |
11668 sh_cnt, build_int_cst (NULL_TREE, pow2)); | 12082 sh_cnt, build_int_cst (NULL_TREE, pow2)); |
11669 return fold_build2 (RSHIFT_EXPR, type, | 12083 return fold_build2_loc (loc, RSHIFT_EXPR, type, |
11670 fold_convert (type, arg0), sh_cnt); | 12084 fold_convert_loc (loc, type, arg0), sh_cnt); |
11671 } | 12085 } |
11672 } | 12086 } |
11673 | 12087 |
11674 /* For unsigned integral types, FLOOR_DIV_EXPR is the same as | 12088 /* For unsigned integral types, FLOOR_DIV_EXPR is the same as |
11675 TRUNC_DIV_EXPR. Rewrite into the latter in this case. */ | 12089 TRUNC_DIV_EXPR. Rewrite into the latter in this case. */ |
11676 if (INTEGRAL_TYPE_P (type) | 12090 if (INTEGRAL_TYPE_P (type) |
11677 && TYPE_UNSIGNED (type) | 12091 && TYPE_UNSIGNED (type) |
11678 && code == FLOOR_DIV_EXPR) | 12092 && code == FLOOR_DIV_EXPR) |
11679 return fold_build2 (TRUNC_DIV_EXPR, type, op0, op1); | 12093 return fold_build2_loc (loc, TRUNC_DIV_EXPR, type, op0, op1); |
11680 | 12094 |
11681 /* Fall thru */ | 12095 /* Fall thru */ |
11682 | 12096 |
11683 case ROUND_DIV_EXPR: | 12097 case ROUND_DIV_EXPR: |
11684 case CEIL_DIV_EXPR: | 12098 case CEIL_DIV_EXPR: |
11685 case EXACT_DIV_EXPR: | 12099 case EXACT_DIV_EXPR: |
11686 if (integer_onep (arg1)) | 12100 if (integer_onep (arg1)) |
11687 return non_lvalue (fold_convert (type, arg0)); | 12101 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
11688 if (integer_zerop (arg1)) | 12102 if (integer_zerop (arg1)) |
11689 return NULL_TREE; | 12103 return NULL_TREE; |
11690 /* X / -1 is -X. */ | 12104 /* X / -1 is -X. */ |
11691 if (!TYPE_UNSIGNED (type) | 12105 if (!TYPE_UNSIGNED (type) |
11692 && TREE_CODE (arg1) == INTEGER_CST | 12106 && TREE_CODE (arg1) == INTEGER_CST |
11693 && TREE_INT_CST_LOW (arg1) == (unsigned HOST_WIDE_INT) -1 | 12107 && TREE_INT_CST_LOW (arg1) == (unsigned HOST_WIDE_INT) -1 |
11694 && TREE_INT_CST_HIGH (arg1) == -1) | 12108 && TREE_INT_CST_HIGH (arg1) == -1) |
11695 return fold_convert (type, negate_expr (arg0)); | 12109 return fold_convert_loc (loc, type, negate_expr (arg0)); |
11696 | 12110 |
11697 /* Convert -A / -B to A / B when the type is signed and overflow is | 12111 /* Convert -A / -B to A / B when the type is signed and overflow is |
11698 undefined. */ | 12112 undefined. */ |
11699 if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type)) | 12113 if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type)) |
11700 && TREE_CODE (arg0) == NEGATE_EXPR | 12114 && TREE_CODE (arg0) == NEGATE_EXPR |
11703 if (INTEGRAL_TYPE_P (type)) | 12117 if (INTEGRAL_TYPE_P (type)) |
11704 fold_overflow_warning (("assuming signed overflow does not occur " | 12118 fold_overflow_warning (("assuming signed overflow does not occur " |
11705 "when distributing negation across " | 12119 "when distributing negation across " |
11706 "division"), | 12120 "division"), |
11707 WARN_STRICT_OVERFLOW_MISC); | 12121 WARN_STRICT_OVERFLOW_MISC); |
11708 return fold_build2 (code, type, | 12122 return fold_build2_loc (loc, code, type, |
11709 fold_convert (type, TREE_OPERAND (arg0, 0)), | 12123 fold_convert_loc (loc, type, |
11710 fold_convert (type, negate_expr (arg1))); | 12124 TREE_OPERAND (arg0, 0)), |
12125 fold_convert_loc (loc, type, | |
12126 negate_expr (arg1))); | |
11711 } | 12127 } |
11712 if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type)) | 12128 if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type)) |
11713 && TREE_CODE (arg1) == NEGATE_EXPR | 12129 && TREE_CODE (arg1) == NEGATE_EXPR |
11714 && negate_expr_p (arg0)) | 12130 && negate_expr_p (arg0)) |
11715 { | 12131 { |
11716 if (INTEGRAL_TYPE_P (type)) | 12132 if (INTEGRAL_TYPE_P (type)) |
11717 fold_overflow_warning (("assuming signed overflow does not occur " | 12133 fold_overflow_warning (("assuming signed overflow does not occur " |
11718 "when distributing negation across " | 12134 "when distributing negation across " |
11719 "division"), | 12135 "division"), |
11720 WARN_STRICT_OVERFLOW_MISC); | 12136 WARN_STRICT_OVERFLOW_MISC); |
11721 return fold_build2 (code, type, | 12137 return fold_build2_loc (loc, code, type, |
11722 fold_convert (type, negate_expr (arg0)), | 12138 fold_convert_loc (loc, type, |
11723 fold_convert (type, TREE_OPERAND (arg1, 0))); | 12139 negate_expr (arg0)), |
12140 fold_convert_loc (loc, type, | |
12141 TREE_OPERAND (arg1, 0))); | |
11724 } | 12142 } |
11725 | 12143 |
11726 /* If arg0 is a multiple of arg1, then rewrite to the fastest div | 12144 /* If arg0 is a multiple of arg1, then rewrite to the fastest div |
11727 operation, EXACT_DIV_EXPR. | 12145 operation, EXACT_DIV_EXPR. |
11728 | 12146 |
11729 Note that only CEIL_DIV_EXPR and FLOOR_DIV_EXPR are rewritten now. | 12147 Note that only CEIL_DIV_EXPR and FLOOR_DIV_EXPR are rewritten now. |
11730 At one time others generated faster code, it's not clear if they do | 12148 At one time others generated faster code, it's not clear if they do |
11731 after the last round to changes to the DIV code in expmed.c. */ | 12149 after the last round to changes to the DIV code in expmed.c. */ |
11732 if ((code == CEIL_DIV_EXPR || code == FLOOR_DIV_EXPR) | 12150 if ((code == CEIL_DIV_EXPR || code == FLOOR_DIV_EXPR) |
11733 && multiple_of_p (type, arg0, arg1)) | 12151 && multiple_of_p (type, arg0, arg1)) |
11734 return fold_build2 (EXACT_DIV_EXPR, type, arg0, arg1); | 12152 return fold_build2_loc (loc, EXACT_DIV_EXPR, type, arg0, arg1); |
11735 | 12153 |
11736 strict_overflow_p = false; | 12154 strict_overflow_p = false; |
11737 if (TREE_CODE (arg1) == INTEGER_CST | 12155 if (TREE_CODE (arg1) == INTEGER_CST |
11738 && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, | 12156 && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, |
11739 &strict_overflow_p))) | 12157 &strict_overflow_p))) |
11740 { | 12158 { |
11741 if (strict_overflow_p) | 12159 if (strict_overflow_p) |
11742 fold_overflow_warning (("assuming signed overflow does not occur " | 12160 fold_overflow_warning (("assuming signed overflow does not occur " |
11743 "when simplifying division"), | 12161 "when simplifying division"), |
11744 WARN_STRICT_OVERFLOW_MISC); | 12162 WARN_STRICT_OVERFLOW_MISC); |
11745 return fold_convert (type, tem); | 12163 return fold_convert_loc (loc, type, tem); |
11746 } | 12164 } |
11747 | 12165 |
11748 return NULL_TREE; | 12166 return NULL_TREE; |
11749 | 12167 |
11750 case CEIL_MOD_EXPR: | 12168 case CEIL_MOD_EXPR: |
11752 case ROUND_MOD_EXPR: | 12170 case ROUND_MOD_EXPR: |
11753 case TRUNC_MOD_EXPR: | 12171 case TRUNC_MOD_EXPR: |
11754 /* X % 1 is always zero, but be sure to preserve any side | 12172 /* X % 1 is always zero, but be sure to preserve any side |
11755 effects in X. */ | 12173 effects in X. */ |
11756 if (integer_onep (arg1)) | 12174 if (integer_onep (arg1)) |
11757 return omit_one_operand (type, integer_zero_node, arg0); | 12175 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
11758 | 12176 |
11759 /* X % 0, return X % 0 unchanged so that we can get the | 12177 /* X % 0, return X % 0 unchanged so that we can get the |
11760 proper warnings and errors. */ | 12178 proper warnings and errors. */ |
11761 if (integer_zerop (arg1)) | 12179 if (integer_zerop (arg1)) |
11762 return NULL_TREE; | 12180 return NULL_TREE; |
11763 | 12181 |
11764 /* 0 % X is always zero, but be sure to preserve any side | 12182 /* 0 % X is always zero, but be sure to preserve any side |
11765 effects in X. Place this after checking for X == 0. */ | 12183 effects in X. Place this after checking for X == 0. */ |
11766 if (integer_zerop (arg0)) | 12184 if (integer_zerop (arg0)) |
11767 return omit_one_operand (type, integer_zero_node, arg1); | 12185 return omit_one_operand_loc (loc, type, integer_zero_node, arg1); |
11768 | 12186 |
11769 /* X % -1 is zero. */ | 12187 /* X % -1 is zero. */ |
11770 if (!TYPE_UNSIGNED (type) | 12188 if (!TYPE_UNSIGNED (type) |
11771 && TREE_CODE (arg1) == INTEGER_CST | 12189 && TREE_CODE (arg1) == INTEGER_CST |
11772 && TREE_INT_CST_LOW (arg1) == (unsigned HOST_WIDE_INT) -1 | 12190 && TREE_INT_CST_LOW (arg1) == (unsigned HOST_WIDE_INT) -1 |
11773 && TREE_INT_CST_HIGH (arg1) == -1) | 12191 && TREE_INT_CST_HIGH (arg1) == -1) |
11774 return omit_one_operand (type, integer_zero_node, arg0); | 12192 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
11775 | 12193 |
11776 /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR, | 12194 /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR, |
11777 i.e. "X % C" into "X & (C - 1)", if X and C are positive. */ | 12195 i.e. "X % C" into "X & (C - 1)", if X and C are positive. */ |
11778 strict_overflow_p = false; | 12196 strict_overflow_p = false; |
11779 if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR) | 12197 if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR) |
11786 if (TREE_CODE (arg1) == LSHIFT_EXPR) | 12204 if (TREE_CODE (arg1) == LSHIFT_EXPR) |
11787 c = TREE_OPERAND (arg1, 0); | 12205 c = TREE_OPERAND (arg1, 0); |
11788 | 12206 |
11789 if (integer_pow2p (c) && tree_int_cst_sgn (c) > 0) | 12207 if (integer_pow2p (c) && tree_int_cst_sgn (c) > 0) |
11790 { | 12208 { |
11791 tree mask = fold_build2 (MINUS_EXPR, TREE_TYPE (arg1), arg1, | 12209 tree mask = fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (arg1), arg1, |
11792 build_int_cst (TREE_TYPE (arg1), 1)); | 12210 build_int_cst (TREE_TYPE (arg1), 1)); |
11793 if (strict_overflow_p) | 12211 if (strict_overflow_p) |
11794 fold_overflow_warning (("assuming signed overflow does not " | 12212 fold_overflow_warning (("assuming signed overflow does not " |
11795 "occur when simplifying " | 12213 "occur when simplifying " |
11796 "X % (power of two)"), | 12214 "X % (power of two)"), |
11797 WARN_STRICT_OVERFLOW_MISC); | 12215 WARN_STRICT_OVERFLOW_MISC); |
11798 return fold_build2 (BIT_AND_EXPR, type, | 12216 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
11799 fold_convert (type, arg0), | 12217 fold_convert_loc (loc, type, arg0), |
11800 fold_convert (type, mask)); | 12218 fold_convert_loc (loc, type, mask)); |
11801 } | 12219 } |
11802 } | 12220 } |
11803 | 12221 |
11804 /* X % -C is the same as X % C. */ | 12222 /* X % -C is the same as X % C. */ |
11805 if (code == TRUNC_MOD_EXPR | 12223 if (code == TRUNC_MOD_EXPR |
11808 && !TREE_OVERFLOW (arg1) | 12226 && !TREE_OVERFLOW (arg1) |
11809 && TREE_INT_CST_HIGH (arg1) < 0 | 12227 && TREE_INT_CST_HIGH (arg1) < 0 |
11810 && !TYPE_OVERFLOW_TRAPS (type) | 12228 && !TYPE_OVERFLOW_TRAPS (type) |
11811 /* Avoid this transformation if C is INT_MIN, i.e. C == -C. */ | 12229 /* Avoid this transformation if C is INT_MIN, i.e. C == -C. */ |
11812 && !sign_bit_p (arg1, arg1)) | 12230 && !sign_bit_p (arg1, arg1)) |
11813 return fold_build2 (code, type, fold_convert (type, arg0), | 12231 return fold_build2_loc (loc, code, type, |
11814 fold_convert (type, negate_expr (arg1))); | 12232 fold_convert_loc (loc, type, arg0), |
12233 fold_convert_loc (loc, type, | |
12234 negate_expr (arg1))); | |
11815 | 12235 |
11816 /* X % -Y is the same as X % Y. */ | 12236 /* X % -Y is the same as X % Y. */ |
11817 if (code == TRUNC_MOD_EXPR | 12237 if (code == TRUNC_MOD_EXPR |
11818 && !TYPE_UNSIGNED (type) | 12238 && !TYPE_UNSIGNED (type) |
11819 && TREE_CODE (arg1) == NEGATE_EXPR | 12239 && TREE_CODE (arg1) == NEGATE_EXPR |
11820 && !TYPE_OVERFLOW_TRAPS (type)) | 12240 && !TYPE_OVERFLOW_TRAPS (type)) |
11821 return fold_build2 (code, type, fold_convert (type, arg0), | 12241 return fold_build2_loc (loc, code, type, fold_convert_loc (loc, type, arg0), |
11822 fold_convert (type, TREE_OPERAND (arg1, 0))); | 12242 fold_convert_loc (loc, type, |
12243 TREE_OPERAND (arg1, 0))); | |
11823 | 12244 |
11824 if (TREE_CODE (arg1) == INTEGER_CST | 12245 if (TREE_CODE (arg1) == INTEGER_CST |
11825 && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, | 12246 && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, |
11826 &strict_overflow_p))) | 12247 &strict_overflow_p))) |
11827 { | 12248 { |
11828 if (strict_overflow_p) | 12249 if (strict_overflow_p) |
11829 fold_overflow_warning (("assuming signed overflow does not occur " | 12250 fold_overflow_warning (("assuming signed overflow does not occur " |
11830 "when simplifying modulus"), | 12251 "when simplifying modulus"), |
11831 WARN_STRICT_OVERFLOW_MISC); | 12252 WARN_STRICT_OVERFLOW_MISC); |
11832 return fold_convert (type, tem); | 12253 return fold_convert_loc (loc, type, tem); |
11833 } | 12254 } |
11834 | 12255 |
11835 return NULL_TREE; | 12256 return NULL_TREE; |
11836 | 12257 |
11837 case LROTATE_EXPR: | 12258 case LROTATE_EXPR: |
11838 case RROTATE_EXPR: | 12259 case RROTATE_EXPR: |
11839 if (integer_all_onesp (arg0)) | 12260 if (integer_all_onesp (arg0)) |
11840 return omit_one_operand (type, arg0, arg1); | 12261 return omit_one_operand_loc (loc, type, arg0, arg1); |
11841 goto shift; | 12262 goto shift; |
11842 | 12263 |
11843 case RSHIFT_EXPR: | 12264 case RSHIFT_EXPR: |
11844 /* Optimize -1 >> x for arithmetic right shifts. */ | 12265 /* Optimize -1 >> x for arithmetic right shifts. */ |
11845 if (integer_all_onesp (arg0) && !TYPE_UNSIGNED (type) | 12266 if (integer_all_onesp (arg0) && !TYPE_UNSIGNED (type) |
11846 && tree_expr_nonnegative_p (arg1)) | 12267 && tree_expr_nonnegative_p (arg1)) |
11847 return omit_one_operand (type, arg0, arg1); | 12268 return omit_one_operand_loc (loc, type, arg0, arg1); |
11848 /* ... fall through ... */ | 12269 /* ... fall through ... */ |
11849 | 12270 |
11850 case LSHIFT_EXPR: | 12271 case LSHIFT_EXPR: |
11851 shift: | 12272 shift: |
11852 if (integer_zerop (arg1)) | 12273 if (integer_zerop (arg1)) |
11853 return non_lvalue (fold_convert (type, arg0)); | 12274 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
11854 if (integer_zerop (arg0)) | 12275 if (integer_zerop (arg0)) |
11855 return omit_one_operand (type, arg0, arg1); | 12276 return omit_one_operand_loc (loc, type, arg0, arg1); |
11856 | 12277 |
11857 /* Since negative shift count is not well-defined, | 12278 /* Since negative shift count is not well-defined, |
11858 don't try to compute it in the compiler. */ | 12279 don't try to compute it in the compiler. */ |
11859 if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1) < 0) | 12280 if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1) < 0) |
11860 return NULL_TREE; | 12281 return NULL_TREE; |
11873 if (low >= TYPE_PRECISION (type)) | 12294 if (low >= TYPE_PRECISION (type)) |
11874 { | 12295 { |
11875 if (code == LROTATE_EXPR || code == RROTATE_EXPR) | 12296 if (code == LROTATE_EXPR || code == RROTATE_EXPR) |
11876 low = low % TYPE_PRECISION (type); | 12297 low = low % TYPE_PRECISION (type); |
11877 else if (TYPE_UNSIGNED (type) || code == LSHIFT_EXPR) | 12298 else if (TYPE_UNSIGNED (type) || code == LSHIFT_EXPR) |
11878 return omit_one_operand (type, build_int_cst (type, 0), | 12299 return omit_one_operand_loc (loc, type, build_int_cst (type, 0), |
11879 TREE_OPERAND (arg0, 0)); | 12300 TREE_OPERAND (arg0, 0)); |
11880 else | 12301 else |
11881 low = TYPE_PRECISION (type) - 1; | 12302 low = TYPE_PRECISION (type) - 1; |
11882 } | 12303 } |
11883 | 12304 |
11884 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), | 12305 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), |
11885 build_int_cst (type, low)); | 12306 build_int_cst (type, low)); |
11886 } | 12307 } |
11887 | 12308 |
11888 /* Transform (x >> c) << c into x & (-1<<c), or transform (x << c) >> c | 12309 /* Transform (x >> c) << c into x & (-1<<c), or transform (x << c) >> c |
11889 into x & ((unsigned)-1 >> c) for unsigned types. */ | 12310 into x & ((unsigned)-1 >> c) for unsigned types. */ |
11900 tree lshift; | 12321 tree lshift; |
11901 tree arg00; | 12322 tree arg00; |
11902 | 12323 |
11903 if (low0 == low1) | 12324 if (low0 == low1) |
11904 { | 12325 { |
11905 arg00 = fold_convert (type, TREE_OPERAND (arg0, 0)); | 12326 arg00 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); |
11906 | 12327 |
11907 lshift = build_int_cst (type, -1); | 12328 lshift = build_int_cst (type, -1); |
11908 lshift = int_const_binop (code, lshift, arg1, 0); | 12329 lshift = int_const_binop (code, lshift, arg1, 0); |
11909 | 12330 |
11910 return fold_build2 (BIT_AND_EXPR, type, arg00, lshift); | 12331 return fold_build2_loc (loc, BIT_AND_EXPR, type, arg00, lshift); |
11911 } | 12332 } |
11912 } | 12333 } |
11913 | 12334 |
11914 /* Rewrite an LROTATE_EXPR by a constant into an | 12335 /* Rewrite an LROTATE_EXPR by a constant into an |
11915 RROTATE_EXPR by a new constant. */ | 12336 RROTATE_EXPR by a new constant. */ |
11916 if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST) | 12337 if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST) |
11917 { | 12338 { |
11918 tree tem = build_int_cst (TREE_TYPE (arg1), | 12339 tree tem = build_int_cst (TREE_TYPE (arg1), |
11919 TYPE_PRECISION (type)); | 12340 TYPE_PRECISION (type)); |
11920 tem = const_binop (MINUS_EXPR, tem, arg1, 0); | 12341 tem = const_binop (MINUS_EXPR, tem, arg1, 0); |
11921 return fold_build2 (RROTATE_EXPR, type, op0, tem); | 12342 return fold_build2_loc (loc, RROTATE_EXPR, type, op0, tem); |
11922 } | 12343 } |
11923 | 12344 |
11924 /* If we have a rotate of a bit operation with the rotate count and | 12345 /* If we have a rotate of a bit operation with the rotate count and |
11925 the second operand of the bit operation both constant, | 12346 the second operand of the bit operation both constant, |
11926 permute the two operations. */ | 12347 permute the two operations. */ |
11927 if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST | 12348 if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST |
11928 && (TREE_CODE (arg0) == BIT_AND_EXPR | 12349 && (TREE_CODE (arg0) == BIT_AND_EXPR |
11929 || TREE_CODE (arg0) == BIT_IOR_EXPR | 12350 || TREE_CODE (arg0) == BIT_IOR_EXPR |
11930 || TREE_CODE (arg0) == BIT_XOR_EXPR) | 12351 || TREE_CODE (arg0) == BIT_XOR_EXPR) |
11931 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) | 12352 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) |
11932 return fold_build2 (TREE_CODE (arg0), type, | 12353 return fold_build2_loc (loc, TREE_CODE (arg0), type, |
11933 fold_build2 (code, type, | 12354 fold_build2_loc (loc, code, type, |
11934 TREE_OPERAND (arg0, 0), arg1), | 12355 TREE_OPERAND (arg0, 0), arg1), |
11935 fold_build2 (code, type, | 12356 fold_build2_loc (loc, code, type, |
11936 TREE_OPERAND (arg0, 1), arg1)); | 12357 TREE_OPERAND (arg0, 1), arg1)); |
11937 | 12358 |
11938 /* Two consecutive rotates adding up to the precision of the | 12359 /* Two consecutive rotates adding up to the precision of the |
11939 type can be ignored. */ | 12360 type can be ignored. */ |
11940 if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST | 12361 if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST |
11953 if ((code == LSHIFT_EXPR || code == RSHIFT_EXPR) | 12374 if ((code == LSHIFT_EXPR || code == RSHIFT_EXPR) |
11954 && TREE_CODE (arg0) == BIT_AND_EXPR | 12375 && TREE_CODE (arg0) == BIT_AND_EXPR |
11955 && TREE_CODE (arg1) == INTEGER_CST | 12376 && TREE_CODE (arg1) == INTEGER_CST |
11956 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) | 12377 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) |
11957 { | 12378 { |
11958 tree mask = fold_build2 (code, type, | 12379 tree mask = fold_build2_loc (loc, code, type, |
11959 fold_convert (type, TREE_OPERAND (arg0, 1)), | 12380 fold_convert_loc (loc, type, |
12381 TREE_OPERAND (arg0, 1)), | |
11960 arg1); | 12382 arg1); |
11961 tree shift = fold_build2 (code, type, | 12383 tree shift = fold_build2_loc (loc, code, type, |
11962 fold_convert (type, TREE_OPERAND (arg0, 0)), | 12384 fold_convert_loc (loc, type, |
12385 TREE_OPERAND (arg0, 0)), | |
11963 arg1); | 12386 arg1); |
11964 tem = fold_binary (BIT_AND_EXPR, type, shift, mask); | 12387 tem = fold_binary_loc (loc, BIT_AND_EXPR, type, shift, mask); |
11965 if (tem) | 12388 if (tem) |
11966 return tem; | 12389 return tem; |
11967 } | 12390 } |
11968 | 12391 |
11969 return NULL_TREE; | 12392 return NULL_TREE; |
11970 | 12393 |
11971 case MIN_EXPR: | 12394 case MIN_EXPR: |
11972 if (operand_equal_p (arg0, arg1, 0)) | 12395 if (operand_equal_p (arg0, arg1, 0)) |
11973 return omit_one_operand (type, arg0, arg1); | 12396 return omit_one_operand_loc (loc, type, arg0, arg1); |
11974 if (INTEGRAL_TYPE_P (type) | 12397 if (INTEGRAL_TYPE_P (type) |
11975 && operand_equal_p (arg1, TYPE_MIN_VALUE (type), OEP_ONLY_CONST)) | 12398 && operand_equal_p (arg1, TYPE_MIN_VALUE (type), OEP_ONLY_CONST)) |
11976 return omit_one_operand (type, arg1, arg0); | 12399 return omit_one_operand_loc (loc, type, arg1, arg0); |
11977 tem = fold_minmax (MIN_EXPR, type, arg0, arg1); | 12400 tem = fold_minmax (loc, MIN_EXPR, type, arg0, arg1); |
11978 if (tem) | 12401 if (tem) |
11979 return tem; | 12402 return tem; |
11980 goto associate; | 12403 goto associate; |
11981 | 12404 |
11982 case MAX_EXPR: | 12405 case MAX_EXPR: |
11983 if (operand_equal_p (arg0, arg1, 0)) | 12406 if (operand_equal_p (arg0, arg1, 0)) |
11984 return omit_one_operand (type, arg0, arg1); | 12407 return omit_one_operand_loc (loc, type, arg0, arg1); |
11985 if (INTEGRAL_TYPE_P (type) | 12408 if (INTEGRAL_TYPE_P (type) |
11986 && TYPE_MAX_VALUE (type) | 12409 && TYPE_MAX_VALUE (type) |
11987 && operand_equal_p (arg1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST)) | 12410 && operand_equal_p (arg1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST)) |
11988 return omit_one_operand (type, arg1, arg0); | 12411 return omit_one_operand_loc (loc, type, arg1, arg0); |
11989 tem = fold_minmax (MAX_EXPR, type, arg0, arg1); | 12412 tem = fold_minmax (loc, MAX_EXPR, type, arg0, arg1); |
11990 if (tem) | 12413 if (tem) |
11991 return tem; | 12414 return tem; |
11992 goto associate; | 12415 goto associate; |
11993 | 12416 |
11994 case TRUTH_ANDIF_EXPR: | 12417 case TRUTH_ANDIF_EXPR: |
11995 /* Note that the operands of this must be ints | 12418 /* Note that the operands of this must be ints |
11996 and their values must be 0 or 1. | 12419 and their values must be 0 or 1. |
11997 ("true" is a fixed value perhaps depending on the language.) */ | 12420 ("true" is a fixed value perhaps depending on the language.) */ |
11998 /* If first arg is constant zero, return it. */ | 12421 /* If first arg is constant zero, return it. */ |
11999 if (integer_zerop (arg0)) | 12422 if (integer_zerop (arg0)) |
12000 return fold_convert (type, arg0); | 12423 return fold_convert_loc (loc, type, arg0); |
12001 case TRUTH_AND_EXPR: | 12424 case TRUTH_AND_EXPR: |
12002 /* If either arg is constant true, drop it. */ | 12425 /* If either arg is constant true, drop it. */ |
12003 if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0)) | 12426 if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0)) |
12004 return non_lvalue (fold_convert (type, arg1)); | 12427 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1)); |
12005 if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1) | 12428 if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1) |
12006 /* Preserve sequence points. */ | 12429 /* Preserve sequence points. */ |
12007 && (code != TRUTH_ANDIF_EXPR || ! TREE_SIDE_EFFECTS (arg0))) | 12430 && (code != TRUTH_ANDIF_EXPR || ! TREE_SIDE_EFFECTS (arg0))) |
12008 return non_lvalue (fold_convert (type, arg0)); | 12431 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
12009 /* If second arg is constant zero, result is zero, but first arg | 12432 /* If second arg is constant zero, result is zero, but first arg |
12010 must be evaluated. */ | 12433 must be evaluated. */ |
12011 if (integer_zerop (arg1)) | 12434 if (integer_zerop (arg1)) |
12012 return omit_one_operand (type, arg1, arg0); | 12435 return omit_one_operand_loc (loc, type, arg1, arg0); |
12013 /* Likewise for first arg, but note that only the TRUTH_AND_EXPR | 12436 /* Likewise for first arg, but note that only the TRUTH_AND_EXPR |
12014 case will be handled here. */ | 12437 case will be handled here. */ |
12015 if (integer_zerop (arg0)) | 12438 if (integer_zerop (arg0)) |
12016 return omit_one_operand (type, arg0, arg1); | 12439 return omit_one_operand_loc (loc, type, arg0, arg1); |
12017 | 12440 |
12018 /* !X && X is always false. */ | 12441 /* !X && X is always false. */ |
12019 if (TREE_CODE (arg0) == TRUTH_NOT_EXPR | 12442 if (TREE_CODE (arg0) == TRUTH_NOT_EXPR |
12020 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 12443 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
12021 return omit_one_operand (type, integer_zero_node, arg1); | 12444 return omit_one_operand_loc (loc, type, integer_zero_node, arg1); |
12022 /* X && !X is always false. */ | 12445 /* X && !X is always false. */ |
12023 if (TREE_CODE (arg1) == TRUTH_NOT_EXPR | 12446 if (TREE_CODE (arg1) == TRUTH_NOT_EXPR |
12024 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 12447 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
12025 return omit_one_operand (type, integer_zero_node, arg0); | 12448 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
12026 | 12449 |
12027 /* A < X && A + 1 > Y ==> A < X && A >= Y. Normally A + 1 > Y | 12450 /* A < X && A + 1 > Y ==> A < X && A >= Y. Normally A + 1 > Y |
12028 means A >= Y && A != MAX, but in this case we know that | 12451 means A >= Y && A != MAX, but in this case we know that |
12029 A < X <= MAX. */ | 12452 A < X <= MAX. */ |
12030 | 12453 |
12031 if (!TREE_SIDE_EFFECTS (arg0) | 12454 if (!TREE_SIDE_EFFECTS (arg0) |
12032 && !TREE_SIDE_EFFECTS (arg1)) | 12455 && !TREE_SIDE_EFFECTS (arg1)) |
12033 { | 12456 { |
12034 tem = fold_to_nonsharp_ineq_using_bound (arg0, arg1); | 12457 tem = fold_to_nonsharp_ineq_using_bound (loc, arg0, arg1); |
12035 if (tem && !operand_equal_p (tem, arg0, 0)) | 12458 if (tem && !operand_equal_p (tem, arg0, 0)) |
12036 return fold_build2 (code, type, tem, arg1); | 12459 return fold_build2_loc (loc, code, type, tem, arg1); |
12037 | 12460 |
12038 tem = fold_to_nonsharp_ineq_using_bound (arg1, arg0); | 12461 tem = fold_to_nonsharp_ineq_using_bound (loc, arg1, arg0); |
12039 if (tem && !operand_equal_p (tem, arg1, 0)) | 12462 if (tem && !operand_equal_p (tem, arg1, 0)) |
12040 return fold_build2 (code, type, arg0, tem); | 12463 return fold_build2_loc (loc, code, type, arg0, tem); |
12041 } | 12464 } |
12042 | 12465 |
12043 truth_andor: | 12466 truth_andor: |
12044 /* We only do these simplifications if we are optimizing. */ | 12467 /* We only do these simplifications if we are optimizing. */ |
12045 if (!optimize) | 12468 if (!optimize) |
12066 || TREE_CODE (arg0) == TRUTH_AND_EXPR) | 12489 || TREE_CODE (arg0) == TRUTH_AND_EXPR) |
12067 && (code == TRUTH_AND_EXPR | 12490 && (code == TRUTH_AND_EXPR |
12068 || code == TRUTH_OR_EXPR)); | 12491 || code == TRUTH_OR_EXPR)); |
12069 | 12492 |
12070 if (operand_equal_p (a00, a10, 0)) | 12493 if (operand_equal_p (a00, a10, 0)) |
12071 return fold_build2 (TREE_CODE (arg0), type, a00, | 12494 return fold_build2_loc (loc, TREE_CODE (arg0), type, a00, |
12072 fold_build2 (code, type, a01, a11)); | 12495 fold_build2_loc (loc, code, type, a01, a11)); |
12073 else if (commutative && operand_equal_p (a00, a11, 0)) | 12496 else if (commutative && operand_equal_p (a00, a11, 0)) |
12074 return fold_build2 (TREE_CODE (arg0), type, a00, | 12497 return fold_build2_loc (loc, TREE_CODE (arg0), type, a00, |
12075 fold_build2 (code, type, a01, a10)); | 12498 fold_build2_loc (loc, code, type, a01, a10)); |
12076 else if (commutative && operand_equal_p (a01, a10, 0)) | 12499 else if (commutative && operand_equal_p (a01, a10, 0)) |
12077 return fold_build2 (TREE_CODE (arg0), type, a01, | 12500 return fold_build2_loc (loc, TREE_CODE (arg0), type, a01, |
12078 fold_build2 (code, type, a00, a11)); | 12501 fold_build2_loc (loc, code, type, a00, a11)); |
12079 | 12502 |
12080 /* This case if tricky because we must either have commutative | 12503 /* This case if tricky because we must either have commutative |
12081 operators or else A10 must not have side-effects. */ | 12504 operators or else A10 must not have side-effects. */ |
12082 | 12505 |
12083 else if ((commutative || ! TREE_SIDE_EFFECTS (a10)) | 12506 else if ((commutative || ! TREE_SIDE_EFFECTS (a10)) |
12084 && operand_equal_p (a01, a11, 0)) | 12507 && operand_equal_p (a01, a11, 0)) |
12085 return fold_build2 (TREE_CODE (arg0), type, | 12508 return fold_build2_loc (loc, TREE_CODE (arg0), type, |
12086 fold_build2 (code, type, a00, a10), | 12509 fold_build2_loc (loc, code, type, a00, a10), |
12087 a01); | 12510 a01); |
12088 } | 12511 } |
12089 | 12512 |
12090 /* See if we can build a range comparison. */ | 12513 /* See if we can build a range comparison. */ |
12091 if (0 != (tem = fold_range_test (code, type, op0, op1))) | 12514 if (0 != (tem = fold_range_test (loc, code, type, op0, op1))) |
12092 return tem; | 12515 return tem; |
12093 | 12516 |
12094 /* Check for the possibility of merging component references. If our | 12517 /* Check for the possibility of merging component references. If our |
12095 lhs is another similar operation, try to merge its rhs with our | 12518 lhs is another similar operation, try to merge its rhs with our |
12096 rhs. Then try to merge our lhs and rhs. */ | 12519 rhs. Then try to merge our lhs and rhs. */ |
12097 if (TREE_CODE (arg0) == code | 12520 if (TREE_CODE (arg0) == code |
12098 && 0 != (tem = fold_truthop (code, type, | 12521 && 0 != (tem = fold_truthop (loc, code, type, |
12099 TREE_OPERAND (arg0, 1), arg1))) | 12522 TREE_OPERAND (arg0, 1), arg1))) |
12100 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), tem); | 12523 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem); |
12101 | 12524 |
12102 if ((tem = fold_truthop (code, type, arg0, arg1)) != 0) | 12525 if ((tem = fold_truthop (loc, code, type, arg0, arg1)) != 0) |
12103 return tem; | 12526 return tem; |
12104 | 12527 |
12105 return NULL_TREE; | 12528 return NULL_TREE; |
12106 | 12529 |
12107 case TRUTH_ORIF_EXPR: | 12530 case TRUTH_ORIF_EXPR: |
12108 /* Note that the operands of this must be ints | 12531 /* Note that the operands of this must be ints |
12109 and their values must be 0 or true. | 12532 and their values must be 0 or true. |
12110 ("true" is a fixed value perhaps depending on the language.) */ | 12533 ("true" is a fixed value perhaps depending on the language.) */ |
12111 /* If first arg is constant true, return it. */ | 12534 /* If first arg is constant true, return it. */ |
12112 if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0)) | 12535 if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0)) |
12113 return fold_convert (type, arg0); | 12536 return fold_convert_loc (loc, type, arg0); |
12114 case TRUTH_OR_EXPR: | 12537 case TRUTH_OR_EXPR: |
12115 /* If either arg is constant zero, drop it. */ | 12538 /* If either arg is constant zero, drop it. */ |
12116 if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0)) | 12539 if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0)) |
12117 return non_lvalue (fold_convert (type, arg1)); | 12540 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1)); |
12118 if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1) | 12541 if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1) |
12119 /* Preserve sequence points. */ | 12542 /* Preserve sequence points. */ |
12120 && (code != TRUTH_ORIF_EXPR || ! TREE_SIDE_EFFECTS (arg0))) | 12543 && (code != TRUTH_ORIF_EXPR || ! TREE_SIDE_EFFECTS (arg0))) |
12121 return non_lvalue (fold_convert (type, arg0)); | 12544 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
12122 /* If second arg is constant true, result is true, but we must | 12545 /* If second arg is constant true, result is true, but we must |
12123 evaluate first arg. */ | 12546 evaluate first arg. */ |
12124 if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1)) | 12547 if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1)) |
12125 return omit_one_operand (type, arg1, arg0); | 12548 return omit_one_operand_loc (loc, type, arg1, arg0); |
12126 /* Likewise for first arg, but note this only occurs here for | 12549 /* Likewise for first arg, but note this only occurs here for |
12127 TRUTH_OR_EXPR. */ | 12550 TRUTH_OR_EXPR. */ |
12128 if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0)) | 12551 if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0)) |
12129 return omit_one_operand (type, arg0, arg1); | 12552 return omit_one_operand_loc (loc, type, arg0, arg1); |
12130 | 12553 |
12131 /* !X || X is always true. */ | 12554 /* !X || X is always true. */ |
12132 if (TREE_CODE (arg0) == TRUTH_NOT_EXPR | 12555 if (TREE_CODE (arg0) == TRUTH_NOT_EXPR |
12133 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 12556 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
12134 return omit_one_operand (type, integer_one_node, arg1); | 12557 return omit_one_operand_loc (loc, type, integer_one_node, arg1); |
12135 /* X || !X is always true. */ | 12558 /* X || !X is always true. */ |
12136 if (TREE_CODE (arg1) == TRUTH_NOT_EXPR | 12559 if (TREE_CODE (arg1) == TRUTH_NOT_EXPR |
12137 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 12560 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
12138 return omit_one_operand (type, integer_one_node, arg0); | 12561 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
12139 | 12562 |
12140 goto truth_andor; | 12563 goto truth_andor; |
12141 | 12564 |
12142 case TRUTH_XOR_EXPR: | 12565 case TRUTH_XOR_EXPR: |
12143 /* If the second arg is constant zero, drop it. */ | 12566 /* If the second arg is constant zero, drop it. */ |
12144 if (integer_zerop (arg1)) | 12567 if (integer_zerop (arg1)) |
12145 return non_lvalue (fold_convert (type, arg0)); | 12568 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
12146 /* If the second arg is constant true, this is a logical inversion. */ | 12569 /* If the second arg is constant true, this is a logical inversion. */ |
12147 if (integer_onep (arg1)) | 12570 if (integer_onep (arg1)) |
12148 { | 12571 { |
12149 /* Only call invert_truthvalue if operand is a truth value. */ | 12572 /* Only call invert_truthvalue if operand is a truth value. */ |
12150 if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE) | 12573 if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE) |
12151 tem = fold_build1 (TRUTH_NOT_EXPR, TREE_TYPE (arg0), arg0); | 12574 tem = fold_build1_loc (loc, TRUTH_NOT_EXPR, TREE_TYPE (arg0), arg0); |
12152 else | 12575 else |
12153 tem = invert_truthvalue (arg0); | 12576 tem = invert_truthvalue_loc (loc, arg0); |
12154 return non_lvalue (fold_convert (type, tem)); | 12577 return non_lvalue_loc (loc, fold_convert_loc (loc, type, tem)); |
12155 } | 12578 } |
12156 /* Identical arguments cancel to zero. */ | 12579 /* Identical arguments cancel to zero. */ |
12157 if (operand_equal_p (arg0, arg1, 0)) | 12580 if (operand_equal_p (arg0, arg1, 0)) |
12158 return omit_one_operand (type, integer_zero_node, arg0); | 12581 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
12159 | 12582 |
12160 /* !X ^ X is always true. */ | 12583 /* !X ^ X is always true. */ |
12161 if (TREE_CODE (arg0) == TRUTH_NOT_EXPR | 12584 if (TREE_CODE (arg0) == TRUTH_NOT_EXPR |
12162 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) | 12585 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) |
12163 return omit_one_operand (type, integer_one_node, arg1); | 12586 return omit_one_operand_loc (loc, type, integer_one_node, arg1); |
12164 | 12587 |
12165 /* X ^ !X is always true. */ | 12588 /* X ^ !X is always true. */ |
12166 if (TREE_CODE (arg1) == TRUTH_NOT_EXPR | 12589 if (TREE_CODE (arg1) == TRUTH_NOT_EXPR |
12167 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) | 12590 && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)) |
12168 return omit_one_operand (type, integer_one_node, arg0); | 12591 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
12169 | 12592 |
12170 return NULL_TREE; | 12593 return NULL_TREE; |
12171 | 12594 |
12172 case EQ_EXPR: | 12595 case EQ_EXPR: |
12173 case NE_EXPR: | 12596 case NE_EXPR: |
12174 tem = fold_comparison (code, type, op0, op1); | 12597 tem = fold_comparison (loc, code, type, op0, op1); |
12175 if (tem != NULL_TREE) | 12598 if (tem != NULL_TREE) |
12176 return tem; | 12599 return tem; |
12177 | 12600 |
12178 /* bool_var != 0 becomes bool_var. */ | 12601 /* bool_var != 0 becomes bool_var. */ |
12179 if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1) | 12602 if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1) |
12180 && code == NE_EXPR) | 12603 && code == NE_EXPR) |
12181 return non_lvalue (fold_convert (type, arg0)); | 12604 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
12182 | 12605 |
12183 /* bool_var == 1 becomes bool_var. */ | 12606 /* bool_var == 1 becomes bool_var. */ |
12184 if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1) | 12607 if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1) |
12185 && code == EQ_EXPR) | 12608 && code == EQ_EXPR) |
12186 return non_lvalue (fold_convert (type, arg0)); | 12609 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); |
12187 | 12610 |
12188 /* bool_var != 1 becomes !bool_var. */ | 12611 /* bool_var != 1 becomes !bool_var. */ |
12189 if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1) | 12612 if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1) |
12190 && code == NE_EXPR) | 12613 && code == NE_EXPR) |
12191 return fold_build1 (TRUTH_NOT_EXPR, type, fold_convert (type, arg0)); | 12614 return fold_build1_loc (loc, TRUTH_NOT_EXPR, type, |
12615 fold_convert_loc (loc, type, arg0)); | |
12192 | 12616 |
12193 /* bool_var == 0 becomes !bool_var. */ | 12617 /* bool_var == 0 becomes !bool_var. */ |
12194 if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1) | 12618 if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1) |
12195 && code == EQ_EXPR) | 12619 && code == EQ_EXPR) |
12196 return fold_build1 (TRUTH_NOT_EXPR, type, fold_convert (type, arg0)); | 12620 return fold_build1_loc (loc, TRUTH_NOT_EXPR, type, |
12621 fold_convert_loc (loc, type, arg0)); | |
12622 | |
12623 /* !exp != 0 becomes !exp */ | |
12624 if (TREE_CODE (arg0) == TRUTH_NOT_EXPR && integer_zerop (arg1) | |
12625 && code == NE_EXPR) | |
12626 return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); | |
12197 | 12627 |
12198 /* If this is an equality comparison of the address of two non-weak, | 12628 /* If this is an equality comparison of the address of two non-weak, |
12199 unaliased symbols neither of which are extern (since we do not | 12629 unaliased symbols neither of which are extern (since we do not |
12200 have access to attributes for externs), then we know the result. */ | 12630 have access to attributes for externs), then we know the result. */ |
12201 if (TREE_CODE (arg0) == ADDR_EXPR | 12631 if (TREE_CODE (arg0) == ADDR_EXPR |
12235 && (TREE_CODE (arg0) == PLUS_EXPR | 12665 && (TREE_CODE (arg0) == PLUS_EXPR |
12236 || TREE_CODE (arg0) == MINUS_EXPR) | 12666 || TREE_CODE (arg0) == MINUS_EXPR) |
12237 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST | 12667 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST |
12238 && 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR | 12668 && 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR |
12239 ? MINUS_EXPR : PLUS_EXPR, | 12669 ? MINUS_EXPR : PLUS_EXPR, |
12240 fold_convert (TREE_TYPE (arg0), arg1), | 12670 fold_convert_loc (loc, TREE_TYPE (arg0), |
12671 arg1), | |
12241 TREE_OPERAND (arg0, 1), 0)) | 12672 TREE_OPERAND (arg0, 1), 0)) |
12242 && !TREE_OVERFLOW (tem)) | 12673 && !TREE_OVERFLOW (tem)) |
12243 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), tem); | 12674 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem); |
12244 | 12675 |
12245 /* Similarly for a NEGATE_EXPR. */ | 12676 /* Similarly for a NEGATE_EXPR. */ |
12246 if (TREE_CODE (arg0) == NEGATE_EXPR | 12677 if (TREE_CODE (arg0) == NEGATE_EXPR |
12247 && TREE_CODE (arg1) == INTEGER_CST | 12678 && TREE_CODE (arg1) == INTEGER_CST |
12248 && 0 != (tem = negate_expr (arg1)) | 12679 && 0 != (tem = negate_expr (arg1)) |
12249 && TREE_CODE (tem) == INTEGER_CST | 12680 && TREE_CODE (tem) == INTEGER_CST |
12250 && !TREE_OVERFLOW (tem)) | 12681 && !TREE_OVERFLOW (tem)) |
12251 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), tem); | 12682 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem); |
12252 | 12683 |
12253 /* Similarly for a BIT_XOR_EXPR; X ^ C1 == C2 is X == (C1 ^ C2). */ | 12684 /* Similarly for a BIT_XOR_EXPR; X ^ C1 == C2 is X == (C1 ^ C2). */ |
12254 if (TREE_CODE (arg0) == BIT_XOR_EXPR | 12685 if (TREE_CODE (arg0) == BIT_XOR_EXPR |
12255 && TREE_CODE (arg1) == INTEGER_CST | 12686 && TREE_CODE (arg1) == INTEGER_CST |
12256 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) | 12687 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) |
12257 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), | 12688 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), |
12258 fold_build2 (BIT_XOR_EXPR, TREE_TYPE (arg0), | 12689 fold_build2_loc (loc, BIT_XOR_EXPR, TREE_TYPE (arg0), |
12259 fold_convert (TREE_TYPE (arg0), arg1), | 12690 fold_convert_loc (loc, |
12691 TREE_TYPE (arg0), | |
12692 arg1), | |
12260 TREE_OPERAND (arg0, 1))); | 12693 TREE_OPERAND (arg0, 1))); |
12261 | 12694 |
12262 /* Transform comparisons of the form X +- C CMP X. */ | 12695 /* Transform comparisons of the form X +- Y CMP X to Y CMP 0. */ |
12263 if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) | 12696 if ((TREE_CODE (arg0) == PLUS_EXPR |
12697 || TREE_CODE (arg0) == POINTER_PLUS_EXPR | |
12698 || TREE_CODE (arg0) == MINUS_EXPR) | |
12264 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) | 12699 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) |
12265 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST | |
12266 && (INTEGRAL_TYPE_P (TREE_TYPE (arg0)) | 12700 && (INTEGRAL_TYPE_P (TREE_TYPE (arg0)) |
12267 || POINTER_TYPE_P (TREE_TYPE (arg0)))) | 12701 || POINTER_TYPE_P (TREE_TYPE (arg0)))) |
12268 { | 12702 { |
12269 tree cst = TREE_OPERAND (arg0, 1); | 12703 tree val = TREE_OPERAND (arg0, 1); |
12270 | 12704 return omit_two_operands_loc (loc, type, |
12271 if (code == EQ_EXPR | 12705 fold_build2_loc (loc, code, type, |
12272 && !integer_zerop (cst)) | 12706 val, |
12273 return omit_two_operands (type, boolean_false_node, | 12707 build_int_cst (TREE_TYPE (val), |
12274 TREE_OPERAND (arg0, 0), arg1); | 12708 0)), |
12275 else | 12709 TREE_OPERAND (arg0, 0), arg1); |
12276 return omit_two_operands (type, boolean_true_node, | 12710 } |
12277 TREE_OPERAND (arg0, 0), arg1); | 12711 |
12712 /* Transform comparisons of the form C - X CMP X if C % 2 == 1. */ | |
12713 if (TREE_CODE (arg0) == MINUS_EXPR | |
12714 && TREE_CODE (TREE_OPERAND (arg0, 0)) == INTEGER_CST | |
12715 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0) | |
12716 && (TREE_INT_CST_LOW (TREE_OPERAND (arg0, 0)) & 1) == 1) | |
12717 { | |
12718 return omit_two_operands_loc (loc, type, | |
12719 code == NE_EXPR | |
12720 ? boolean_true_node : boolean_false_node, | |
12721 TREE_OPERAND (arg0, 1), arg1); | |
12278 } | 12722 } |
12279 | 12723 |
12280 /* If we have X - Y == 0, we can convert that to X == Y and similarly | 12724 /* If we have X - Y == 0, we can convert that to X == Y and similarly |
12281 for !=. Don't do this for ordered comparisons due to overflow. */ | 12725 for !=. Don't do this for ordered comparisons due to overflow. */ |
12282 if (TREE_CODE (arg0) == MINUS_EXPR | 12726 if (TREE_CODE (arg0) == MINUS_EXPR |
12283 && integer_zerop (arg1)) | 12727 && integer_zerop (arg1)) |
12284 return fold_build2 (code, type, | 12728 return fold_build2_loc (loc, code, type, |
12285 TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1)); | 12729 TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1)); |
12286 | 12730 |
12287 /* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0. */ | 12731 /* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0. */ |
12288 if (TREE_CODE (arg0) == ABS_EXPR | 12732 if (TREE_CODE (arg0) == ABS_EXPR |
12289 && (integer_zerop (arg1) || real_zerop (arg1))) | 12733 && (integer_zerop (arg1) || real_zerop (arg1))) |
12290 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), arg1); | 12734 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), arg1); |
12291 | 12735 |
12292 /* If this is an EQ or NE comparison with zero and ARG0 is | 12736 /* If this is an EQ or NE comparison with zero and ARG0 is |
12293 (1 << foo) & bar, convert it to (bar >> foo) & 1. Both require | 12737 (1 << foo) & bar, convert it to (bar >> foo) & 1. Both require |
12294 two operations, but the latter can be done in one less insn | 12738 two operations, but the latter can be done in one less insn |
12295 on machines that have only two-operand insns or on which a | 12739 on machines that have only two-operand insns or on which a |
12300 tree arg00 = TREE_OPERAND (arg0, 0); | 12744 tree arg00 = TREE_OPERAND (arg0, 0); |
12301 tree arg01 = TREE_OPERAND (arg0, 1); | 12745 tree arg01 = TREE_OPERAND (arg0, 1); |
12302 if (TREE_CODE (arg00) == LSHIFT_EXPR | 12746 if (TREE_CODE (arg00) == LSHIFT_EXPR |
12303 && integer_onep (TREE_OPERAND (arg00, 0))) | 12747 && integer_onep (TREE_OPERAND (arg00, 0))) |
12304 { | 12748 { |
12305 tree tem = fold_build2 (RSHIFT_EXPR, TREE_TYPE (arg00), | 12749 tree tem = fold_build2_loc (loc, RSHIFT_EXPR, TREE_TYPE (arg00), |
12306 arg01, TREE_OPERAND (arg00, 1)); | 12750 arg01, TREE_OPERAND (arg00, 1)); |
12307 tem = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg0), tem, | 12751 tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), tem, |
12308 build_int_cst (TREE_TYPE (arg0), 1)); | 12752 build_int_cst (TREE_TYPE (arg0), 1)); |
12309 return fold_build2 (code, type, | 12753 return fold_build2_loc (loc, code, type, |
12310 fold_convert (TREE_TYPE (arg1), tem), arg1); | 12754 fold_convert_loc (loc, TREE_TYPE (arg1), tem), |
12755 arg1); | |
12311 } | 12756 } |
12312 else if (TREE_CODE (arg01) == LSHIFT_EXPR | 12757 else if (TREE_CODE (arg01) == LSHIFT_EXPR |
12313 && integer_onep (TREE_OPERAND (arg01, 0))) | 12758 && integer_onep (TREE_OPERAND (arg01, 0))) |
12314 { | 12759 { |
12315 tree tem = fold_build2 (RSHIFT_EXPR, TREE_TYPE (arg01), | 12760 tree tem = fold_build2_loc (loc, RSHIFT_EXPR, TREE_TYPE (arg01), |
12316 arg00, TREE_OPERAND (arg01, 1)); | 12761 arg00, TREE_OPERAND (arg01, 1)); |
12317 tem = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg0), tem, | 12762 tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), tem, |
12318 build_int_cst (TREE_TYPE (arg0), 1)); | 12763 build_int_cst (TREE_TYPE (arg0), 1)); |
12319 return fold_build2 (code, type, | 12764 return fold_build2_loc (loc, code, type, |
12320 fold_convert (TREE_TYPE (arg1), tem), arg1); | 12765 fold_convert_loc (loc, TREE_TYPE (arg1), tem), |
12766 arg1); | |
12321 } | 12767 } |
12322 } | 12768 } |
12323 | 12769 |
12324 /* If this is an NE or EQ comparison of zero against the result of a | 12770 /* If this is an NE or EQ comparison of zero against the result of a |
12325 signed MOD operation whose second operand is a power of 2, make | 12771 signed MOD operation whose second operand is a power of 2, make |
12331 || TREE_CODE (arg0) == FLOOR_MOD_EXPR | 12777 || TREE_CODE (arg0) == FLOOR_MOD_EXPR |
12332 || TREE_CODE (arg0) == ROUND_MOD_EXPR) | 12778 || TREE_CODE (arg0) == ROUND_MOD_EXPR) |
12333 && integer_pow2p (TREE_OPERAND (arg0, 1))) | 12779 && integer_pow2p (TREE_OPERAND (arg0, 1))) |
12334 { | 12780 { |
12335 tree newtype = unsigned_type_for (TREE_TYPE (arg0)); | 12781 tree newtype = unsigned_type_for (TREE_TYPE (arg0)); |
12336 tree newmod = fold_build2 (TREE_CODE (arg0), newtype, | 12782 tree newmod = fold_build2_loc (loc, TREE_CODE (arg0), newtype, |
12337 fold_convert (newtype, | 12783 fold_convert_loc (loc, newtype, |
12338 TREE_OPERAND (arg0, 0)), | 12784 TREE_OPERAND (arg0, 0)), |
12339 fold_convert (newtype, | 12785 fold_convert_loc (loc, newtype, |
12340 TREE_OPERAND (arg0, 1))); | 12786 TREE_OPERAND (arg0, 1))); |
12341 | 12787 |
12342 return fold_build2 (code, type, newmod, | 12788 return fold_build2_loc (loc, code, type, newmod, |
12343 fold_convert (newtype, arg1)); | 12789 fold_convert_loc (loc, newtype, arg1)); |
12344 } | 12790 } |
12345 | 12791 |
12346 /* Fold ((X >> C1) & C2) == 0 and ((X >> C1) & C2) != 0 where | 12792 /* Fold ((X >> C1) & C2) == 0 and ((X >> C1) & C2) != 0 where |
12347 C1 is a valid shift constant, and C2 is a power of two, i.e. | 12793 C1 is a valid shift constant, and C2 is a power of two, i.e. |
12348 a single bit. */ | 12794 a single bit. */ |
12366 unsigned HOST_WIDE_INT log2 = tree_log2 (arg01); | 12812 unsigned HOST_WIDE_INT log2 = tree_log2 (arg01); |
12367 /* If (C2 << C1) doesn't overflow, then ((X >> C1) & C2) != 0 | 12813 /* If (C2 << C1) doesn't overflow, then ((X >> C1) & C2) != 0 |
12368 can be rewritten as (X & (C2 << C1)) != 0. */ | 12814 can be rewritten as (X & (C2 << C1)) != 0. */ |
12369 if ((log2 + TREE_INT_CST_LOW (arg001)) < prec) | 12815 if ((log2 + TREE_INT_CST_LOW (arg001)) < prec) |
12370 { | 12816 { |
12371 tem = fold_build2 (LSHIFT_EXPR, itype, arg01, arg001); | 12817 tem = fold_build2_loc (loc, LSHIFT_EXPR, itype, arg01, arg001); |
12372 tem = fold_build2 (BIT_AND_EXPR, itype, arg000, tem); | 12818 tem = fold_build2_loc (loc, BIT_AND_EXPR, itype, arg000, tem); |
12373 return fold_build2 (code, type, tem, arg1); | 12819 return fold_build2_loc (loc, code, type, tem, arg1); |
12374 } | 12820 } |
12375 /* Otherwise, for signed (arithmetic) shifts, | 12821 /* Otherwise, for signed (arithmetic) shifts, |
12376 ((X >> C1) & C2) != 0 is rewritten as X < 0, and | 12822 ((X >> C1) & C2) != 0 is rewritten as X < 0, and |
12377 ((X >> C1) & C2) == 0 is rewritten as X >= 0. */ | 12823 ((X >> C1) & C2) == 0 is rewritten as X >= 0. */ |
12378 else if (!TYPE_UNSIGNED (itype)) | 12824 else if (!TYPE_UNSIGNED (itype)) |
12379 return fold_build2 (code == EQ_EXPR ? GE_EXPR : LT_EXPR, type, | 12825 return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR, type, |
12380 arg000, build_int_cst (itype, 0)); | 12826 arg000, build_int_cst (itype, 0)); |
12381 /* Otherwise, of unsigned (logical) shifts, | 12827 /* Otherwise, of unsigned (logical) shifts, |
12382 ((X >> C1) & C2) != 0 is rewritten as (X,false), and | 12828 ((X >> C1) & C2) != 0 is rewritten as (X,false), and |
12383 ((X >> C1) & C2) == 0 is rewritten as (X,true). */ | 12829 ((X >> C1) & C2) == 0 is rewritten as (X,true). */ |
12384 else | 12830 else |
12385 return omit_one_operand (type, | 12831 return omit_one_operand_loc (loc, type, |
12386 code == EQ_EXPR ? integer_one_node | 12832 code == EQ_EXPR ? integer_one_node |
12387 : integer_zero_node, | 12833 : integer_zero_node, |
12388 arg000); | 12834 arg000); |
12389 } | 12835 } |
12390 } | 12836 } |
12393 comparison since the AND will give the correct value. */ | 12839 comparison since the AND will give the correct value. */ |
12394 if (code == NE_EXPR | 12840 if (code == NE_EXPR |
12395 && integer_zerop (arg1) | 12841 && integer_zerop (arg1) |
12396 && TREE_CODE (arg0) == BIT_AND_EXPR | 12842 && TREE_CODE (arg0) == BIT_AND_EXPR |
12397 && integer_onep (TREE_OPERAND (arg0, 1))) | 12843 && integer_onep (TREE_OPERAND (arg0, 1))) |
12398 return fold_convert (type, arg0); | 12844 return fold_convert_loc (loc, type, arg0); |
12399 | 12845 |
12400 /* If we have (A & C) == C where C is a power of 2, convert this into | 12846 /* If we have (A & C) == C where C is a power of 2, convert this into |
12401 (A & C) != 0. Similarly for NE_EXPR. */ | 12847 (A & C) != 0. Similarly for NE_EXPR. */ |
12402 if (TREE_CODE (arg0) == BIT_AND_EXPR | 12848 if (TREE_CODE (arg0) == BIT_AND_EXPR |
12403 && integer_pow2p (TREE_OPERAND (arg0, 1)) | 12849 && integer_pow2p (TREE_OPERAND (arg0, 1)) |
12404 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) | 12850 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) |
12405 return fold_build2 (code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type, | 12851 return fold_build2_loc (loc, code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type, |
12406 arg0, fold_convert (TREE_TYPE (arg0), | 12852 arg0, fold_convert_loc (loc, TREE_TYPE (arg0), |
12407 integer_zero_node)); | 12853 integer_zero_node)); |
12408 | 12854 |
12409 /* If we have (A & C) != 0 or (A & C) == 0 and C is the sign | 12855 /* If we have (A & C) != 0 or (A & C) == 0 and C is the sign |
12410 bit, then fold the expression into A < 0 or A >= 0. */ | 12856 bit, then fold the expression into A < 0 or A >= 0. */ |
12411 tem = fold_single_bit_test_into_sign_test (code, arg0, arg1, type); | 12857 tem = fold_single_bit_test_into_sign_test (loc, code, arg0, arg1, type); |
12412 if (tem) | 12858 if (tem) |
12413 return tem; | 12859 return tem; |
12414 | 12860 |
12415 /* If we have (A & C) == D where D & ~C != 0, convert this into 0. | 12861 /* If we have (A & C) == D where D & ~C != 0, convert this into 0. |
12416 Similarly for NE_EXPR. */ | 12862 Similarly for NE_EXPR. */ |
12417 if (TREE_CODE (arg0) == BIT_AND_EXPR | 12863 if (TREE_CODE (arg0) == BIT_AND_EXPR |
12418 && TREE_CODE (arg1) == INTEGER_CST | 12864 && TREE_CODE (arg1) == INTEGER_CST |
12419 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) | 12865 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) |
12420 { | 12866 { |
12421 tree notc = fold_build1 (BIT_NOT_EXPR, | 12867 tree notc = fold_build1_loc (loc, BIT_NOT_EXPR, |
12422 TREE_TYPE (TREE_OPERAND (arg0, 1)), | 12868 TREE_TYPE (TREE_OPERAND (arg0, 1)), |
12423 TREE_OPERAND (arg0, 1)); | 12869 TREE_OPERAND (arg0, 1)); |
12424 tree dandnotc = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg0), | 12870 tree dandnotc = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), |
12425 arg1, notc); | 12871 arg1, notc); |
12426 tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node; | 12872 tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node; |
12427 if (integer_nonzerop (dandnotc)) | 12873 if (integer_nonzerop (dandnotc)) |
12428 return omit_one_operand (type, rslt, arg0); | 12874 return omit_one_operand_loc (loc, type, rslt, arg0); |
12429 } | 12875 } |
12430 | 12876 |
12431 /* If we have (A | C) == D where C & ~D != 0, convert this into 0. | 12877 /* If we have (A | C) == D where C & ~D != 0, convert this into 0. |
12432 Similarly for NE_EXPR. */ | 12878 Similarly for NE_EXPR. */ |
12433 if (TREE_CODE (arg0) == BIT_IOR_EXPR | 12879 if (TREE_CODE (arg0) == BIT_IOR_EXPR |
12434 && TREE_CODE (arg1) == INTEGER_CST | 12880 && TREE_CODE (arg1) == INTEGER_CST |
12435 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) | 12881 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) |
12436 { | 12882 { |
12437 tree notd = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), arg1); | 12883 tree notd = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg1), arg1); |
12438 tree candnotd = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg0), | 12884 tree candnotd = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), |
12439 TREE_OPERAND (arg0, 1), notd); | 12885 TREE_OPERAND (arg0, 1), notd); |
12440 tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node; | 12886 tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node; |
12441 if (integer_nonzerop (candnotd)) | 12887 if (integer_nonzerop (candnotd)) |
12442 return omit_one_operand (type, rslt, arg0); | 12888 return omit_one_operand_loc (loc, type, rslt, arg0); |
12443 } | 12889 } |
12444 | 12890 |
12445 /* If this is a comparison of a field, we may be able to simplify it. */ | 12891 /* If this is a comparison of a field, we may be able to simplify it. */ |
12446 if ((TREE_CODE (arg0) == COMPONENT_REF | 12892 if ((TREE_CODE (arg0) == COMPONENT_REF |
12447 || TREE_CODE (arg0) == BIT_FIELD_REF) | 12893 || TREE_CODE (arg0) == BIT_FIELD_REF) |
12448 /* Handle the constant case even without -O | 12894 /* Handle the constant case even without -O |
12449 to make sure the warnings are given. */ | 12895 to make sure the warnings are given. */ |
12450 && (optimize || TREE_CODE (arg1) == INTEGER_CST)) | 12896 && (optimize || TREE_CODE (arg1) == INTEGER_CST)) |
12451 { | 12897 { |
12452 t1 = optimize_bit_field_compare (code, type, arg0, arg1); | 12898 t1 = optimize_bit_field_compare (loc, code, type, arg0, arg1); |
12453 if (t1) | 12899 if (t1) |
12454 return t1; | 12900 return t1; |
12455 } | 12901 } |
12456 | 12902 |
12457 /* Optimize comparisons of strlen vs zero to a compare of the | 12903 /* Optimize comparisons of strlen vs zero to a compare of the |
12469 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL | 12915 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL |
12470 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRLEN | 12916 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRLEN |
12471 && call_expr_nargs (arg0) == 1 | 12917 && call_expr_nargs (arg0) == 1 |
12472 && TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (arg0, 0))) == POINTER_TYPE) | 12918 && TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (arg0, 0))) == POINTER_TYPE) |
12473 { | 12919 { |
12474 tree iref = build_fold_indirect_ref (CALL_EXPR_ARG (arg0, 0)); | 12920 tree iref = build_fold_indirect_ref_loc (loc, |
12475 return fold_build2 (code, type, iref, | 12921 CALL_EXPR_ARG (arg0, 0)); |
12922 return fold_build2_loc (loc, code, type, iref, | |
12476 build_int_cst (TREE_TYPE (iref), 0)); | 12923 build_int_cst (TREE_TYPE (iref), 0)); |
12477 } | 12924 } |
12478 } | 12925 } |
12479 | 12926 |
12480 /* Fold (X >> C) != 0 into X < 0 if C is one less than the width | 12927 /* Fold (X >> C) != 0 into X < 0 if C is one less than the width |
12491 == (unsigned HOST_WIDE_INT) (TYPE_PRECISION (itype) - 1)) | 12938 == (unsigned HOST_WIDE_INT) (TYPE_PRECISION (itype) - 1)) |
12492 { | 12939 { |
12493 if (TYPE_UNSIGNED (itype)) | 12940 if (TYPE_UNSIGNED (itype)) |
12494 { | 12941 { |
12495 itype = signed_type_for (itype); | 12942 itype = signed_type_for (itype); |
12496 arg00 = fold_convert (itype, arg00); | 12943 arg00 = fold_convert_loc (loc, itype, arg00); |
12497 } | 12944 } |
12498 return fold_build2 (code == EQ_EXPR ? GE_EXPR : LT_EXPR, | 12945 return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR, |
12499 type, arg00, build_int_cst (itype, 0)); | 12946 type, arg00, build_int_cst (itype, 0)); |
12500 } | 12947 } |
12501 } | 12948 } |
12502 | 12949 |
12503 /* (X ^ Y) == 0 becomes X == Y, and (X ^ Y) != 0 becomes X != Y. */ | 12950 /* (X ^ Y) == 0 becomes X == Y, and (X ^ Y) != 0 becomes X != Y. */ |
12504 if (integer_zerop (arg1) | 12951 if (integer_zerop (arg1) |
12505 && TREE_CODE (arg0) == BIT_XOR_EXPR) | 12952 && TREE_CODE (arg0) == BIT_XOR_EXPR) |
12506 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), | 12953 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), |
12507 TREE_OPERAND (arg0, 1)); | 12954 TREE_OPERAND (arg0, 1)); |
12508 | 12955 |
12509 /* (X ^ Y) == Y becomes X == 0. We know that Y has no side-effects. */ | 12956 /* (X ^ Y) == Y becomes X == 0. We know that Y has no side-effects. */ |
12510 if (TREE_CODE (arg0) == BIT_XOR_EXPR | 12957 if (TREE_CODE (arg0) == BIT_XOR_EXPR |
12511 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) | 12958 && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) |
12512 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), | 12959 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), |
12513 build_int_cst (TREE_TYPE (arg1), 0)); | 12960 build_int_cst (TREE_TYPE (arg1), 0)); |
12514 /* Likewise (X ^ Y) == X becomes Y == 0. X has no side-effects. */ | 12961 /* Likewise (X ^ Y) == X becomes Y == 0. X has no side-effects. */ |
12515 if (TREE_CODE (arg0) == BIT_XOR_EXPR | 12962 if (TREE_CODE (arg0) == BIT_XOR_EXPR |
12516 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) | 12963 && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0) |
12517 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) | 12964 && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1)) |
12518 return fold_build2 (code, type, TREE_OPERAND (arg0, 1), | 12965 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 1), |
12519 build_int_cst (TREE_TYPE (arg1), 0)); | 12966 build_int_cst (TREE_TYPE (arg1), 0)); |
12520 | 12967 |
12521 /* (X ^ C1) op C2 can be rewritten as X op (C1 ^ C2). */ | 12968 /* (X ^ C1) op C2 can be rewritten as X op (C1 ^ C2). */ |
12522 if (TREE_CODE (arg0) == BIT_XOR_EXPR | 12969 if (TREE_CODE (arg0) == BIT_XOR_EXPR |
12523 && TREE_CODE (arg1) == INTEGER_CST | 12970 && TREE_CODE (arg1) == INTEGER_CST |
12524 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) | 12971 && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST) |
12525 return fold_build2 (code, type, TREE_OPERAND (arg0, 0), | 12972 return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), |
12526 fold_build2 (BIT_XOR_EXPR, TREE_TYPE (arg1), | 12973 fold_build2_loc (loc, BIT_XOR_EXPR, TREE_TYPE (arg1), |
12527 TREE_OPERAND (arg0, 1), arg1)); | 12974 TREE_OPERAND (arg0, 1), arg1)); |
12528 | 12975 |
12529 /* Fold (~X & C) == 0 into (X & C) != 0 and (~X & C) != 0 into | 12976 /* Fold (~X & C) == 0 into (X & C) != 0 and (~X & C) != 0 into |
12530 (X & C) == 0 when C is a single bit. */ | 12977 (X & C) == 0 when C is a single bit. */ |
12531 if (TREE_CODE (arg0) == BIT_AND_EXPR | 12978 if (TREE_CODE (arg0) == BIT_AND_EXPR |
12532 && TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_NOT_EXPR | 12979 && TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_NOT_EXPR |
12533 && integer_zerop (arg1) | 12980 && integer_zerop (arg1) |
12534 && integer_pow2p (TREE_OPERAND (arg0, 1))) | 12981 && integer_pow2p (TREE_OPERAND (arg0, 1))) |
12535 { | 12982 { |
12536 tem = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg0), | 12983 tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), |
12537 TREE_OPERAND (TREE_OPERAND (arg0, 0), 0), | 12984 TREE_OPERAND (TREE_OPERAND (arg0, 0), 0), |
12538 TREE_OPERAND (arg0, 1)); | 12985 TREE_OPERAND (arg0, 1)); |
12539 return fold_build2 (code == EQ_EXPR ? NE_EXPR : EQ_EXPR, | 12986 return fold_build2_loc (loc, code == EQ_EXPR ? NE_EXPR : EQ_EXPR, |
12540 type, tem, arg1); | 12987 type, tem, arg1); |
12541 } | 12988 } |
12542 | 12989 |
12543 /* Fold ((X & C) ^ C) eq/ne 0 into (X & C) ne/eq 0, when the | 12990 /* Fold ((X & C) ^ C) eq/ne 0 into (X & C) ne/eq 0, when the |
12544 constant C is a power of two, i.e. a single bit. */ | 12991 constant C is a power of two, i.e. a single bit. */ |
12548 && integer_pow2p (TREE_OPERAND (arg0, 1)) | 12995 && integer_pow2p (TREE_OPERAND (arg0, 1)) |
12549 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1), | 12996 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1), |
12550 TREE_OPERAND (arg0, 1), OEP_ONLY_CONST)) | 12997 TREE_OPERAND (arg0, 1), OEP_ONLY_CONST)) |
12551 { | 12998 { |
12552 tree arg00 = TREE_OPERAND (arg0, 0); | 12999 tree arg00 = TREE_OPERAND (arg0, 0); |
12553 return fold_build2 (code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type, | 13000 return fold_build2_loc (loc, code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type, |
12554 arg00, build_int_cst (TREE_TYPE (arg00), 0)); | 13001 arg00, build_int_cst (TREE_TYPE (arg00), 0)); |
12555 } | 13002 } |
12556 | 13003 |
12557 /* Likewise, fold ((X ^ C) & C) eq/ne 0 into (X & C) ne/eq 0, | 13004 /* Likewise, fold ((X ^ C) & C) eq/ne 0 into (X & C) ne/eq 0, |
12558 when is C is a power of two, i.e. a single bit. */ | 13005 when is C is a power of two, i.e. a single bit. */ |
12562 && integer_pow2p (TREE_OPERAND (arg0, 1)) | 13009 && integer_pow2p (TREE_OPERAND (arg0, 1)) |
12563 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1), | 13010 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1), |
12564 TREE_OPERAND (arg0, 1), OEP_ONLY_CONST)) | 13011 TREE_OPERAND (arg0, 1), OEP_ONLY_CONST)) |
12565 { | 13012 { |
12566 tree arg000 = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0); | 13013 tree arg000 = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0); |
12567 tem = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg000), | 13014 tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg000), |
12568 arg000, TREE_OPERAND (arg0, 1)); | 13015 arg000, TREE_OPERAND (arg0, 1)); |
12569 return fold_build2 (code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type, | 13016 return fold_build2_loc (loc, code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type, |
12570 tem, build_int_cst (TREE_TYPE (tem), 0)); | 13017 tem, build_int_cst (TREE_TYPE (tem), 0)); |
12571 } | 13018 } |
12572 | 13019 |
12573 if (integer_zerop (arg1) | 13020 if (integer_zerop (arg1) |
12574 && tree_expr_nonzero_p (arg0)) | 13021 && tree_expr_nonzero_p (arg0)) |
12575 { | 13022 { |
12576 tree res = constant_boolean_node (code==NE_EXPR, type); | 13023 tree res = constant_boolean_node (code==NE_EXPR, type); |
12577 return omit_one_operand (type, res, arg0); | 13024 return omit_one_operand_loc (loc, type, res, arg0); |
12578 } | 13025 } |
12579 | 13026 |
12580 /* Fold -X op -Y as X op Y, where op is eq/ne. */ | 13027 /* Fold -X op -Y as X op Y, where op is eq/ne. */ |
12581 if (TREE_CODE (arg0) == NEGATE_EXPR | 13028 if (TREE_CODE (arg0) == NEGATE_EXPR |
12582 && TREE_CODE (arg1) == NEGATE_EXPR) | 13029 && TREE_CODE (arg1) == NEGATE_EXPR) |
12583 return fold_build2 (code, type, | 13030 return fold_build2_loc (loc, code, type, |
12584 TREE_OPERAND (arg0, 0), | 13031 TREE_OPERAND (arg0, 0), |
12585 TREE_OPERAND (arg1, 0)); | 13032 TREE_OPERAND (arg1, 0)); |
12586 | 13033 |
12587 /* Fold (X & C) op (Y & C) as (X ^ Y) & C op 0", and symmetries. */ | 13034 /* Fold (X & C) op (Y & C) as (X ^ Y) & C op 0", and symmetries. */ |
12588 if (TREE_CODE (arg0) == BIT_AND_EXPR | 13035 if (TREE_CODE (arg0) == BIT_AND_EXPR |
12593 tree arg10 = TREE_OPERAND (arg1, 0); | 13040 tree arg10 = TREE_OPERAND (arg1, 0); |
12594 tree arg11 = TREE_OPERAND (arg1, 1); | 13041 tree arg11 = TREE_OPERAND (arg1, 1); |
12595 tree itype = TREE_TYPE (arg0); | 13042 tree itype = TREE_TYPE (arg0); |
12596 | 13043 |
12597 if (operand_equal_p (arg01, arg11, 0)) | 13044 if (operand_equal_p (arg01, arg11, 0)) |
12598 return fold_build2 (code, type, | 13045 return fold_build2_loc (loc, code, type, |
12599 fold_build2 (BIT_AND_EXPR, itype, | 13046 fold_build2_loc (loc, BIT_AND_EXPR, itype, |
12600 fold_build2 (BIT_XOR_EXPR, itype, | 13047 fold_build2_loc (loc, |
13048 BIT_XOR_EXPR, itype, | |
12601 arg00, arg10), | 13049 arg00, arg10), |
12602 arg01), | 13050 arg01), |
12603 build_int_cst (itype, 0)); | 13051 build_int_cst (itype, 0)); |
12604 | 13052 |
12605 if (operand_equal_p (arg01, arg10, 0)) | 13053 if (operand_equal_p (arg01, arg10, 0)) |
12606 return fold_build2 (code, type, | 13054 return fold_build2_loc (loc, code, type, |
12607 fold_build2 (BIT_AND_EXPR, itype, | 13055 fold_build2_loc (loc, BIT_AND_EXPR, itype, |
12608 fold_build2 (BIT_XOR_EXPR, itype, | 13056 fold_build2_loc (loc, |
13057 BIT_XOR_EXPR, itype, | |
12609 arg00, arg11), | 13058 arg00, arg11), |
12610 arg01), | 13059 arg01), |
12611 build_int_cst (itype, 0)); | 13060 build_int_cst (itype, 0)); |
12612 | 13061 |
12613 if (operand_equal_p (arg00, arg11, 0)) | 13062 if (operand_equal_p (arg00, arg11, 0)) |
12614 return fold_build2 (code, type, | 13063 return fold_build2_loc (loc, code, type, |
12615 fold_build2 (BIT_AND_EXPR, itype, | 13064 fold_build2_loc (loc, BIT_AND_EXPR, itype, |
12616 fold_build2 (BIT_XOR_EXPR, itype, | 13065 fold_build2_loc (loc, |
13066 BIT_XOR_EXPR, itype, | |
12617 arg01, arg10), | 13067 arg01, arg10), |
12618 arg00), | 13068 arg00), |
12619 build_int_cst (itype, 0)); | 13069 build_int_cst (itype, 0)); |
12620 | 13070 |
12621 if (operand_equal_p (arg00, arg10, 0)) | 13071 if (operand_equal_p (arg00, arg10, 0)) |
12622 return fold_build2 (code, type, | 13072 return fold_build2_loc (loc, code, type, |
12623 fold_build2 (BIT_AND_EXPR, itype, | 13073 fold_build2_loc (loc, BIT_AND_EXPR, itype, |
12624 fold_build2 (BIT_XOR_EXPR, itype, | 13074 fold_build2_loc (loc, |
13075 BIT_XOR_EXPR, itype, | |
12625 arg01, arg11), | 13076 arg01, arg11), |
12626 arg00), | 13077 arg00), |
12627 build_int_cst (itype, 0)); | 13078 build_int_cst (itype, 0)); |
12628 } | 13079 } |
12629 | 13080 |
12638 | 13089 |
12639 /* Optimize (X ^ Z) op (Y ^ Z) as X op Y, and symmetries. | 13090 /* Optimize (X ^ Z) op (Y ^ Z) as X op Y, and symmetries. |
12640 operand_equal_p guarantees no side-effects so we don't need | 13091 operand_equal_p guarantees no side-effects so we don't need |
12641 to use omit_one_operand on Z. */ | 13092 to use omit_one_operand on Z. */ |
12642 if (operand_equal_p (arg01, arg11, 0)) | 13093 if (operand_equal_p (arg01, arg11, 0)) |
12643 return fold_build2 (code, type, arg00, arg10); | 13094 return fold_build2_loc (loc, code, type, arg00, arg10); |
12644 if (operand_equal_p (arg01, arg10, 0)) | 13095 if (operand_equal_p (arg01, arg10, 0)) |
12645 return fold_build2 (code, type, arg00, arg11); | 13096 return fold_build2_loc (loc, code, type, arg00, arg11); |
12646 if (operand_equal_p (arg00, arg11, 0)) | 13097 if (operand_equal_p (arg00, arg11, 0)) |
12647 return fold_build2 (code, type, arg01, arg10); | 13098 return fold_build2_loc (loc, code, type, arg01, arg10); |
12648 if (operand_equal_p (arg00, arg10, 0)) | 13099 if (operand_equal_p (arg00, arg10, 0)) |
12649 return fold_build2 (code, type, arg01, arg11); | 13100 return fold_build2_loc (loc, code, type, arg01, arg11); |
12650 | 13101 |
12651 /* Optimize (X ^ C1) op (Y ^ C2) as (X ^ (C1 ^ C2)) op Y. */ | 13102 /* Optimize (X ^ C1) op (Y ^ C2) as (X ^ (C1 ^ C2)) op Y. */ |
12652 if (TREE_CODE (arg01) == INTEGER_CST | 13103 if (TREE_CODE (arg01) == INTEGER_CST |
12653 && TREE_CODE (arg11) == INTEGER_CST) | 13104 && TREE_CODE (arg11) == INTEGER_CST) |
12654 return fold_build2 (code, type, | 13105 return fold_build2_loc (loc, code, type, |
12655 fold_build2 (BIT_XOR_EXPR, itype, arg00, | 13106 fold_build2_loc (loc, BIT_XOR_EXPR, itype, arg00, |
12656 fold_build2 (BIT_XOR_EXPR, itype, | 13107 fold_build2_loc (loc, |
13108 BIT_XOR_EXPR, itype, | |
12657 arg01, arg11)), | 13109 arg01, arg11)), |
12658 arg10); | 13110 arg10); |
12659 } | 13111 } |
12660 | 13112 |
12661 /* Attempt to simplify equality/inequality comparisons of complex | 13113 /* Attempt to simplify equality/inequality comparisons of complex |
12689 { | 13141 { |
12690 real1 = TREE_REALPART (arg1); | 13142 real1 = TREE_REALPART (arg1); |
12691 imag1 = TREE_IMAGPART (arg1); | 13143 imag1 = TREE_IMAGPART (arg1); |
12692 } | 13144 } |
12693 | 13145 |
12694 rcond = fold_binary (code, type, real0, real1); | 13146 rcond = fold_binary_loc (loc, code, type, real0, real1); |
12695 if (rcond && TREE_CODE (rcond) == INTEGER_CST) | 13147 if (rcond && TREE_CODE (rcond) == INTEGER_CST) |
12696 { | 13148 { |
12697 if (integer_zerop (rcond)) | 13149 if (integer_zerop (rcond)) |
12698 { | 13150 { |
12699 if (code == EQ_EXPR) | 13151 if (code == EQ_EXPR) |
12700 return omit_two_operands (type, boolean_false_node, | 13152 return omit_two_operands_loc (loc, type, boolean_false_node, |
12701 imag0, imag1); | 13153 imag0, imag1); |
12702 return fold_build2 (NE_EXPR, type, imag0, imag1); | 13154 return fold_build2_loc (loc, NE_EXPR, type, imag0, imag1); |
12703 } | 13155 } |
12704 else | 13156 else |
12705 { | 13157 { |
12706 if (code == NE_EXPR) | 13158 if (code == NE_EXPR) |
12707 return omit_two_operands (type, boolean_true_node, | 13159 return omit_two_operands_loc (loc, type, boolean_true_node, |
12708 imag0, imag1); | 13160 imag0, imag1); |
12709 return fold_build2 (EQ_EXPR, type, imag0, imag1); | 13161 return fold_build2_loc (loc, EQ_EXPR, type, imag0, imag1); |
12710 } | 13162 } |
12711 } | 13163 } |
12712 | 13164 |
12713 icond = fold_binary (code, type, imag0, imag1); | 13165 icond = fold_binary_loc (loc, code, type, imag0, imag1); |
12714 if (icond && TREE_CODE (icond) == INTEGER_CST) | 13166 if (icond && TREE_CODE (icond) == INTEGER_CST) |
12715 { | 13167 { |
12716 if (integer_zerop (icond)) | 13168 if (integer_zerop (icond)) |
12717 { | 13169 { |
12718 if (code == EQ_EXPR) | 13170 if (code == EQ_EXPR) |
12719 return omit_two_operands (type, boolean_false_node, | 13171 return omit_two_operands_loc (loc, type, boolean_false_node, |
12720 real0, real1); | 13172 real0, real1); |
12721 return fold_build2 (NE_EXPR, type, real0, real1); | 13173 return fold_build2_loc (loc, NE_EXPR, type, real0, real1); |
12722 } | 13174 } |
12723 else | 13175 else |
12724 { | 13176 { |
12725 if (code == NE_EXPR) | 13177 if (code == NE_EXPR) |
12726 return omit_two_operands (type, boolean_true_node, | 13178 return omit_two_operands_loc (loc, type, boolean_true_node, |
12727 real0, real1); | 13179 real0, real1); |
12728 return fold_build2 (EQ_EXPR, type, real0, real1); | 13180 return fold_build2_loc (loc, EQ_EXPR, type, real0, real1); |
12729 } | 13181 } |
12730 } | 13182 } |
12731 } | 13183 } |
12732 | 13184 |
12733 return NULL_TREE; | 13185 return NULL_TREE; |
12734 | 13186 |
12735 case LT_EXPR: | 13187 case LT_EXPR: |
12736 case GT_EXPR: | 13188 case GT_EXPR: |
12737 case LE_EXPR: | 13189 case LE_EXPR: |
12738 case GE_EXPR: | 13190 case GE_EXPR: |
12739 tem = fold_comparison (code, type, op0, op1); | 13191 tem = fold_comparison (loc, code, type, op0, op1); |
12740 if (tem != NULL_TREE) | 13192 if (tem != NULL_TREE) |
12741 return tem; | 13193 return tem; |
12742 | 13194 |
12743 /* Transform comparisons of the form X +- C CMP X. */ | 13195 /* Transform comparisons of the form X +- C CMP X. */ |
12744 if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) | 13196 if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) |
12927 if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1) == max_hi | 13379 if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1) == max_hi |
12928 && TREE_INT_CST_LOW (arg1) == max_lo) | 13380 && TREE_INT_CST_LOW (arg1) == max_lo) |
12929 switch (code) | 13381 switch (code) |
12930 { | 13382 { |
12931 case GT_EXPR: | 13383 case GT_EXPR: |
12932 return omit_one_operand (type, integer_zero_node, arg0); | 13384 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
12933 | 13385 |
12934 case GE_EXPR: | 13386 case GE_EXPR: |
12935 return fold_build2 (EQ_EXPR, type, op0, op1); | 13387 return fold_build2_loc (loc, EQ_EXPR, type, op0, op1); |
12936 | 13388 |
12937 case LE_EXPR: | 13389 case LE_EXPR: |
12938 return omit_one_operand (type, integer_one_node, arg0); | 13390 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
12939 | 13391 |
12940 case LT_EXPR: | 13392 case LT_EXPR: |
12941 return fold_build2 (NE_EXPR, type, op0, op1); | 13393 return fold_build2_loc (loc, NE_EXPR, type, op0, op1); |
12942 | 13394 |
12943 /* The GE_EXPR and LT_EXPR cases above are not normally | 13395 /* The GE_EXPR and LT_EXPR cases above are not normally |
12944 reached because of previous transformations. */ | 13396 reached because of previous transformations. */ |
12945 | 13397 |
12946 default: | 13398 default: |
12952 switch (code) | 13404 switch (code) |
12953 { | 13405 { |
12954 case GT_EXPR: | 13406 case GT_EXPR: |
12955 arg1 = const_binop (PLUS_EXPR, arg1, | 13407 arg1 = const_binop (PLUS_EXPR, arg1, |
12956 build_int_cst (TREE_TYPE (arg1), 1), 0); | 13408 build_int_cst (TREE_TYPE (arg1), 1), 0); |
12957 return fold_build2 (EQ_EXPR, type, | 13409 return fold_build2_loc (loc, EQ_EXPR, type, |
12958 fold_convert (TREE_TYPE (arg1), arg0), | 13410 fold_convert_loc (loc, |
13411 TREE_TYPE (arg1), arg0), | |
12959 arg1); | 13412 arg1); |
12960 case LE_EXPR: | 13413 case LE_EXPR: |
12961 arg1 = const_binop (PLUS_EXPR, arg1, | 13414 arg1 = const_binop (PLUS_EXPR, arg1, |
12962 build_int_cst (TREE_TYPE (arg1), 1), 0); | 13415 build_int_cst (TREE_TYPE (arg1), 1), 0); |
12963 return fold_build2 (NE_EXPR, type, | 13416 return fold_build2_loc (loc, NE_EXPR, type, |
12964 fold_convert (TREE_TYPE (arg1), arg0), | 13417 fold_convert_loc (loc, TREE_TYPE (arg1), |
13418 arg0), | |
12965 arg1); | 13419 arg1); |
12966 default: | 13420 default: |
12967 break; | 13421 break; |
12968 } | 13422 } |
12969 else if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1) | 13423 else if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1) |
12970 == min_hi | 13424 == min_hi |
12971 && TREE_INT_CST_LOW (arg1) == min_lo) | 13425 && TREE_INT_CST_LOW (arg1) == min_lo) |
12972 switch (code) | 13426 switch (code) |
12973 { | 13427 { |
12974 case LT_EXPR: | 13428 case LT_EXPR: |
12975 return omit_one_operand (type, integer_zero_node, arg0); | 13429 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
12976 | 13430 |
12977 case LE_EXPR: | 13431 case LE_EXPR: |
12978 return fold_build2 (EQ_EXPR, type, op0, op1); | 13432 return fold_build2_loc (loc, EQ_EXPR, type, op0, op1); |
12979 | 13433 |
12980 case GE_EXPR: | 13434 case GE_EXPR: |
12981 return omit_one_operand (type, integer_one_node, arg0); | 13435 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
12982 | 13436 |
12983 case GT_EXPR: | 13437 case GT_EXPR: |
12984 return fold_build2 (NE_EXPR, type, op0, op1); | 13438 return fold_build2_loc (loc, NE_EXPR, type, op0, op1); |
12985 | 13439 |
12986 default: | 13440 default: |
12987 break; | 13441 break; |
12988 } | 13442 } |
12989 else if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1) | 13443 else if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1) |
12991 && TREE_INT_CST_LOW (arg1) == min_lo + 1) | 13445 && TREE_INT_CST_LOW (arg1) == min_lo + 1) |
12992 switch (code) | 13446 switch (code) |
12993 { | 13447 { |
12994 case GE_EXPR: | 13448 case GE_EXPR: |
12995 arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0); | 13449 arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0); |
12996 return fold_build2 (NE_EXPR, type, | 13450 return fold_build2_loc (loc, NE_EXPR, type, |
12997 fold_convert (TREE_TYPE (arg1), arg0), | 13451 fold_convert_loc (loc, |
13452 TREE_TYPE (arg1), arg0), | |
12998 arg1); | 13453 arg1); |
12999 case LT_EXPR: | 13454 case LT_EXPR: |
13000 arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0); | 13455 arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0); |
13001 return fold_build2 (EQ_EXPR, type, | 13456 return fold_build2_loc (loc, EQ_EXPR, type, |
13002 fold_convert (TREE_TYPE (arg1), arg0), | 13457 fold_convert_loc (loc, TREE_TYPE (arg1), |
13458 arg0), | |
13003 arg1); | 13459 arg1); |
13004 default: | 13460 default: |
13005 break; | 13461 break; |
13006 } | 13462 } |
13007 | 13463 |
13020 and X >= signed_max+1 because previous transformations. */ | 13476 and X >= signed_max+1 because previous transformations. */ |
13021 if (code == LE_EXPR || code == GT_EXPR) | 13477 if (code == LE_EXPR || code == GT_EXPR) |
13022 { | 13478 { |
13023 tree st; | 13479 tree st; |
13024 st = signed_type_for (TREE_TYPE (arg1)); | 13480 st = signed_type_for (TREE_TYPE (arg1)); |
13025 return fold_build2 (code == LE_EXPR ? GE_EXPR : LT_EXPR, | 13481 return fold_build2_loc (loc, |
13026 type, fold_convert (st, arg0), | 13482 code == LE_EXPR ? GE_EXPR : LT_EXPR, |
13483 type, fold_convert_loc (loc, st, arg0), | |
13027 build_int_cst (st, 0)); | 13484 build_int_cst (st, 0)); |
13028 } | 13485 } |
13029 } | 13486 } |
13030 } | 13487 } |
13031 } | 13488 } |
13040 && TREE_CODE (arg0) == ABS_EXPR | 13497 && TREE_CODE (arg0) == ABS_EXPR |
13041 && ! TREE_SIDE_EFFECTS (arg0) | 13498 && ! TREE_SIDE_EFFECTS (arg0) |
13042 && (0 != (tem = negate_expr (arg1))) | 13499 && (0 != (tem = negate_expr (arg1))) |
13043 && TREE_CODE (tem) == INTEGER_CST | 13500 && TREE_CODE (tem) == INTEGER_CST |
13044 && !TREE_OVERFLOW (tem)) | 13501 && !TREE_OVERFLOW (tem)) |
13045 return fold_build2 (TRUTH_ANDIF_EXPR, type, | 13502 return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type, |
13046 build2 (GE_EXPR, type, | 13503 build2 (GE_EXPR, type, |
13047 TREE_OPERAND (arg0, 0), tem), | 13504 TREE_OPERAND (arg0, 0), tem), |
13048 build2 (LE_EXPR, type, | 13505 build2 (LE_EXPR, type, |
13049 TREE_OPERAND (arg0, 0), arg1)); | 13506 TREE_OPERAND (arg0, 0), arg1)); |
13050 | 13507 |
13059 if (strict_overflow_p) | 13516 if (strict_overflow_p) |
13060 fold_overflow_warning (("assuming signed overflow does not occur " | 13517 fold_overflow_warning (("assuming signed overflow does not occur " |
13061 "when simplifying comparison of " | 13518 "when simplifying comparison of " |
13062 "absolute value and zero"), | 13519 "absolute value and zero"), |
13063 WARN_STRICT_OVERFLOW_CONDITIONAL); | 13520 WARN_STRICT_OVERFLOW_CONDITIONAL); |
13064 return omit_one_operand (type, integer_one_node, arg0); | 13521 return omit_one_operand_loc (loc, type, integer_one_node, arg0); |
13065 } | 13522 } |
13066 | 13523 |
13067 /* Convert ABS_EXPR<x> < 0 to false. */ | 13524 /* Convert ABS_EXPR<x> < 0 to false. */ |
13068 strict_overflow_p = false; | 13525 strict_overflow_p = false; |
13069 if (code == LT_EXPR | 13526 if (code == LT_EXPR |
13073 if (strict_overflow_p) | 13530 if (strict_overflow_p) |
13074 fold_overflow_warning (("assuming signed overflow does not occur " | 13531 fold_overflow_warning (("assuming signed overflow does not occur " |
13075 "when simplifying comparison of " | 13532 "when simplifying comparison of " |
13076 "absolute value and zero"), | 13533 "absolute value and zero"), |
13077 WARN_STRICT_OVERFLOW_CONDITIONAL); | 13534 WARN_STRICT_OVERFLOW_CONDITIONAL); |
13078 return omit_one_operand (type, integer_zero_node, arg0); | 13535 return omit_one_operand_loc (loc, type, integer_zero_node, arg0); |
13079 } | 13536 } |
13080 | 13537 |
13081 /* If X is unsigned, convert X < (1 << Y) into X >> Y == 0 | 13538 /* If X is unsigned, convert X < (1 << Y) into X >> Y == 0 |
13082 and similarly for >= into !=. */ | 13539 and similarly for >= into !=. */ |
13083 if ((code == LT_EXPR || code == GE_EXPR) | 13540 if ((code == LT_EXPR || code == GE_EXPR) |
13084 && TYPE_UNSIGNED (TREE_TYPE (arg0)) | 13541 && TYPE_UNSIGNED (TREE_TYPE (arg0)) |
13085 && TREE_CODE (arg1) == LSHIFT_EXPR | 13542 && TREE_CODE (arg1) == LSHIFT_EXPR |
13086 && integer_onep (TREE_OPERAND (arg1, 0))) | 13543 && integer_onep (TREE_OPERAND (arg1, 0))) |
13087 return build2 (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type, | 13544 { |
13088 build2 (RSHIFT_EXPR, TREE_TYPE (arg0), arg0, | 13545 tem = build2 (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type, |
13089 TREE_OPERAND (arg1, 1)), | 13546 build2 (RSHIFT_EXPR, TREE_TYPE (arg0), arg0, |
13090 build_int_cst (TREE_TYPE (arg0), 0)); | 13547 TREE_OPERAND (arg1, 1)), |
13548 build_int_cst (TREE_TYPE (arg0), 0)); | |
13549 goto fold_binary_exit; | |
13550 } | |
13091 | 13551 |
13092 if ((code == LT_EXPR || code == GE_EXPR) | 13552 if ((code == LT_EXPR || code == GE_EXPR) |
13093 && TYPE_UNSIGNED (TREE_TYPE (arg0)) | 13553 && TYPE_UNSIGNED (TREE_TYPE (arg0)) |
13094 && CONVERT_EXPR_P (arg1) | 13554 && CONVERT_EXPR_P (arg1) |
13095 && TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR | 13555 && TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR |
13096 && integer_onep (TREE_OPERAND (TREE_OPERAND (arg1, 0), 0))) | 13556 && integer_onep (TREE_OPERAND (TREE_OPERAND (arg1, 0), 0))) |
13097 return | 13557 { |
13098 build2 (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type, | 13558 tem = build2 (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type, |
13099 fold_convert (TREE_TYPE (arg0), | 13559 fold_convert_loc (loc, TREE_TYPE (arg0), |
13100 build2 (RSHIFT_EXPR, TREE_TYPE (arg0), arg0, | 13560 build2 (RSHIFT_EXPR, |
13101 TREE_OPERAND (TREE_OPERAND (arg1, 0), | 13561 TREE_TYPE (arg0), arg0, |
13102 1))), | 13562 TREE_OPERAND (TREE_OPERAND (arg1, 0), |
13103 build_int_cst (TREE_TYPE (arg0), 0)); | 13563 1))), |
13564 build_int_cst (TREE_TYPE (arg0), 0)); | |
13565 goto fold_binary_exit; | |
13566 } | |
13104 | 13567 |
13105 return NULL_TREE; | 13568 return NULL_TREE; |
13106 | 13569 |
13107 case UNORDERED_EXPR: | 13570 case UNORDERED_EXPR: |
13108 case ORDERED_EXPR: | 13571 case ORDERED_EXPR: |
13125 && (code != LTGT_EXPR || ! flag_trapping_math)) | 13588 && (code != LTGT_EXPR || ! flag_trapping_math)) |
13126 { | 13589 { |
13127 t1 = (code == ORDERED_EXPR || code == LTGT_EXPR) | 13590 t1 = (code == ORDERED_EXPR || code == LTGT_EXPR) |
13128 ? integer_zero_node | 13591 ? integer_zero_node |
13129 : integer_one_node; | 13592 : integer_one_node; |
13130 return omit_one_operand (type, t1, arg1); | 13593 return omit_one_operand_loc (loc, type, t1, arg1); |
13131 } | 13594 } |
13132 | 13595 |
13133 /* If the second operand is NaN, the result is constant. */ | 13596 /* If the second operand is NaN, the result is constant. */ |
13134 if (TREE_CODE (arg1) == REAL_CST | 13597 if (TREE_CODE (arg1) == REAL_CST |
13135 && REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)) | 13598 && REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)) |
13136 && (code != LTGT_EXPR || ! flag_trapping_math)) | 13599 && (code != LTGT_EXPR || ! flag_trapping_math)) |
13137 { | 13600 { |
13138 t1 = (code == ORDERED_EXPR || code == LTGT_EXPR) | 13601 t1 = (code == ORDERED_EXPR || code == LTGT_EXPR) |
13139 ? integer_zero_node | 13602 ? integer_zero_node |
13140 : integer_one_node; | 13603 : integer_one_node; |
13141 return omit_one_operand (type, t1, arg0); | 13604 return omit_one_operand_loc (loc, type, t1, arg0); |
13142 } | 13605 } |
13143 | 13606 |
13144 /* Simplify unordered comparison of something with itself. */ | 13607 /* Simplify unordered comparison of something with itself. */ |
13145 if ((code == UNLE_EXPR || code == UNGE_EXPR || code == UNEQ_EXPR) | 13608 if ((code == UNLE_EXPR || code == UNGE_EXPR || code == UNEQ_EXPR) |
13146 && operand_equal_p (arg0, arg1, 0)) | 13609 && operand_equal_p (arg0, arg1, 0)) |
13159 | 13622 |
13160 if (TYPE_PRECISION (TREE_TYPE (targ1)) > TYPE_PRECISION (newtype)) | 13623 if (TYPE_PRECISION (TREE_TYPE (targ1)) > TYPE_PRECISION (newtype)) |
13161 newtype = TREE_TYPE (targ1); | 13624 newtype = TREE_TYPE (targ1); |
13162 | 13625 |
13163 if (TYPE_PRECISION (newtype) < TYPE_PRECISION (TREE_TYPE (arg0))) | 13626 if (TYPE_PRECISION (newtype) < TYPE_PRECISION (TREE_TYPE (arg0))) |
13164 return fold_build2 (code, type, fold_convert (newtype, targ0), | 13627 return fold_build2_loc (loc, code, type, |
13165 fold_convert (newtype, targ1)); | 13628 fold_convert_loc (loc, newtype, targ0), |
13629 fold_convert_loc (loc, newtype, targ1)); | |
13166 } | 13630 } |
13167 | 13631 |
13168 return NULL_TREE; | 13632 return NULL_TREE; |
13169 | 13633 |
13170 case COMPOUND_EXPR: | 13634 case COMPOUND_EXPR: |
13172 nor an integer constant expression. */ | 13636 nor an integer constant expression. */ |
13173 if (TREE_SIDE_EFFECTS (arg0) || TREE_CONSTANT (arg1)) | 13637 if (TREE_SIDE_EFFECTS (arg0) || TREE_CONSTANT (arg1)) |
13174 return NULL_TREE; | 13638 return NULL_TREE; |
13175 /* Don't let (0, 0) be null pointer constant. */ | 13639 /* Don't let (0, 0) be null pointer constant. */ |
13176 tem = integer_zerop (arg1) ? build1 (NOP_EXPR, type, arg1) | 13640 tem = integer_zerop (arg1) ? build1 (NOP_EXPR, type, arg1) |
13177 : fold_convert (type, arg1); | 13641 : fold_convert_loc (loc, type, arg1); |
13178 return pedantic_non_lvalue (tem); | 13642 return pedantic_non_lvalue_loc (loc, tem); |
13179 | 13643 |
13180 case COMPLEX_EXPR: | 13644 case COMPLEX_EXPR: |
13181 if ((TREE_CODE (arg0) == REAL_CST | 13645 if ((TREE_CODE (arg0) == REAL_CST |
13182 && TREE_CODE (arg1) == REAL_CST) | 13646 && TREE_CODE (arg1) == REAL_CST) |
13183 || (TREE_CODE (arg0) == INTEGER_CST | 13647 || (TREE_CODE (arg0) == INTEGER_CST |
13190 gcc_unreachable (); | 13654 gcc_unreachable (); |
13191 | 13655 |
13192 default: | 13656 default: |
13193 return NULL_TREE; | 13657 return NULL_TREE; |
13194 } /* switch (code) */ | 13658 } /* switch (code) */ |
13195 } | 13659 fold_binary_exit: |
13196 | 13660 protected_set_expr_location (tem, loc); |
13197 /* Callback for walk_tree, looking for LABEL_EXPR. | 13661 return tem; |
13198 Returns tree TP if it is LABEL_EXPR. Otherwise it returns NULL_TREE. | 13662 } |
13199 Do not check the sub-tree of GOTO_EXPR. */ | 13663 |
13664 /* Callback for walk_tree, looking for LABEL_EXPR. Return *TP if it is | |
13665 a LABEL_EXPR; otherwise return NULL_TREE. Do not check the subtrees | |
13666 of GOTO_EXPR. */ | |
13200 | 13667 |
13201 static tree | 13668 static tree |
13202 contains_label_1 (tree *tp, | 13669 contains_label_1 (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) |
13203 int *walk_subtrees, | |
13204 void *data ATTRIBUTE_UNUSED) | |
13205 { | 13670 { |
13206 switch (TREE_CODE (*tp)) | 13671 switch (TREE_CODE (*tp)) |
13207 { | 13672 { |
13208 case LABEL_EXPR: | 13673 case LABEL_EXPR: |
13209 return *tp; | 13674 return *tp; |
13675 | |
13210 case GOTO_EXPR: | 13676 case GOTO_EXPR: |
13211 *walk_subtrees = 0; | 13677 *walk_subtrees = 0; |
13212 /* no break */ | 13678 |
13679 /* ... fall through ... */ | |
13680 | |
13213 default: | 13681 default: |
13214 return NULL_TREE; | 13682 return NULL_TREE; |
13215 } | 13683 } |
13216 } | 13684 } |
13217 | 13685 |
13218 /* Checks whether the sub-tree ST contains a label LABEL_EXPR which is | 13686 /* Return whether the sub-tree ST contains a label which is accessible from |
13219 accessible from outside the sub-tree. Returns NULL_TREE if no | 13687 outside the sub-tree. */ |
13220 addressable label is found. */ | |
13221 | 13688 |
13222 static bool | 13689 static bool |
13223 contains_label_p (tree st) | 13690 contains_label_p (tree st) |
13224 { | 13691 { |
13225 return (walk_tree (&st, contains_label_1 , NULL, NULL) != NULL_TREE); | 13692 return |
13693 (walk_tree_without_duplicates (&st, contains_label_1 , NULL) != NULL_TREE); | |
13226 } | 13694 } |
13227 | 13695 |
13228 /* Fold a ternary expression of code CODE and type TYPE with operands | 13696 /* Fold a ternary expression of code CODE and type TYPE with operands |
13229 OP0, OP1, and OP2. Return the folded expression if folding is | 13697 OP0, OP1, and OP2. Return the folded expression if folding is |
13230 successful. Otherwise, return NULL_TREE. */ | 13698 successful. Otherwise, return NULL_TREE. */ |
13231 | 13699 |
13232 tree | 13700 tree |
13233 fold_ternary (enum tree_code code, tree type, tree op0, tree op1, tree op2) | 13701 fold_ternary_loc (location_t loc, enum tree_code code, tree type, |
13702 tree op0, tree op1, tree op2) | |
13234 { | 13703 { |
13235 tree tem; | 13704 tree tem; |
13236 tree arg0 = NULL_TREE, arg1 = NULL_TREE; | 13705 tree arg0 = NULL_TREE, arg1 = NULL_TREE; |
13237 enum tree_code_class kind = TREE_CODE_CLASS (code); | 13706 enum tree_code_class kind = TREE_CODE_CLASS (code); |
13238 | 13707 |
13288 Avoid throwing away that operand which contains label. */ | 13757 Avoid throwing away that operand which contains label. */ |
13289 if ((!TREE_SIDE_EFFECTS (unused_op) | 13758 if ((!TREE_SIDE_EFFECTS (unused_op) |
13290 || !contains_label_p (unused_op)) | 13759 || !contains_label_p (unused_op)) |
13291 && (! VOID_TYPE_P (TREE_TYPE (tem)) | 13760 && (! VOID_TYPE_P (TREE_TYPE (tem)) |
13292 || VOID_TYPE_P (type))) | 13761 || VOID_TYPE_P (type))) |
13293 return pedantic_non_lvalue (tem); | 13762 return pedantic_non_lvalue_loc (loc, tem); |
13294 return NULL_TREE; | 13763 return NULL_TREE; |
13295 } | 13764 } |
13296 if (operand_equal_p (arg1, op2, 0)) | 13765 if (operand_equal_p (arg1, op2, 0)) |
13297 return pedantic_omit_one_operand (type, arg1, arg0); | 13766 return pedantic_omit_one_operand_loc (loc, type, arg1, arg0); |
13298 | 13767 |
13299 /* If we have A op B ? A : C, we may be able to convert this to a | 13768 /* If we have A op B ? A : C, we may be able to convert this to a |
13300 simpler expression, depending on the operation and the values | 13769 simpler expression, depending on the operation and the values |
13301 of B and C. Signed zeros prevent all of these transformations, | 13770 of B and C. Signed zeros prevent all of these transformations, |
13302 for reasons given above each one. | 13771 for reasons given above each one. |
13305 if (COMPARISON_CLASS_P (arg0) | 13774 if (COMPARISON_CLASS_P (arg0) |
13306 && operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0), | 13775 && operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0), |
13307 arg1, TREE_OPERAND (arg0, 1)) | 13776 arg1, TREE_OPERAND (arg0, 1)) |
13308 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg1)))) | 13777 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg1)))) |
13309 { | 13778 { |
13310 tem = fold_cond_expr_with_comparison (type, arg0, op1, op2); | 13779 tem = fold_cond_expr_with_comparison (loc, type, arg0, op1, op2); |
13311 if (tem) | 13780 if (tem) |
13312 return tem; | 13781 return tem; |
13313 } | 13782 } |
13314 | 13783 |
13315 if (COMPARISON_CLASS_P (arg0) | 13784 if (COMPARISON_CLASS_P (arg0) |
13316 && operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0), | 13785 && operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0), |
13317 op2, | 13786 op2, |
13318 TREE_OPERAND (arg0, 1)) | 13787 TREE_OPERAND (arg0, 1)) |
13319 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (op2)))) | 13788 && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (op2)))) |
13320 { | 13789 { |
13321 tem = fold_truth_not_expr (arg0); | 13790 tem = fold_truth_not_expr (loc, arg0); |
13322 if (tem && COMPARISON_CLASS_P (tem)) | 13791 if (tem && COMPARISON_CLASS_P (tem)) |
13323 { | 13792 { |
13324 tem = fold_cond_expr_with_comparison (type, tem, op2, op1); | 13793 tem = fold_cond_expr_with_comparison (loc, type, tem, op2, op1); |
13325 if (tem) | 13794 if (tem) |
13326 return tem; | 13795 return tem; |
13327 } | 13796 } |
13328 } | 13797 } |
13329 | 13798 |
13333 && tree_swap_operands_p (op1, op2, false)) | 13802 && tree_swap_operands_p (op1, op2, false)) |
13334 { | 13803 { |
13335 /* See if this can be inverted. If it can't, possibly because | 13804 /* See if this can be inverted. If it can't, possibly because |
13336 it was a floating-point inequality comparison, don't do | 13805 it was a floating-point inequality comparison, don't do |
13337 anything. */ | 13806 anything. */ |
13338 tem = fold_truth_not_expr (arg0); | 13807 tem = fold_truth_not_expr (loc, arg0); |
13339 if (tem) | 13808 if (tem) |
13340 return fold_build3 (code, type, tem, op2, op1); | 13809 return fold_build3_loc (loc, code, type, tem, op2, op1); |
13341 } | 13810 } |
13342 | 13811 |
13343 /* Convert A ? 1 : 0 to simply A. */ | 13812 /* Convert A ? 1 : 0 to simply A. */ |
13344 if (integer_onep (op1) | 13813 if (integer_onep (op1) |
13345 && integer_zerop (op2) | 13814 && integer_zerop (op2) |
13346 /* If we try to convert OP0 to our type, the | 13815 /* If we try to convert OP0 to our type, the |
13347 call to fold will try to move the conversion inside | 13816 call to fold will try to move the conversion inside |
13348 a COND, which will recurse. In that case, the COND_EXPR | 13817 a COND, which will recurse. In that case, the COND_EXPR |
13349 is probably the best choice, so leave it alone. */ | 13818 is probably the best choice, so leave it alone. */ |
13350 && type == TREE_TYPE (arg0)) | 13819 && type == TREE_TYPE (arg0)) |
13351 return pedantic_non_lvalue (arg0); | 13820 return pedantic_non_lvalue_loc (loc, arg0); |
13352 | 13821 |
13353 /* Convert A ? 0 : 1 to !A. This prefers the use of NOT_EXPR | 13822 /* Convert A ? 0 : 1 to !A. This prefers the use of NOT_EXPR |
13354 over COND_EXPR in cases such as floating point comparisons. */ | 13823 over COND_EXPR in cases such as floating point comparisons. */ |
13355 if (integer_zerop (op1) | 13824 if (integer_zerop (op1) |
13356 && integer_onep (op2) | 13825 && integer_onep (op2) |
13357 && truth_value_p (TREE_CODE (arg0))) | 13826 && truth_value_p (TREE_CODE (arg0))) |
13358 return pedantic_non_lvalue (fold_convert (type, | 13827 return pedantic_non_lvalue_loc (loc, |
13359 invert_truthvalue (arg0))); | 13828 fold_convert_loc (loc, type, |
13829 invert_truthvalue_loc (loc, | |
13830 arg0))); | |
13360 | 13831 |
13361 /* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>). */ | 13832 /* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>). */ |
13362 if (TREE_CODE (arg0) == LT_EXPR | 13833 if (TREE_CODE (arg0) == LT_EXPR |
13363 && integer_zerop (TREE_OPERAND (arg0, 1)) | 13834 && integer_zerop (TREE_OPERAND (arg0, 1)) |
13364 && integer_zerop (op2) | 13835 && integer_zerop (op2) |
13409 | 13880 |
13410 if ((TREE_INT_CST_HIGH (arg1) & mask_hi) == mask_hi | 13881 if ((TREE_INT_CST_HIGH (arg1) & mask_hi) == mask_hi |
13411 && (TREE_INT_CST_LOW (arg1) & mask_lo) == mask_lo) | 13882 && (TREE_INT_CST_LOW (arg1) & mask_lo) == mask_lo) |
13412 { | 13883 { |
13413 tem_type = signed_type_for (TREE_TYPE (tem)); | 13884 tem_type = signed_type_for (TREE_TYPE (tem)); |
13414 tem = fold_convert (tem_type, tem); | 13885 tem = fold_convert_loc (loc, tem_type, tem); |
13415 } | 13886 } |
13416 else if ((TREE_INT_CST_HIGH (arg1) & mask_hi) == 0 | 13887 else if ((TREE_INT_CST_HIGH (arg1) & mask_hi) == 0 |
13417 && (TREE_INT_CST_LOW (arg1) & mask_lo) == 0) | 13888 && (TREE_INT_CST_LOW (arg1) & mask_lo) == 0) |
13418 { | 13889 { |
13419 tem_type = unsigned_type_for (TREE_TYPE (tem)); | 13890 tem_type = unsigned_type_for (TREE_TYPE (tem)); |
13420 tem = fold_convert (tem_type, tem); | 13891 tem = fold_convert_loc (loc, tem_type, tem); |
13421 } | 13892 } |
13422 else | 13893 else |
13423 tem = NULL; | 13894 tem = NULL; |
13424 } | 13895 } |
13425 | 13896 |
13426 if (tem) | 13897 if (tem) |
13427 return fold_convert (type, | 13898 return |
13428 fold_build2 (BIT_AND_EXPR, | 13899 fold_convert_loc (loc, type, |
13429 TREE_TYPE (tem), tem, | 13900 fold_build2_loc (loc, BIT_AND_EXPR, |
13430 fold_convert (TREE_TYPE (tem), | 13901 TREE_TYPE (tem), tem, |
13431 arg1))); | 13902 fold_convert_loc (loc, |
13903 TREE_TYPE (tem), | |
13904 arg1))); | |
13432 } | 13905 } |
13433 | 13906 |
13434 /* (A >> N) & 1 ? (1 << N) : 0 is simply A & (1 << N). A & 1 was | 13907 /* (A >> N) & 1 ? (1 << N) : 0 is simply A & (1 << N). A & 1 was |
13435 already handled above. */ | 13908 already handled above. */ |
13436 if (TREE_CODE (arg0) == BIT_AND_EXPR | 13909 if (TREE_CODE (arg0) == BIT_AND_EXPR |
13442 STRIP_NOPS (tem); | 13915 STRIP_NOPS (tem); |
13443 if (TREE_CODE (tem) == RSHIFT_EXPR | 13916 if (TREE_CODE (tem) == RSHIFT_EXPR |
13444 && TREE_CODE (TREE_OPERAND (tem, 1)) == INTEGER_CST | 13917 && TREE_CODE (TREE_OPERAND (tem, 1)) == INTEGER_CST |
13445 && (unsigned HOST_WIDE_INT) tree_log2 (arg1) == | 13918 && (unsigned HOST_WIDE_INT) tree_log2 (arg1) == |
13446 TREE_INT_CST_LOW (TREE_OPERAND (tem, 1))) | 13919 TREE_INT_CST_LOW (TREE_OPERAND (tem, 1))) |
13447 return fold_build2 (BIT_AND_EXPR, type, | 13920 return fold_build2_loc (loc, BIT_AND_EXPR, type, |
13448 TREE_OPERAND (tem, 0), arg1); | 13921 TREE_OPERAND (tem, 0), arg1); |
13449 } | 13922 } |
13450 | 13923 |
13451 /* A & N ? N : 0 is simply A & N if N is a power of two. This | 13924 /* A & N ? N : 0 is simply A & N if N is a power of two. This |
13452 is probably obsolete because the first operand should be a | 13925 is probably obsolete because the first operand should be a |
13457 && integer_zerop (TREE_OPERAND (arg0, 1)) | 13930 && integer_zerop (TREE_OPERAND (arg0, 1)) |
13458 && integer_pow2p (arg1) | 13931 && integer_pow2p (arg1) |
13459 && TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_AND_EXPR | 13932 && TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_AND_EXPR |
13460 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1), | 13933 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1), |
13461 arg1, OEP_ONLY_CONST)) | 13934 arg1, OEP_ONLY_CONST)) |
13462 return pedantic_non_lvalue (fold_convert (type, | 13935 return pedantic_non_lvalue_loc (loc, |
13463 TREE_OPERAND (arg0, 0))); | 13936 fold_convert_loc (loc, type, |
13937 TREE_OPERAND (arg0, 0))); | |
13464 | 13938 |
13465 /* Convert A ? B : 0 into A && B if A and B are truth values. */ | 13939 /* Convert A ? B : 0 into A && B if A and B are truth values. */ |
13466 if (integer_zerop (op2) | 13940 if (integer_zerop (op2) |
13467 && truth_value_p (TREE_CODE (arg0)) | 13941 && truth_value_p (TREE_CODE (arg0)) |
13468 && truth_value_p (TREE_CODE (arg1))) | 13942 && truth_value_p (TREE_CODE (arg1))) |
13469 return fold_build2 (TRUTH_ANDIF_EXPR, type, | 13943 return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type, |
13470 fold_convert (type, arg0), | 13944 fold_convert_loc (loc, type, arg0), |
13471 arg1); | 13945 arg1); |
13472 | 13946 |
13473 /* Convert A ? B : 1 into !A || B if A and B are truth values. */ | 13947 /* Convert A ? B : 1 into !A || B if A and B are truth values. */ |
13474 if (integer_onep (op2) | 13948 if (integer_onep (op2) |
13475 && truth_value_p (TREE_CODE (arg0)) | 13949 && truth_value_p (TREE_CODE (arg0)) |
13476 && truth_value_p (TREE_CODE (arg1))) | 13950 && truth_value_p (TREE_CODE (arg1))) |
13477 { | 13951 { |
13478 /* Only perform transformation if ARG0 is easily inverted. */ | 13952 /* Only perform transformation if ARG0 is easily inverted. */ |
13479 tem = fold_truth_not_expr (arg0); | 13953 tem = fold_truth_not_expr (loc, arg0); |
13480 if (tem) | 13954 if (tem) |
13481 return fold_build2 (TRUTH_ORIF_EXPR, type, | 13955 return fold_build2_loc (loc, TRUTH_ORIF_EXPR, type, |
13482 fold_convert (type, tem), | 13956 fold_convert_loc (loc, type, tem), |
13483 arg1); | 13957 arg1); |
13484 } | 13958 } |
13485 | 13959 |
13486 /* Convert A ? 0 : B into !A && B if A and B are truth values. */ | 13960 /* Convert A ? 0 : B into !A && B if A and B are truth values. */ |
13487 if (integer_zerop (arg1) | 13961 if (integer_zerop (arg1) |
13488 && truth_value_p (TREE_CODE (arg0)) | 13962 && truth_value_p (TREE_CODE (arg0)) |
13489 && truth_value_p (TREE_CODE (op2))) | 13963 && truth_value_p (TREE_CODE (op2))) |
13490 { | 13964 { |
13491 /* Only perform transformation if ARG0 is easily inverted. */ | 13965 /* Only perform transformation if ARG0 is easily inverted. */ |
13492 tem = fold_truth_not_expr (arg0); | 13966 tem = fold_truth_not_expr (loc, arg0); |
13493 if (tem) | 13967 if (tem) |
13494 return fold_build2 (TRUTH_ANDIF_EXPR, type, | 13968 return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type, |
13495 fold_convert (type, tem), | 13969 fold_convert_loc (loc, type, tem), |
13496 op2); | 13970 op2); |
13497 } | 13971 } |
13498 | 13972 |
13499 /* Convert A ? 1 : B into A || B if A and B are truth values. */ | 13973 /* Convert A ? 1 : B into A || B if A and B are truth values. */ |
13500 if (integer_onep (arg1) | 13974 if (integer_onep (arg1) |
13501 && truth_value_p (TREE_CODE (arg0)) | 13975 && truth_value_p (TREE_CODE (arg0)) |
13502 && truth_value_p (TREE_CODE (op2))) | 13976 && truth_value_p (TREE_CODE (op2))) |
13503 return fold_build2 (TRUTH_ORIF_EXPR, type, | 13977 return fold_build2_loc (loc, TRUTH_ORIF_EXPR, type, |
13504 fold_convert (type, arg0), | 13978 fold_convert_loc (loc, type, arg0), |
13505 op2); | 13979 op2); |
13506 | 13980 |
13507 return NULL_TREE; | 13981 return NULL_TREE; |
13508 | 13982 |
13509 case CALL_EXPR: | 13983 case CALL_EXPR: |
13540 while (idx-- > 0 && elements) | 14014 while (idx-- > 0 && elements) |
13541 elements = TREE_CHAIN (elements); | 14015 elements = TREE_CHAIN (elements); |
13542 if (elements) | 14016 if (elements) |
13543 return TREE_VALUE (elements); | 14017 return TREE_VALUE (elements); |
13544 else | 14018 else |
13545 return fold_convert (type, integer_zero_node); | 14019 return fold_convert_loc (loc, type, integer_zero_node); |
13546 } | 14020 } |
13547 } | 14021 } |
13548 | 14022 |
13549 /* A bit-field-ref that referenced the full argument can be stripped. */ | 14023 /* A bit-field-ref that referenced the full argument can be stripped. */ |
13550 if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)) | 14024 if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)) |
13551 && TYPE_PRECISION (TREE_TYPE (arg0)) == tree_low_cst (arg1, 1) | 14025 && TYPE_PRECISION (TREE_TYPE (arg0)) == tree_low_cst (arg1, 1) |
13552 && integer_zerop (op2)) | 14026 && integer_zerop (op2)) |
13553 return fold_convert (type, arg0); | 14027 return fold_convert_loc (loc, type, arg0); |
13554 | 14028 |
13555 return NULL_TREE; | 14029 return NULL_TREE; |
13556 | 14030 |
13557 default: | 14031 default: |
13558 return NULL_TREE; | 14032 return NULL_TREE; |
13577 { | 14051 { |
13578 const tree t = expr; | 14052 const tree t = expr; |
13579 enum tree_code code = TREE_CODE (t); | 14053 enum tree_code code = TREE_CODE (t); |
13580 enum tree_code_class kind = TREE_CODE_CLASS (code); | 14054 enum tree_code_class kind = TREE_CODE_CLASS (code); |
13581 tree tem; | 14055 tree tem; |
14056 location_t loc = EXPR_LOCATION (expr); | |
13582 | 14057 |
13583 /* Return right away if a constant. */ | 14058 /* Return right away if a constant. */ |
13584 if (kind == tcc_constant) | 14059 if (kind == tcc_constant) |
13585 return t; | 14060 return t; |
13586 | 14061 |
13588 treated specially. */ | 14063 treated specially. */ |
13589 if (kind == tcc_vl_exp) | 14064 if (kind == tcc_vl_exp) |
13590 { | 14065 { |
13591 if (code == CALL_EXPR) | 14066 if (code == CALL_EXPR) |
13592 { | 14067 { |
13593 tem = fold_call_expr (expr, false); | 14068 tem = fold_call_expr (loc, expr, false); |
13594 return tem ? tem : expr; | 14069 return tem ? tem : expr; |
13595 } | 14070 } |
13596 return expr; | 14071 return expr; |
13597 } | 14072 } |
13598 | 14073 |
13603 | 14078 |
13604 switch (TREE_CODE_LENGTH (code)) | 14079 switch (TREE_CODE_LENGTH (code)) |
13605 { | 14080 { |
13606 case 1: | 14081 case 1: |
13607 op0 = TREE_OPERAND (t, 0); | 14082 op0 = TREE_OPERAND (t, 0); |
13608 tem = fold_unary (code, type, op0); | 14083 tem = fold_unary_loc (loc, code, type, op0); |
13609 return tem ? tem : expr; | 14084 return tem ? tem : expr; |
13610 case 2: | 14085 case 2: |
13611 op0 = TREE_OPERAND (t, 0); | 14086 op0 = TREE_OPERAND (t, 0); |
13612 op1 = TREE_OPERAND (t, 1); | 14087 op1 = TREE_OPERAND (t, 1); |
13613 tem = fold_binary (code, type, op0, op1); | 14088 tem = fold_binary_loc (loc, code, type, op0, op1); |
13614 return tem ? tem : expr; | 14089 return tem ? tem : expr; |
13615 case 3: | 14090 case 3: |
13616 op0 = TREE_OPERAND (t, 0); | 14091 op0 = TREE_OPERAND (t, 0); |
13617 op1 = TREE_OPERAND (t, 1); | 14092 op1 = TREE_OPERAND (t, 1); |
13618 op2 = TREE_OPERAND (t, 2); | 14093 op2 = TREE_OPERAND (t, 2); |
13619 tem = fold_ternary (code, type, op0, op1, op2); | 14094 tem = fold_ternary_loc (loc, code, type, op0, op1, op2); |
13620 return tem ? tem : expr; | 14095 return tem ? tem : expr; |
13621 default: | 14096 default: |
13622 break; | 14097 break; |
13623 } | 14098 } |
13624 } | 14099 } |
13738 { | 14213 { |
13739 const void **slot; | 14214 const void **slot; |
13740 enum tree_code code; | 14215 enum tree_code code; |
13741 union tree_node buf; | 14216 union tree_node buf; |
13742 int i, len; | 14217 int i, len; |
13743 | 14218 |
13744 recursive_label: | 14219 recursive_label: |
13745 | 14220 |
13746 gcc_assert ((sizeof (struct tree_exp) + 5 * sizeof (tree) | 14221 gcc_assert ((sizeof (struct tree_exp) + 5 * sizeof (tree) |
13747 <= sizeof (struct tree_function_decl)) | 14222 <= sizeof (struct tree_function_decl)) |
13748 && sizeof (struct tree_type) <= sizeof (struct tree_function_decl)); | 14223 && sizeof (struct tree_type) <= sizeof (struct tree_function_decl)); |
13848 fold_checksum_tree (DECL_ABSTRACT_ORIGIN (expr), ctx, ht); | 14323 fold_checksum_tree (DECL_ABSTRACT_ORIGIN (expr), ctx, ht); |
13849 fold_checksum_tree (DECL_ATTRIBUTES (expr), ctx, ht); | 14324 fold_checksum_tree (DECL_ATTRIBUTES (expr), ctx, ht); |
13850 } | 14325 } |
13851 if (CODE_CONTAINS_STRUCT (TREE_CODE (expr), TS_DECL_WITH_VIS)) | 14326 if (CODE_CONTAINS_STRUCT (TREE_CODE (expr), TS_DECL_WITH_VIS)) |
13852 fold_checksum_tree (DECL_SECTION_NAME (expr), ctx, ht); | 14327 fold_checksum_tree (DECL_SECTION_NAME (expr), ctx, ht); |
13853 | 14328 |
13854 if (CODE_CONTAINS_STRUCT (TREE_CODE (expr), TS_DECL_NON_COMMON)) | 14329 if (CODE_CONTAINS_STRUCT (TREE_CODE (expr), TS_DECL_NON_COMMON)) |
13855 { | 14330 { |
13856 fold_checksum_tree (DECL_VINDEX (expr), ctx, ht); | 14331 fold_checksum_tree (DECL_VINDEX (expr), ctx, ht); |
13857 fold_checksum_tree (DECL_RESULT_FLD (expr), ctx, ht); | 14332 fold_checksum_tree (DECL_RESULT_FLD (expr), ctx, ht); |
13858 fold_checksum_tree (DECL_ARGUMENT_FLD (expr), ctx, ht); | 14333 fold_checksum_tree (DECL_ARGUMENT_FLD (expr), ctx, ht); |
13893 { | 14368 { |
13894 int i; | 14369 int i; |
13895 unsigned char checksum[16]; | 14370 unsigned char checksum[16]; |
13896 struct md5_ctx ctx; | 14371 struct md5_ctx ctx; |
13897 htab_t ht = htab_create (32, htab_hash_pointer, htab_eq_pointer, NULL); | 14372 htab_t ht = htab_create (32, htab_hash_pointer, htab_eq_pointer, NULL); |
13898 | 14373 |
13899 md5_init_ctx (&ctx); | 14374 md5_init_ctx (&ctx); |
13900 fold_checksum_tree (t, &ctx, ht); | 14375 fold_checksum_tree (t, &ctx, ht); |
13901 md5_finish_ctx (&ctx, checksum); | 14376 md5_finish_ctx (&ctx, checksum); |
13902 htab_empty (ht); | 14377 htab_empty (ht); |
13903 | 14378 |
13908 } | 14383 } |
13909 | 14384 |
13910 #endif | 14385 #endif |
13911 | 14386 |
13912 /* Fold a unary tree expression with code CODE of type TYPE with an | 14387 /* Fold a unary tree expression with code CODE of type TYPE with an |
13913 operand OP0. Return a folded expression if successful. Otherwise, | 14388 operand OP0. LOC is the location of the resulting expression. |
13914 return a tree expression with code CODE of type TYPE with an | 14389 Return a folded expression if successful. Otherwise, return a tree |
13915 operand OP0. */ | 14390 expression with code CODE of type TYPE with an operand OP0. */ |
13916 | 14391 |
13917 tree | 14392 tree |
13918 fold_build1_stat (enum tree_code code, tree type, tree op0 MEM_STAT_DECL) | 14393 fold_build1_stat_loc (location_t loc, |
14394 enum tree_code code, tree type, tree op0 MEM_STAT_DECL) | |
13919 { | 14395 { |
13920 tree tem; | 14396 tree tem; |
13921 #ifdef ENABLE_FOLD_CHECKING | 14397 #ifdef ENABLE_FOLD_CHECKING |
13922 unsigned char checksum_before[16], checksum_after[16]; | 14398 unsigned char checksum_before[16], checksum_after[16]; |
13923 struct md5_ctx ctx; | 14399 struct md5_ctx ctx; |
13927 md5_init_ctx (&ctx); | 14403 md5_init_ctx (&ctx); |
13928 fold_checksum_tree (op0, &ctx, ht); | 14404 fold_checksum_tree (op0, &ctx, ht); |
13929 md5_finish_ctx (&ctx, checksum_before); | 14405 md5_finish_ctx (&ctx, checksum_before); |
13930 htab_empty (ht); | 14406 htab_empty (ht); |
13931 #endif | 14407 #endif |
13932 | 14408 |
13933 tem = fold_unary (code, type, op0); | 14409 tem = fold_unary_loc (loc, code, type, op0); |
13934 if (!tem) | 14410 if (!tem) |
13935 tem = build1_stat (code, type, op0 PASS_MEM_STAT); | 14411 { |
13936 | 14412 tem = build1_stat (code, type, op0 PASS_MEM_STAT); |
14413 SET_EXPR_LOCATION (tem, loc); | |
14414 } | |
14415 | |
13937 #ifdef ENABLE_FOLD_CHECKING | 14416 #ifdef ENABLE_FOLD_CHECKING |
13938 md5_init_ctx (&ctx); | 14417 md5_init_ctx (&ctx); |
13939 fold_checksum_tree (op0, &ctx, ht); | 14418 fold_checksum_tree (op0, &ctx, ht); |
13940 md5_finish_ctx (&ctx, checksum_after); | 14419 md5_finish_ctx (&ctx, checksum_after); |
13941 htab_delete (ht); | 14420 htab_delete (ht); |
13945 #endif | 14424 #endif |
13946 return tem; | 14425 return tem; |
13947 } | 14426 } |
13948 | 14427 |
13949 /* Fold a binary tree expression with code CODE of type TYPE with | 14428 /* Fold a binary tree expression with code CODE of type TYPE with |
13950 operands OP0 and OP1. Return a folded expression if successful. | 14429 operands OP0 and OP1. LOC is the location of the resulting |
13951 Otherwise, return a tree expression with code CODE of type TYPE | 14430 expression. Return a folded expression if successful. Otherwise, |
13952 with operands OP0 and OP1. */ | 14431 return a tree expression with code CODE of type TYPE with operands |
14432 OP0 and OP1. */ | |
13953 | 14433 |
13954 tree | 14434 tree |
13955 fold_build2_stat (enum tree_code code, tree type, tree op0, tree op1 | 14435 fold_build2_stat_loc (location_t loc, |
13956 MEM_STAT_DECL) | 14436 enum tree_code code, tree type, tree op0, tree op1 |
14437 MEM_STAT_DECL) | |
13957 { | 14438 { |
13958 tree tem; | 14439 tree tem; |
13959 #ifdef ENABLE_FOLD_CHECKING | 14440 #ifdef ENABLE_FOLD_CHECKING |
13960 unsigned char checksum_before_op0[16], | 14441 unsigned char checksum_before_op0[16], |
13961 checksum_before_op1[16], | 14442 checksum_before_op1[16], |
13974 fold_checksum_tree (op1, &ctx, ht); | 14455 fold_checksum_tree (op1, &ctx, ht); |
13975 md5_finish_ctx (&ctx, checksum_before_op1); | 14456 md5_finish_ctx (&ctx, checksum_before_op1); |
13976 htab_empty (ht); | 14457 htab_empty (ht); |
13977 #endif | 14458 #endif |
13978 | 14459 |
13979 tem = fold_binary (code, type, op0, op1); | 14460 tem = fold_binary_loc (loc, code, type, op0, op1); |
13980 if (!tem) | 14461 if (!tem) |
13981 tem = build2_stat (code, type, op0, op1 PASS_MEM_STAT); | 14462 { |
13982 | 14463 tem = build2_stat (code, type, op0, op1 PASS_MEM_STAT); |
14464 SET_EXPR_LOCATION (tem, loc); | |
14465 } | |
14466 | |
13983 #ifdef ENABLE_FOLD_CHECKING | 14467 #ifdef ENABLE_FOLD_CHECKING |
13984 md5_init_ctx (&ctx); | 14468 md5_init_ctx (&ctx); |
13985 fold_checksum_tree (op0, &ctx, ht); | 14469 fold_checksum_tree (op0, &ctx, ht); |
13986 md5_finish_ctx (&ctx, checksum_after_op0); | 14470 md5_finish_ctx (&ctx, checksum_after_op0); |
13987 htab_empty (ht); | 14471 htab_empty (ht); |
13988 | 14472 |
13989 if (memcmp (checksum_before_op0, checksum_after_op0, 16)) | 14473 if (memcmp (checksum_before_op0, checksum_after_op0, 16)) |
13990 fold_check_failed (op0, tem); | 14474 fold_check_failed (op0, tem); |
13991 | 14475 |
13992 md5_init_ctx (&ctx); | 14476 md5_init_ctx (&ctx); |
13993 fold_checksum_tree (op1, &ctx, ht); | 14477 fold_checksum_tree (op1, &ctx, ht); |
13994 md5_finish_ctx (&ctx, checksum_after_op1); | 14478 md5_finish_ctx (&ctx, checksum_after_op1); |
13995 htab_delete (ht); | 14479 htab_delete (ht); |
13996 | 14480 |
14004 operands OP0, OP1, and OP2. Return a folded expression if | 14488 operands OP0, OP1, and OP2. Return a folded expression if |
14005 successful. Otherwise, return a tree expression with code CODE of | 14489 successful. Otherwise, return a tree expression with code CODE of |
14006 type TYPE with operands OP0, OP1, and OP2. */ | 14490 type TYPE with operands OP0, OP1, and OP2. */ |
14007 | 14491 |
14008 tree | 14492 tree |
14009 fold_build3_stat (enum tree_code code, tree type, tree op0, tree op1, tree op2 | 14493 fold_build3_stat_loc (location_t loc, enum tree_code code, tree type, |
14010 MEM_STAT_DECL) | 14494 tree op0, tree op1, tree op2 MEM_STAT_DECL) |
14011 { | 14495 { |
14012 tree tem; | 14496 tree tem; |
14013 #ifdef ENABLE_FOLD_CHECKING | 14497 #ifdef ENABLE_FOLD_CHECKING |
14014 unsigned char checksum_before_op0[16], | 14498 unsigned char checksum_before_op0[16], |
14015 checksum_before_op1[16], | 14499 checksum_before_op1[16], |
14036 md5_finish_ctx (&ctx, checksum_before_op2); | 14520 md5_finish_ctx (&ctx, checksum_before_op2); |
14037 htab_empty (ht); | 14521 htab_empty (ht); |
14038 #endif | 14522 #endif |
14039 | 14523 |
14040 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); | 14524 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
14041 tem = fold_ternary (code, type, op0, op1, op2); | 14525 tem = fold_ternary_loc (loc, code, type, op0, op1, op2); |
14042 if (!tem) | 14526 if (!tem) |
14043 tem = build3_stat (code, type, op0, op1, op2 PASS_MEM_STAT); | 14527 { |
14044 | 14528 tem = build3_stat (code, type, op0, op1, op2 PASS_MEM_STAT); |
14529 SET_EXPR_LOCATION (tem, loc); | |
14530 } | |
14531 | |
14045 #ifdef ENABLE_FOLD_CHECKING | 14532 #ifdef ENABLE_FOLD_CHECKING |
14046 md5_init_ctx (&ctx); | 14533 md5_init_ctx (&ctx); |
14047 fold_checksum_tree (op0, &ctx, ht); | 14534 fold_checksum_tree (op0, &ctx, ht); |
14048 md5_finish_ctx (&ctx, checksum_after_op0); | 14535 md5_finish_ctx (&ctx, checksum_after_op0); |
14049 htab_empty (ht); | 14536 htab_empty (ht); |
14050 | 14537 |
14051 if (memcmp (checksum_before_op0, checksum_after_op0, 16)) | 14538 if (memcmp (checksum_before_op0, checksum_after_op0, 16)) |
14052 fold_check_failed (op0, tem); | 14539 fold_check_failed (op0, tem); |
14053 | 14540 |
14054 md5_init_ctx (&ctx); | 14541 md5_init_ctx (&ctx); |
14055 fold_checksum_tree (op1, &ctx, ht); | 14542 fold_checksum_tree (op1, &ctx, ht); |
14056 md5_finish_ctx (&ctx, checksum_after_op1); | 14543 md5_finish_ctx (&ctx, checksum_after_op1); |
14057 htab_empty (ht); | 14544 htab_empty (ht); |
14058 | 14545 |
14059 if (memcmp (checksum_before_op1, checksum_after_op1, 16)) | 14546 if (memcmp (checksum_before_op1, checksum_after_op1, 16)) |
14060 fold_check_failed (op1, tem); | 14547 fold_check_failed (op1, tem); |
14061 | 14548 |
14062 md5_init_ctx (&ctx); | 14549 md5_init_ctx (&ctx); |
14063 fold_checksum_tree (op2, &ctx, ht); | 14550 fold_checksum_tree (op2, &ctx, ht); |
14064 md5_finish_ctx (&ctx, checksum_after_op2); | 14551 md5_finish_ctx (&ctx, checksum_after_op2); |
14065 htab_delete (ht); | 14552 htab_delete (ht); |
14066 | 14553 |
14074 arguments in ARGARRAY, and a null static chain. | 14561 arguments in ARGARRAY, and a null static chain. |
14075 Return a folded expression if successful. Otherwise, return a CALL_EXPR | 14562 Return a folded expression if successful. Otherwise, return a CALL_EXPR |
14076 of type TYPE from the given operands as constructed by build_call_array. */ | 14563 of type TYPE from the given operands as constructed by build_call_array. */ |
14077 | 14564 |
14078 tree | 14565 tree |
14079 fold_build_call_array (tree type, tree fn, int nargs, tree *argarray) | 14566 fold_build_call_array_loc (location_t loc, tree type, tree fn, |
14567 int nargs, tree *argarray) | |
14080 { | 14568 { |
14081 tree tem; | 14569 tree tem; |
14082 #ifdef ENABLE_FOLD_CHECKING | 14570 #ifdef ENABLE_FOLD_CHECKING |
14083 unsigned char checksum_before_fn[16], | 14571 unsigned char checksum_before_fn[16], |
14084 checksum_before_arglist[16], | 14572 checksum_before_arglist[16], |
14099 fold_checksum_tree (argarray[i], &ctx, ht); | 14587 fold_checksum_tree (argarray[i], &ctx, ht); |
14100 md5_finish_ctx (&ctx, checksum_before_arglist); | 14588 md5_finish_ctx (&ctx, checksum_before_arglist); |
14101 htab_empty (ht); | 14589 htab_empty (ht); |
14102 #endif | 14590 #endif |
14103 | 14591 |
14104 tem = fold_builtin_call_array (type, fn, nargs, argarray); | 14592 tem = fold_builtin_call_array (loc, type, fn, nargs, argarray); |
14105 | 14593 |
14106 #ifdef ENABLE_FOLD_CHECKING | 14594 #ifdef ENABLE_FOLD_CHECKING |
14107 md5_init_ctx (&ctx); | 14595 md5_init_ctx (&ctx); |
14108 fold_checksum_tree (fn, &ctx, ht); | 14596 fold_checksum_tree (fn, &ctx, ht); |
14109 md5_finish_ctx (&ctx, checksum_after_fn); | 14597 md5_finish_ctx (&ctx, checksum_after_fn); |
14110 htab_empty (ht); | 14598 htab_empty (ht); |
14111 | 14599 |
14112 if (memcmp (checksum_before_fn, checksum_after_fn, 16)) | 14600 if (memcmp (checksum_before_fn, checksum_after_fn, 16)) |
14113 fold_check_failed (fn, tem); | 14601 fold_check_failed (fn, tem); |
14114 | 14602 |
14115 md5_init_ctx (&ctx); | 14603 md5_init_ctx (&ctx); |
14116 for (i = 0; i < nargs; i++) | 14604 for (i = 0; i < nargs; i++) |
14117 fold_checksum_tree (argarray[i], &ctx, ht); | 14605 fold_checksum_tree (argarray[i], &ctx, ht); |
14118 md5_finish_ctx (&ctx, checksum_after_arglist); | 14606 md5_finish_ctx (&ctx, checksum_after_arglist); |
14119 htab_delete (ht); | 14607 htab_delete (ht); |
14146 flag_rounding_math = saved_rounding_math;\ | 14634 flag_rounding_math = saved_rounding_math;\ |
14147 flag_trapv = saved_trapv;\ | 14635 flag_trapv = saved_trapv;\ |
14148 folding_initializer = saved_folding_initializer; | 14636 folding_initializer = saved_folding_initializer; |
14149 | 14637 |
14150 tree | 14638 tree |
14151 fold_build1_initializer (enum tree_code code, tree type, tree op) | 14639 fold_build1_initializer_loc (location_t loc, enum tree_code code, |
14640 tree type, tree op) | |
14152 { | 14641 { |
14153 tree result; | 14642 tree result; |
14154 START_FOLD_INIT; | 14643 START_FOLD_INIT; |
14155 | 14644 |
14156 result = fold_build1 (code, type, op); | 14645 result = fold_build1_loc (loc, code, type, op); |
14157 | 14646 |
14158 END_FOLD_INIT; | 14647 END_FOLD_INIT; |
14159 return result; | 14648 return result; |
14160 } | 14649 } |
14161 | 14650 |
14162 tree | 14651 tree |
14163 fold_build2_initializer (enum tree_code code, tree type, tree op0, tree op1) | 14652 fold_build2_initializer_loc (location_t loc, enum tree_code code, |
14653 tree type, tree op0, tree op1) | |
14164 { | 14654 { |
14165 tree result; | 14655 tree result; |
14166 START_FOLD_INIT; | 14656 START_FOLD_INIT; |
14167 | 14657 |
14168 result = fold_build2 (code, type, op0, op1); | 14658 result = fold_build2_loc (loc, code, type, op0, op1); |
14169 | 14659 |
14170 END_FOLD_INIT; | 14660 END_FOLD_INIT; |
14171 return result; | 14661 return result; |
14172 } | 14662 } |
14173 | 14663 |
14174 tree | 14664 tree |
14175 fold_build3_initializer (enum tree_code code, tree type, tree op0, tree op1, | 14665 fold_build3_initializer_loc (location_t loc, enum tree_code code, |
14176 tree op2) | 14666 tree type, tree op0, tree op1, tree op2) |
14177 { | 14667 { |
14178 tree result; | 14668 tree result; |
14179 START_FOLD_INIT; | 14669 START_FOLD_INIT; |
14180 | 14670 |
14181 result = fold_build3 (code, type, op0, op1, op2); | 14671 result = fold_build3_loc (loc, code, type, op0, op1, op2); |
14182 | 14672 |
14183 END_FOLD_INIT; | 14673 END_FOLD_INIT; |
14184 return result; | 14674 return result; |
14185 } | 14675 } |
14186 | 14676 |
14187 tree | 14677 tree |
14188 fold_build_call_array_initializer (tree type, tree fn, | 14678 fold_build_call_array_initializer_loc (location_t loc, tree type, tree fn, |
14189 int nargs, tree *argarray) | 14679 int nargs, tree *argarray) |
14190 { | 14680 { |
14191 tree result; | 14681 tree result; |
14192 START_FOLD_INIT; | 14682 START_FOLD_INIT; |
14193 | 14683 |
14194 result = fold_build_call_array (type, fn, nargs, argarray); | 14684 result = fold_build_call_array_loc (loc, type, fn, nargs, argarray); |
14195 | 14685 |
14196 END_FOLD_INIT; | 14686 END_FOLD_INIT; |
14197 return result; | 14687 return result; |
14198 } | 14688 } |
14199 | 14689 |
14453 both unsigned and their total bits is shorter than the result. */ | 14943 both unsigned and their total bits is shorter than the result. */ |
14454 if (TREE_CODE (type) == INTEGER_TYPE | 14944 if (TREE_CODE (type) == INTEGER_TYPE |
14455 && (TREE_CODE (op0) == NOP_EXPR || TREE_CODE (op0) == INTEGER_CST) | 14945 && (TREE_CODE (op0) == NOP_EXPR || TREE_CODE (op0) == INTEGER_CST) |
14456 && (TREE_CODE (op1) == NOP_EXPR || TREE_CODE (op1) == INTEGER_CST)) | 14946 && (TREE_CODE (op1) == NOP_EXPR || TREE_CODE (op1) == INTEGER_CST)) |
14457 { | 14947 { |
14458 tree inner0 = (TREE_CODE (op0) == NOP_EXPR) | 14948 tree inner0 = (TREE_CODE (op0) == NOP_EXPR) |
14459 ? TREE_TYPE (TREE_OPERAND (op0, 0)) | 14949 ? TREE_TYPE (TREE_OPERAND (op0, 0)) |
14460 : TREE_TYPE (op0); | 14950 : TREE_TYPE (op0); |
14461 tree inner1 = (TREE_CODE (op1) == NOP_EXPR) | 14951 tree inner1 = (TREE_CODE (op1) == NOP_EXPR) |
14462 ? TREE_TYPE (TREE_OPERAND (op1, 0)) | 14952 ? TREE_TYPE (TREE_OPERAND (op1, 0)) |
14463 : TREE_TYPE (op1); | 14953 : TREE_TYPE (op1); |
14464 | 14954 |
14465 bool unsigned0 = TYPE_UNSIGNED (inner0); | 14955 bool unsigned0 = TYPE_UNSIGNED (inner0); |
14466 bool unsigned1 = TYPE_UNSIGNED (inner1); | 14956 bool unsigned1 = TYPE_UNSIGNED (inner1); |
14822 case CONSTRUCTOR: | 15312 case CONSTRUCTOR: |
14823 case OBJ_TYPE_REF: | 15313 case OBJ_TYPE_REF: |
14824 case ASSERT_EXPR: | 15314 case ASSERT_EXPR: |
14825 case ADDR_EXPR: | 15315 case ADDR_EXPR: |
14826 case WITH_SIZE_EXPR: | 15316 case WITH_SIZE_EXPR: |
14827 case EXC_PTR_EXPR: | |
14828 case SSA_NAME: | 15317 case SSA_NAME: |
14829 case FILTER_EXPR: | |
14830 return tree_single_nonnegative_warnv_p (t, strict_overflow_p); | 15318 return tree_single_nonnegative_warnv_p (t, strict_overflow_p); |
14831 | 15319 |
14832 default: | 15320 default: |
14833 return tree_invalid_nonnegative_warnv_p (t, strict_overflow_p); | 15321 return tree_invalid_nonnegative_warnv_p (t, strict_overflow_p); |
14834 } | 15322 } |
15023 tree base = get_base_address (TREE_OPERAND (t, 0)); | 15511 tree base = get_base_address (TREE_OPERAND (t, 0)); |
15024 | 15512 |
15025 if (!base) | 15513 if (!base) |
15026 return false; | 15514 return false; |
15027 | 15515 |
15028 /* Weak declarations may link to NULL. */ | 15516 /* Weak declarations may link to NULL. Other things may also be NULL |
15029 if (VAR_OR_FUNCTION_DECL_P (base)) | 15517 so protect with -fdelete-null-pointer-checks; but not variables |
15030 return !DECL_WEAK (base); | 15518 allocated on the stack. */ |
15519 if (DECL_P (base) | |
15520 && (flag_delete_null_pointer_checks | |
15521 || (TREE_CODE (base) == VAR_DECL && !TREE_STATIC (base)))) | |
15522 return !VAR_OR_FUNCTION_DECL_P (base) || !DECL_WEAK (base); | |
15031 | 15523 |
15032 /* Constants are never weak. */ | 15524 /* Constants are never weak. */ |
15033 if (CONSTANT_CLASS_P (base)) | 15525 if (CONSTANT_CLASS_P (base)) |
15034 return true; | 15526 return true; |
15035 | 15527 |
15112 case CONSTRUCTOR: | 15604 case CONSTRUCTOR: |
15113 case OBJ_TYPE_REF: | 15605 case OBJ_TYPE_REF: |
15114 case ASSERT_EXPR: | 15606 case ASSERT_EXPR: |
15115 case ADDR_EXPR: | 15607 case ADDR_EXPR: |
15116 case WITH_SIZE_EXPR: | 15608 case WITH_SIZE_EXPR: |
15117 case EXC_PTR_EXPR: | |
15118 case SSA_NAME: | 15609 case SSA_NAME: |
15119 case FILTER_EXPR: | |
15120 return tree_single_nonzero_warnv_p (t, strict_overflow_p); | 15610 return tree_single_nonzero_warnv_p (t, strict_overflow_p); |
15121 | 15611 |
15122 case COMPOUND_EXPR: | 15612 case COMPOUND_EXPR: |
15123 case MODIFY_EXPR: | 15613 case MODIFY_EXPR: |
15124 case BIND_EXPR: | 15614 case BIND_EXPR: |
15198 && TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE) | 15688 && TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE) |
15199 { | 15689 { |
15200 tree exp1 = TREE_OPERAND (exp, 0); | 15690 tree exp1 = TREE_OPERAND (exp, 0); |
15201 tree index; | 15691 tree index; |
15202 tree string; | 15692 tree string; |
15693 location_t loc = EXPR_LOCATION (exp); | |
15203 | 15694 |
15204 if (TREE_CODE (exp) == INDIRECT_REF) | 15695 if (TREE_CODE (exp) == INDIRECT_REF) |
15205 string = string_constant (exp1, &index); | 15696 string = string_constant (exp1, &index); |
15206 else | 15697 else |
15207 { | 15698 { |
15208 tree low_bound = array_ref_low_bound (exp); | 15699 tree low_bound = array_ref_low_bound (exp); |
15209 index = fold_convert (sizetype, TREE_OPERAND (exp, 1)); | 15700 index = fold_convert_loc (loc, sizetype, TREE_OPERAND (exp, 1)); |
15210 | 15701 |
15211 /* Optimize the special-case of a zero lower bound. | 15702 /* Optimize the special-case of a zero lower bound. |
15212 | 15703 |
15213 We convert the low_bound to sizetype to avoid some problems | 15704 We convert the low_bound to sizetype to avoid some problems |
15214 with constant folding. (E.g. suppose the lower bound is 1, | 15705 with constant folding. (E.g. suppose the lower bound is 1, |
15215 and its mode is QI. Without the conversion,l (ARRAY | 15706 and its mode is QI. Without the conversion,l (ARRAY |
15216 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1)) | 15707 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1)) |
15217 +INDEX), which becomes (ARRAY+255+INDEX). Oops!) */ | 15708 +INDEX), which becomes (ARRAY+255+INDEX). Oops!) */ |
15218 if (! integer_zerop (low_bound)) | 15709 if (! integer_zerop (low_bound)) |
15219 index = size_diffop (index, fold_convert (sizetype, low_bound)); | 15710 index = size_diffop_loc (loc, index, |
15711 fold_convert_loc (loc, sizetype, low_bound)); | |
15220 | 15712 |
15221 string = exp1; | 15713 string = exp1; |
15222 } | 15714 } |
15223 | 15715 |
15224 if (string | 15716 if (string |
15272 &(TREE_FIXED_CST (arg0)), NULL, | 15764 &(TREE_FIXED_CST (arg0)), NULL, |
15273 TYPE_SATURATING (type)); | 15765 TYPE_SATURATING (type)); |
15274 t = build_fixed (type, f); | 15766 t = build_fixed (type, f); |
15275 /* Propagate overflow flags. */ | 15767 /* Propagate overflow flags. */ |
15276 if (overflow_p | TREE_OVERFLOW (arg0)) | 15768 if (overflow_p | TREE_OVERFLOW (arg0)) |
15277 { | 15769 TREE_OVERFLOW (t) = 1; |
15278 TREE_OVERFLOW (t) = 1; | |
15279 TREE_CONSTANT_OVERFLOW (t) = 1; | |
15280 } | |
15281 else if (TREE_CONSTANT_OVERFLOW (arg0)) | |
15282 TREE_CONSTANT_OVERFLOW (t) = 1; | |
15283 break; | 15770 break; |
15284 } | 15771 } |
15285 | 15772 |
15286 default: | 15773 default: |
15287 gcc_unreachable (); | 15774 gcc_unreachable (); |
15507 return expr; | 15994 return expr; |
15508 op = TREE_OPERAND (op, 1); | 15995 op = TREE_OPERAND (op, 1); |
15509 if (!TREE_SIDE_EFFECTS (op)) | 15996 if (!TREE_SIDE_EFFECTS (op)) |
15510 return expr; | 15997 return expr; |
15511 } | 15998 } |
15512 | 15999 |
15513 return build1 (CLEANUP_POINT_EXPR, type, expr); | 16000 return build1 (CLEANUP_POINT_EXPR, type, expr); |
15514 } | 16001 } |
15515 | 16002 |
15516 /* Given a pointer value OP0 and a type TYPE, return a simplified version | 16003 /* Given a pointer value OP0 and a type TYPE, return a simplified version |
15517 of an indirection through OP0, or NULL_TREE if no simplification is | 16004 of an indirection through OP0, or NULL_TREE if no simplification is |
15518 possible. */ | 16005 possible. */ |
15519 | 16006 |
15520 tree | 16007 tree |
15521 fold_indirect_ref_1 (tree type, tree op0) | 16008 fold_indirect_ref_1 (location_t loc, tree type, tree op0) |
15522 { | 16009 { |
15523 tree sub = op0; | 16010 tree sub = op0; |
15524 tree subtype; | 16011 tree subtype; |
15525 | 16012 |
15526 STRIP_NOPS (sub); | 16013 STRIP_NOPS (sub); |
15550 { | 16037 { |
15551 tree type_domain = TYPE_DOMAIN (optype); | 16038 tree type_domain = TYPE_DOMAIN (optype); |
15552 tree min_val = size_zero_node; | 16039 tree min_val = size_zero_node; |
15553 if (type_domain && TYPE_MIN_VALUE (type_domain)) | 16040 if (type_domain && TYPE_MIN_VALUE (type_domain)) |
15554 min_val = TYPE_MIN_VALUE (type_domain); | 16041 min_val = TYPE_MIN_VALUE (type_domain); |
15555 return build4 (ARRAY_REF, type, op, min_val, NULL_TREE, NULL_TREE); | 16042 op0 = build4 (ARRAY_REF, type, op, min_val, NULL_TREE, NULL_TREE); |
16043 SET_EXPR_LOCATION (op0, loc); | |
16044 return op0; | |
15556 } | 16045 } |
15557 /* *(foo *)&complexfoo => __real__ complexfoo */ | 16046 /* *(foo *)&complexfoo => __real__ complexfoo */ |
15558 else if (TREE_CODE (optype) == COMPLEX_TYPE | 16047 else if (TREE_CODE (optype) == COMPLEX_TYPE |
15559 && type == TREE_TYPE (optype)) | 16048 && type == TREE_TYPE (optype)) |
15560 return fold_build1 (REALPART_EXPR, type, op); | 16049 return fold_build1_loc (loc, REALPART_EXPR, type, op); |
15561 /* *(foo *)&vectorfoo => BIT_FIELD_REF<vectorfoo,...> */ | 16050 /* *(foo *)&vectorfoo => BIT_FIELD_REF<vectorfoo,...> */ |
15562 else if (TREE_CODE (optype) == VECTOR_TYPE | 16051 else if (TREE_CODE (optype) == VECTOR_TYPE |
15563 && type == TREE_TYPE (optype)) | 16052 && type == TREE_TYPE (optype)) |
15564 { | 16053 { |
15565 tree part_width = TYPE_SIZE (type); | 16054 tree part_width = TYPE_SIZE (type); |
15566 tree index = bitsize_int (0); | 16055 tree index = bitsize_int (0); |
15567 return fold_build3 (BIT_FIELD_REF, type, op, part_width, index); | 16056 return fold_build3_loc (loc, BIT_FIELD_REF, type, op, part_width, index); |
15568 } | 16057 } |
15569 } | 16058 } |
15570 | 16059 |
15571 /* ((foo*)&vectorfoo)[1] => BIT_FIELD_REF<vectorfoo,...> */ | 16060 /* ((foo*)&vectorfoo)[1] => BIT_FIELD_REF<vectorfoo,...> */ |
15572 if (TREE_CODE (sub) == POINTER_PLUS_EXPR | 16061 if (TREE_CODE (sub) == POINTER_PLUS_EXPR |
15573 && TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST) | 16062 && TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST) |
15574 { | 16063 { |
15575 tree op00 = TREE_OPERAND (sub, 0); | 16064 tree op00 = TREE_OPERAND (sub, 0); |
15576 tree op01 = TREE_OPERAND (sub, 1); | 16065 tree op01 = TREE_OPERAND (sub, 1); |
15577 tree op00type; | 16066 tree op00type; |
15578 | 16067 |
15579 STRIP_NOPS (op00); | 16068 STRIP_NOPS (op00); |
15580 op00type = TREE_TYPE (op00); | 16069 op00type = TREE_TYPE (op00); |
15581 if (TREE_CODE (op00) == ADDR_EXPR | 16070 if (TREE_CODE (op00) == ADDR_EXPR |
15582 && TREE_CODE (TREE_TYPE (op00type)) == VECTOR_TYPE | 16071 && TREE_CODE (TREE_TYPE (op00type)) == VECTOR_TYPE |
15583 && type == TREE_TYPE (TREE_TYPE (op00type))) | 16072 && type == TREE_TYPE (TREE_TYPE (op00type))) |
15584 { | 16073 { |
15585 HOST_WIDE_INT offset = tree_low_cst (op01, 0); | 16074 HOST_WIDE_INT offset = tree_low_cst (op01, 0); |
15586 tree part_width = TYPE_SIZE (type); | 16075 tree part_width = TYPE_SIZE (type); |
15587 unsigned HOST_WIDE_INT part_widthi = tree_low_cst (part_width, 0)/BITS_PER_UNIT; | 16076 unsigned HOST_WIDE_INT part_widthi = tree_low_cst (part_width, 0)/BITS_PER_UNIT; |
15588 unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT; | 16077 unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT; |
15589 tree index = bitsize_int (indexi); | 16078 tree index = bitsize_int (indexi); |
15590 | 16079 |
15591 if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (TREE_TYPE (op00type))) | 16080 if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (TREE_TYPE (op00type))) |
15592 return fold_build3 (BIT_FIELD_REF, type, TREE_OPERAND (op00, 0), | 16081 return fold_build3_loc (loc, |
16082 BIT_FIELD_REF, type, TREE_OPERAND (op00, 0), | |
15593 part_width, index); | 16083 part_width, index); |
15594 | 16084 |
15595 } | 16085 } |
15596 } | 16086 } |
15597 | 16087 |
15598 | 16088 |
15599 /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */ | 16089 /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */ |
15610 && TREE_CODE (TREE_TYPE (op00type)) == COMPLEX_TYPE | 16100 && TREE_CODE (TREE_TYPE (op00type)) == COMPLEX_TYPE |
15611 && type == TREE_TYPE (TREE_TYPE (op00type))) | 16101 && type == TREE_TYPE (TREE_TYPE (op00type))) |
15612 { | 16102 { |
15613 tree size = TYPE_SIZE_UNIT (type); | 16103 tree size = TYPE_SIZE_UNIT (type); |
15614 if (tree_int_cst_equal (size, op01)) | 16104 if (tree_int_cst_equal (size, op01)) |
15615 return fold_build1 (IMAGPART_EXPR, type, TREE_OPERAND (op00, 0)); | 16105 return fold_build1_loc (loc, IMAGPART_EXPR, type, |
15616 } | 16106 TREE_OPERAND (op00, 0)); |
15617 } | 16107 } |
15618 | 16108 } |
16109 | |
15619 /* *(foo *)fooarrptr => (*fooarrptr)[0] */ | 16110 /* *(foo *)fooarrptr => (*fooarrptr)[0] */ |
15620 if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE | 16111 if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE |
15621 && type == TREE_TYPE (TREE_TYPE (subtype))) | 16112 && type == TREE_TYPE (TREE_TYPE (subtype))) |
15622 { | 16113 { |
15623 tree type_domain; | 16114 tree type_domain; |
15624 tree min_val = size_zero_node; | 16115 tree min_val = size_zero_node; |
15625 sub = build_fold_indirect_ref (sub); | 16116 sub = build_fold_indirect_ref_loc (loc, sub); |
15626 type_domain = TYPE_DOMAIN (TREE_TYPE (sub)); | 16117 type_domain = TYPE_DOMAIN (TREE_TYPE (sub)); |
15627 if (type_domain && TYPE_MIN_VALUE (type_domain)) | 16118 if (type_domain && TYPE_MIN_VALUE (type_domain)) |
15628 min_val = TYPE_MIN_VALUE (type_domain); | 16119 min_val = TYPE_MIN_VALUE (type_domain); |
15629 return build4 (ARRAY_REF, type, sub, min_val, NULL_TREE, NULL_TREE); | 16120 op0 = build4 (ARRAY_REF, type, sub, min_val, NULL_TREE, NULL_TREE); |
16121 SET_EXPR_LOCATION (op0, loc); | |
16122 return op0; | |
15630 } | 16123 } |
15631 | 16124 |
15632 return NULL_TREE; | 16125 return NULL_TREE; |
15633 } | 16126 } |
15634 | 16127 |
15635 /* Builds an expression for an indirection through T, simplifying some | 16128 /* Builds an expression for an indirection through T, simplifying some |
15636 cases. */ | 16129 cases. */ |
15637 | 16130 |
15638 tree | 16131 tree |
15639 build_fold_indirect_ref (tree t) | 16132 build_fold_indirect_ref_loc (location_t loc, tree t) |
15640 { | 16133 { |
15641 tree type = TREE_TYPE (TREE_TYPE (t)); | 16134 tree type = TREE_TYPE (TREE_TYPE (t)); |
15642 tree sub = fold_indirect_ref_1 (type, t); | 16135 tree sub = fold_indirect_ref_1 (loc, type, t); |
15643 | 16136 |
15644 if (sub) | 16137 if (sub) |
15645 return sub; | 16138 return sub; |
15646 else | 16139 |
15647 return build1 (INDIRECT_REF, type, t); | 16140 t = build1 (INDIRECT_REF, type, t); |
16141 SET_EXPR_LOCATION (t, loc); | |
16142 return t; | |
15648 } | 16143 } |
15649 | 16144 |
15650 /* Given an INDIRECT_REF T, return either T or a simplified version. */ | 16145 /* Given an INDIRECT_REF T, return either T or a simplified version. */ |
15651 | 16146 |
15652 tree | 16147 tree |
15653 fold_indirect_ref (tree t) | 16148 fold_indirect_ref_loc (location_t loc, tree t) |
15654 { | 16149 { |
15655 tree sub = fold_indirect_ref_1 (TREE_TYPE (t), TREE_OPERAND (t, 0)); | 16150 tree sub = fold_indirect_ref_1 (loc, TREE_TYPE (t), TREE_OPERAND (t, 0)); |
15656 | 16151 |
15657 if (sub) | 16152 if (sub) |
15658 return sub; | 16153 return sub; |
15659 else | 16154 else |
15660 return t; | 16155 return t; |
15715 | 16210 |
15716 /* Return the value of VALUE, rounded up to a multiple of DIVISOR. | 16211 /* Return the value of VALUE, rounded up to a multiple of DIVISOR. |
15717 This can only be applied to objects of a sizetype. */ | 16212 This can only be applied to objects of a sizetype. */ |
15718 | 16213 |
15719 tree | 16214 tree |
15720 round_up (tree value, int divisor) | 16215 round_up_loc (location_t loc, tree value, int divisor) |
15721 { | 16216 { |
15722 tree div = NULL_TREE; | 16217 tree div = NULL_TREE; |
15723 | 16218 |
15724 gcc_assert (divisor > 0); | 16219 gcc_assert (divisor > 0); |
15725 if (divisor == 1) | 16220 if (divisor == 1) |
15766 else | 16261 else |
15767 { | 16262 { |
15768 tree t; | 16263 tree t; |
15769 | 16264 |
15770 t = build_int_cst (TREE_TYPE (value), divisor - 1); | 16265 t = build_int_cst (TREE_TYPE (value), divisor - 1); |
15771 value = size_binop (PLUS_EXPR, value, t); | 16266 value = size_binop_loc (loc, PLUS_EXPR, value, t); |
15772 t = build_int_cst (TREE_TYPE (value), -divisor); | 16267 t = build_int_cst (TREE_TYPE (value), -divisor); |
15773 value = size_binop (BIT_AND_EXPR, value, t); | 16268 value = size_binop_loc (loc, BIT_AND_EXPR, value, t); |
15774 } | 16269 } |
15775 } | 16270 } |
15776 else | 16271 else |
15777 { | 16272 { |
15778 if (!div) | 16273 if (!div) |
15779 div = build_int_cst (TREE_TYPE (value), divisor); | 16274 div = build_int_cst (TREE_TYPE (value), divisor); |
15780 value = size_binop (CEIL_DIV_EXPR, value, div); | 16275 value = size_binop_loc (loc, CEIL_DIV_EXPR, value, div); |
15781 value = size_binop (MULT_EXPR, value, div); | 16276 value = size_binop_loc (loc, MULT_EXPR, value, div); |
15782 } | 16277 } |
15783 | 16278 |
15784 return value; | 16279 return value; |
15785 } | 16280 } |
15786 | 16281 |
15787 /* Likewise, but round down. */ | 16282 /* Likewise, but round down. */ |
15788 | 16283 |
15789 tree | 16284 tree |
15790 round_down (tree value, int divisor) | 16285 round_down_loc (location_t loc, tree value, int divisor) |
15791 { | 16286 { |
15792 tree div = NULL_TREE; | 16287 tree div = NULL_TREE; |
15793 | 16288 |
15794 gcc_assert (divisor > 0); | 16289 gcc_assert (divisor > 0); |
15795 if (divisor == 1) | 16290 if (divisor == 1) |
15811 if (divisor == (divisor & -divisor)) | 16306 if (divisor == (divisor & -divisor)) |
15812 { | 16307 { |
15813 tree t; | 16308 tree t; |
15814 | 16309 |
15815 t = build_int_cst (TREE_TYPE (value), -divisor); | 16310 t = build_int_cst (TREE_TYPE (value), -divisor); |
15816 value = size_binop (BIT_AND_EXPR, value, t); | 16311 value = size_binop_loc (loc, BIT_AND_EXPR, value, t); |
15817 } | 16312 } |
15818 else | 16313 else |
15819 { | 16314 { |
15820 if (!div) | 16315 if (!div) |
15821 div = build_int_cst (TREE_TYPE (value), divisor); | 16316 div = build_int_cst (TREE_TYPE (value), divisor); |
15822 value = size_binop (FLOOR_DIV_EXPR, value, div); | 16317 value = size_binop_loc (loc, FLOOR_DIV_EXPR, value, div); |
15823 value = size_binop (MULT_EXPR, value, div); | 16318 value = size_binop_loc (loc, MULT_EXPR, value, div); |
15824 } | 16319 } |
15825 | 16320 |
15826 return value; | 16321 return value; |
15827 } | 16322 } |
15828 | 16323 |
15836 { | 16331 { |
15837 tree core; | 16332 tree core; |
15838 enum machine_mode mode; | 16333 enum machine_mode mode; |
15839 int unsignedp, volatilep; | 16334 int unsignedp, volatilep; |
15840 HOST_WIDE_INT bitsize; | 16335 HOST_WIDE_INT bitsize; |
16336 location_t loc = EXPR_LOCATION (exp); | |
15841 | 16337 |
15842 if (TREE_CODE (exp) == ADDR_EXPR) | 16338 if (TREE_CODE (exp) == ADDR_EXPR) |
15843 { | 16339 { |
15844 core = get_inner_reference (TREE_OPERAND (exp, 0), &bitsize, pbitpos, | 16340 core = get_inner_reference (TREE_OPERAND (exp, 0), &bitsize, pbitpos, |
15845 poffset, &mode, &unsignedp, &volatilep, | 16341 poffset, &mode, &unsignedp, &volatilep, |
15846 false); | 16342 false); |
15847 core = fold_addr_expr (core); | 16343 core = build_fold_addr_expr_loc (loc, core); |
15848 } | 16344 } |
15849 else | 16345 else |
15850 { | 16346 { |
15851 core = exp; | 16347 core = exp; |
15852 *pbitpos = 0; | 16348 *pbitpos = 0; |
15905 | 16401 |
15906 tree | 16402 tree |
15907 fold_strip_sign_ops (tree exp) | 16403 fold_strip_sign_ops (tree exp) |
15908 { | 16404 { |
15909 tree arg0, arg1; | 16405 tree arg0, arg1; |
16406 location_t loc = EXPR_LOCATION (exp); | |
15910 | 16407 |
15911 switch (TREE_CODE (exp)) | 16408 switch (TREE_CODE (exp)) |
15912 { | 16409 { |
15913 case ABS_EXPR: | 16410 case ABS_EXPR: |
15914 case NEGATE_EXPR: | 16411 case NEGATE_EXPR: |
15920 if (HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (TREE_TYPE (exp)))) | 16417 if (HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (TREE_TYPE (exp)))) |
15921 return NULL_TREE; | 16418 return NULL_TREE; |
15922 arg0 = fold_strip_sign_ops (TREE_OPERAND (exp, 0)); | 16419 arg0 = fold_strip_sign_ops (TREE_OPERAND (exp, 0)); |
15923 arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 1)); | 16420 arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 1)); |
15924 if (arg0 != NULL_TREE || arg1 != NULL_TREE) | 16421 if (arg0 != NULL_TREE || arg1 != NULL_TREE) |
15925 return fold_build2 (TREE_CODE (exp), TREE_TYPE (exp), | 16422 return fold_build2_loc (loc, TREE_CODE (exp), TREE_TYPE (exp), |
15926 arg0 ? arg0 : TREE_OPERAND (exp, 0), | 16423 arg0 ? arg0 : TREE_OPERAND (exp, 0), |
15927 arg1 ? arg1 : TREE_OPERAND (exp, 1)); | 16424 arg1 ? arg1 : TREE_OPERAND (exp, 1)); |
15928 break; | 16425 break; |
15929 | 16426 |
15930 case COMPOUND_EXPR: | 16427 case COMPOUND_EXPR: |
15931 arg0 = TREE_OPERAND (exp, 0); | 16428 arg0 = TREE_OPERAND (exp, 0); |
15932 arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 1)); | 16429 arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 1)); |
15933 if (arg1) | 16430 if (arg1) |
15934 return fold_build2 (COMPOUND_EXPR, TREE_TYPE (exp), arg0, arg1); | 16431 return fold_build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (exp), arg0, arg1); |
15935 break; | 16432 break; |
15936 | 16433 |
15937 case COND_EXPR: | 16434 case COND_EXPR: |
15938 arg0 = fold_strip_sign_ops (TREE_OPERAND (exp, 1)); | 16435 arg0 = fold_strip_sign_ops (TREE_OPERAND (exp, 1)); |
15939 arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 2)); | 16436 arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 2)); |
15940 if (arg0 || arg1) | 16437 if (arg0 || arg1) |
15941 return fold_build3 (COND_EXPR, TREE_TYPE (exp), TREE_OPERAND (exp, 0), | 16438 return fold_build3_loc (loc, |
16439 COND_EXPR, TREE_TYPE (exp), TREE_OPERAND (exp, 0), | |
15942 arg0 ? arg0 : TREE_OPERAND (exp, 1), | 16440 arg0 ? arg0 : TREE_OPERAND (exp, 1), |
15943 arg1 ? arg1 : TREE_OPERAND (exp, 2)); | 16441 arg1 ? arg1 : TREE_OPERAND (exp, 2)); |
15944 break; | 16442 break; |
15945 | 16443 |
15946 case CALL_EXPR: | 16444 case CALL_EXPR: |
15947 { | 16445 { |
15948 const enum built_in_function fcode = builtin_mathfn_code (exp); | 16446 const enum built_in_function fcode = builtin_mathfn_code (exp); |
15949 switch (fcode) | 16447 switch (fcode) |
15950 { | 16448 { |
15951 CASE_FLT_FN (BUILT_IN_COPYSIGN): | 16449 CASE_FLT_FN (BUILT_IN_COPYSIGN): |
15952 /* Strip copysign function call, return the 1st argument. */ | 16450 /* Strip copysign function call, return the 1st argument. */ |
15953 arg0 = CALL_EXPR_ARG (exp, 0); | 16451 arg0 = CALL_EXPR_ARG (exp, 0); |
15954 arg1 = CALL_EXPR_ARG (exp, 1); | 16452 arg1 = CALL_EXPR_ARG (exp, 1); |
15955 return omit_one_operand (TREE_TYPE (exp), arg0, arg1); | 16453 return omit_one_operand_loc (loc, TREE_TYPE (exp), arg0, arg1); |
15956 | 16454 |
15957 default: | 16455 default: |
15958 /* Strip sign ops from the argument of "odd" math functions. */ | 16456 /* Strip sign ops from the argument of "odd" math functions. */ |
15959 if (negate_mathfn_p (fcode)) | 16457 if (negate_mathfn_p (fcode)) |
15960 { | 16458 { |
15961 arg0 = fold_strip_sign_ops (CALL_EXPR_ARG (exp, 0)); | 16459 arg0 = fold_strip_sign_ops (CALL_EXPR_ARG (exp, 0)); |
15962 if (arg0) | 16460 if (arg0) |
15963 return build_call_expr (get_callee_fndecl (exp), 1, arg0); | 16461 return build_call_expr_loc (loc, get_callee_fndecl (exp), 1, arg0); |
15964 } | 16462 } |
15965 break; | 16463 break; |
15966 } | 16464 } |
15967 } | 16465 } |
15968 break; | 16466 break; |