Deleted Added
full compact
fold-const.c (50397) fold-const.c (52284)
1/* Fold a constant sub-tree into a single node for C-compiler
2 Copyright (C) 1987, 88, 92-98, 1999 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)

--- 33 unchanged lines hidden (view full) ---

42 force_fit_type takes a constant and prior overflow indicator, and
43 forces the value to fit the type. It returns an overflow indicator. */
44
45#include "config.h"
46#include "system.h"
47#include <setjmp.h>
48#include "flags.h"
49#include "tree.h"
1/* Fold a constant sub-tree into a single node for C-compiler
2 Copyright (C) 1987, 88, 92-98, 1999 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)

--- 33 unchanged lines hidden (view full) ---

42 force_fit_type takes a constant and prior overflow indicator, and
43 forces the value to fit the type. It returns an overflow indicator. */
44
45#include "config.h"
46#include "system.h"
47#include <setjmp.h>
48#include "flags.h"
49#include "tree.h"
50#include "rtl.h"
50#include "toplev.h"
51
51#include "toplev.h"
52
52/* Handle floating overflow for `const_binop'. */
53static jmp_buf float_error;
54
55static void encode PROTO((HOST_WIDE_INT *,
56 HOST_WIDE_INT, HOST_WIDE_INT));
57static void decode PROTO((HOST_WIDE_INT *,
58 HOST_WIDE_INT *, HOST_WIDE_INT *));
59int div_and_round_double PROTO((enum tree_code, int, HOST_WIDE_INT,
60 HOST_WIDE_INT, HOST_WIDE_INT,
61 HOST_WIDE_INT, HOST_WIDE_INT *,
62 HOST_WIDE_INT *, HOST_WIDE_INT *,

--- 27 unchanged lines hidden (view full) ---

90static int merge_ranges PROTO((int *, tree *, tree *, int, tree, tree,
91 int, tree, tree));
92static tree fold_range_test PROTO((tree));
93static tree unextend PROTO((tree, int, int, tree));
94static tree fold_truthop PROTO((enum tree_code, tree, tree, tree));
95static tree strip_compound_expr PROTO((tree, tree));
96static int multiple_of_p PROTO((tree, tree, tree));
97static tree constant_boolean_node PROTO((int, tree));
53static void encode PROTO((HOST_WIDE_INT *,
54 HOST_WIDE_INT, HOST_WIDE_INT));
55static void decode PROTO((HOST_WIDE_INT *,
56 HOST_WIDE_INT *, HOST_WIDE_INT *));
57int div_and_round_double PROTO((enum tree_code, int, HOST_WIDE_INT,
58 HOST_WIDE_INT, HOST_WIDE_INT,
59 HOST_WIDE_INT, HOST_WIDE_INT *,
60 HOST_WIDE_INT *, HOST_WIDE_INT *,

--- 27 unchanged lines hidden (view full) ---

88static int merge_ranges PROTO((int *, tree *, tree *, int, tree, tree,
89 int, tree, tree));
90static tree fold_range_test PROTO((tree));
91static tree unextend PROTO((tree, int, int, tree));
92static tree fold_truthop PROTO((enum tree_code, tree, tree, tree));
93static tree strip_compound_expr PROTO((tree, tree));
94static int multiple_of_p PROTO((tree, tree, tree));
95static tree constant_boolean_node PROTO((int, tree));
96static int count_cond PROTO((tree, int));
97static void const_binop_1 PROTO((PTR));
98static void fold_convert_1 PROTO((PTR));
98
99#ifndef BRANCH_COST
100#define BRANCH_COST 1
101#endif
102
103/* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
104 Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
105 Then this yields nonzero if overflow occurred during the addition.

--- 266 unchanged lines hidden (view full) ---

372/* Shift the doubleword integer in L1, H1 right by COUNT places
373 keeping only PREC bits of result. COUNT must be positive.
374 ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
375 Store the value as two `HOST_WIDE_INT' pieces in *LV and *HV. */
376
377void
378rshift_double (l1, h1, count, prec, lv, hv, arith)
379 HOST_WIDE_INT l1, h1, count;
99
100#ifndef BRANCH_COST
101#define BRANCH_COST 1
102#endif
103
104/* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
105 Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
106 Then this yields nonzero if overflow occurred during the addition.

--- 266 unchanged lines hidden (view full) ---

373/* Shift the doubleword integer in L1, H1 right by COUNT places
374 keeping only PREC bits of result. COUNT must be positive.
375 ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
376 Store the value as two `HOST_WIDE_INT' pieces in *LV and *HV. */
377
378void
379rshift_double (l1, h1, count, prec, lv, hv, arith)
380 HOST_WIDE_INT l1, h1, count;
380 int prec;
381 int prec ATTRIBUTE_UNUSED;
381 HOST_WIDE_INT *lv, *hv;
382 int arith;
383{
384 unsigned HOST_WIDE_INT signmask;
385 signmask = (arith
386 ? -((unsigned HOST_WIDE_INT) h1 >> (HOST_BITS_PER_WIDE_INT - 1))
387 : 0);
388

--- 134 unchanged lines hidden (view full) ---

523
524 bzero ((char *) num, sizeof num); /* to zero 9th element */
525 bzero ((char *) den, sizeof den);
526
527 encode (num, lnum, hnum);
528 encode (den, lden, hden);
529
530 /* Special code for when the divisor < BASE. */
382 HOST_WIDE_INT *lv, *hv;
383 int arith;
384{
385 unsigned HOST_WIDE_INT signmask;
386 signmask = (arith
387 ? -((unsigned HOST_WIDE_INT) h1 >> (HOST_BITS_PER_WIDE_INT - 1))
388 : 0);
389

--- 134 unchanged lines hidden (view full) ---

524
525 bzero ((char *) num, sizeof num); /* to zero 9th element */
526 bzero ((char *) den, sizeof den);
527
528 encode (num, lnum, hnum);
529 encode (den, lden, hden);
530
531 /* Special code for when the divisor < BASE. */
531 if (hden == 0 && lden < BASE)
532 if (hden == 0 && lden < (HOST_WIDE_INT) BASE)
532 {
533 /* hnum != 0 already checked. */
534 for (i = 4 - 1; i >= 0; i--)
535 {
536 work = num[i] + carry * BASE;
537 quo[i] = work / (unsigned HOST_WIDE_INT) lden;
538 carry = work % (unsigned HOST_WIDE_INT) lden;
539 }

--- 339 unchanged lines hidden (view full) ---

879/* Try to change R into its exact multiplicative inverse in machine mode
880 MODE. Return nonzero function value if successful. */
881
882int
883exact_real_inverse (mode, r)
884 enum machine_mode mode;
885 REAL_VALUE_TYPE *r;
886{
533 {
534 /* hnum != 0 already checked. */
535 for (i = 4 - 1; i >= 0; i--)
536 {
537 work = num[i] + carry * BASE;
538 quo[i] = work / (unsigned HOST_WIDE_INT) lden;
539 carry = work % (unsigned HOST_WIDE_INT) lden;
540 }

--- 339 unchanged lines hidden (view full) ---

880/* Try to change R into its exact multiplicative inverse in machine mode
881 MODE. Return nonzero function value if successful. */
882
883int
884exact_real_inverse (mode, r)
885 enum machine_mode mode;
886 REAL_VALUE_TYPE *r;
887{
888 jmp_buf float_error;
887 union
888 {
889 double d;
890 unsigned short i[4];
891 }x, t, y;
892 int i;
893
894 /* Usually disable if bounds checks are not reliable. */

--- 63 unchanged lines hidden (view full) ---

958 goto fail;
959#endif
960
961 /* Output the reciprocal and return success flag. */
962 set_float_handler (NULL_PTR);
963 *r = y.d;
964 return 1;
965}
889 union
890 {
891 double d;
892 unsigned short i[4];
893 }x, t, y;
894 int i;
895
896 /* Usually disable if bounds checks are not reliable. */

--- 63 unchanged lines hidden (view full) ---

960 goto fail;
961#endif
962
963 /* Output the reciprocal and return success flag. */
964 set_float_handler (NULL_PTR);
965 *r = y.d;
966 return 1;
967}
968
969
970/* Convert C9X hexadecimal floating point string constant S. Return
971 real value type in mode MODE. This function uses the host computer's
972 fp arithmetic when there is no REAL_ARITHMETIC. */
973
974REAL_VALUE_TYPE
975real_hex_to_f (s, mode)
976 char *s;
977 enum machine_mode mode;
978{
979 REAL_VALUE_TYPE ip;
980 char *p = s;
981 unsigned HOST_WIDE_INT low, high;
982 int frexpon, expon, shcount, nrmcount, k;
983 int sign, expsign, decpt, isfloat, isldouble, gotp, lost;
984 char c;
985
986 isldouble = 0;
987 isfloat = 0;
988 frexpon = 0;
989 expon = 0;
990 expsign = 1;
991 ip = 0.0;
992
993 while (*p == ' ' || *p == '\t')
994 ++p;
995
996 /* Sign, if any, comes first. */
997 sign = 1;
998 if (*p == '-')
999 {
1000 sign = -1;
1001 ++p;
1002 }
1003
1004 /* The string is supposed to start with 0x or 0X . */
1005 if (*p == '0')
1006 {
1007 ++p;
1008 if (*p == 'x' || *p == 'X')
1009 ++p;
1010 else
1011 abort ();
1012 }
1013 else
1014 abort ();
1015
1016 while (*p == '0')
1017 ++p;
1018
1019 high = 0;
1020 low = 0;
1021 lost = 0; /* Nonzero low order bits shifted out and discarded. */
1022 frexpon = 0; /* Bits after the decimal point. */
1023 expon = 0; /* Value of exponent. */
1024 decpt = 0; /* How many decimal points. */
1025 gotp = 0; /* How many P's. */
1026 shcount = 0;
1027 while ((c = *p) != '\0')
1028 {
1029 if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')
1030 || (c >= 'a' && c <= 'f'))
1031 {
1032 k = c & 0x7f;
1033 if (k >= 'a')
1034 k = k - 'a' + 10;
1035 else if (k >= 'A')
1036 k = k - 'A' + 10;
1037 else
1038 k = k - '0';
1039
1040 if ((high & 0xf0000000) == 0)
1041 {
1042 high = (high << 4) + ((low >> 28) & 15);
1043 low = (low << 4) + k;
1044 shcount += 4;
1045 if (decpt)
1046 frexpon += 4;
1047 }
1048 else
1049 {
1050 /* Record nonzero lost bits. */
1051 lost |= k;
1052 if (!decpt)
1053 frexpon -= 4;
1054 }
1055 ++p;
1056 }
1057 else if ( c == '.')
1058 {
1059 ++decpt;
1060 ++p;
1061 }
1062 else if (c == 'p' || c == 'P')
1063 {
1064 ++gotp;
1065 ++p;
1066 /* Sign of exponent. */
1067 if (*p == '-')
1068 {
1069 expsign = -1;
1070 ++p;
1071 }
1072 /* Value of exponent.
1073 The exponent field is a decimal integer. */
1074 while (isdigit(*p))
1075 {
1076 k = (*p++ & 0x7f) - '0';
1077 expon = 10 * expon + k;
1078 }
1079 expon *= expsign;
1080 /* F suffix is ambiguous in the significand part
1081 so it must appear after the decimal exponent field. */
1082 if (*p == 'f' || *p == 'F')
1083 {
1084 isfloat = 1;
1085 ++p;
1086 break;
1087 }
1088 }
1089 else if (c == 'l' || c == 'L')
1090 {
1091 isldouble = 1;
1092 ++p;
1093 break;
1094 }
1095 else
1096 break;
1097 }
1098 /* Abort if last character read was not legitimate. */
1099 c = *p;
1100 if ((c != '\0' && c != ' ' && c != '\n' && c != '\r') || (decpt > 1))
1101 abort ();
1102 /* There must be either one decimal point or one p. */
1103 if (decpt == 0 && gotp == 0)
1104 abort ();
1105 shcount -= 4;
1106 if ((high == 0) && (low == 0))
1107 {
1108 return dconst0;
1109 }
1110
1111 /* Normalize. */
1112 nrmcount = 0;
1113 if (high == 0)
1114 {
1115 high = low;
1116 low = 0;
1117 nrmcount += 32;
1118 }
1119 /* Leave a high guard bit for carry-out. */
1120 if ((high & 0x80000000) != 0)
1121 {
1122 lost |= low & 1;
1123 low = (low >> 1) | (high << 31);
1124 high = high >> 1;
1125 nrmcount -= 1;
1126 }
1127 if ((high & 0xffff8000) == 0)
1128 {
1129 high = (high << 16) + ((low >> 16) & 0xffff);
1130 low = low << 16;
1131 nrmcount += 16;
1132 }
1133 while ((high & 0xc0000000) == 0)
1134 {
1135 high = (high << 1) + ((low >> 31) & 1);
1136 low = low << 1;
1137 nrmcount += 1;
1138 }
1139 if (isfloat || GET_MODE_SIZE(mode) == UNITS_PER_WORD)
1140 {
1141 /* Keep 24 bits precision, bits 0x7fffff80.
1142 Rounding bit is 0x40. */
1143 lost = lost | low | (high & 0x3f);
1144 low = 0;
1145 if (high & 0x40)
1146 {
1147 if ((high & 0x80) || lost)
1148 high += 0x40;
1149 }
1150 high &= 0xffffff80;
1151 }
1152 else
1153 {
1154 /* We need real.c to do long double formats, so here default
1155 to double precision. */
1156#if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
1157 /* IEEE double.
1158 Keep 53 bits precision, bits 0x7fffffff fffffc00.
1159 Rounding bit is low word 0x200. */
1160 lost = lost | (low & 0x1ff);
1161 if (low & 0x200)
1162 {
1163 if ((low & 0x400) || lost)
1164 {
1165 low = (low + 0x200) & 0xfffffc00;
1166 if (low == 0)
1167 high += 1;
1168 }
1169 }
1170 low &= 0xfffffc00;
1171#else
1172 /* Assume it's a VAX with 56-bit significand,
1173 bits 0x7fffffff ffffff80. */
1174 lost = lost | (low & 0x7f);
1175 if (low & 0x40)
1176 {
1177 if ((low & 0x80) || lost)
1178 {
1179 low = (low + 0x40) & 0xffffff80;
1180 if (low == 0)
1181 high += 1;
1182 }
1183 }
1184 low &= 0xffffff80;
1185#endif
1186 }
1187 ip = (double) high;
1188 ip = REAL_VALUE_LDEXP (ip, 32) + (double) low;
1189 /* Apply shifts and exponent value as power of 2. */
1190 ip = REAL_VALUE_LDEXP (ip, expon - (nrmcount + frexpon));
1191
1192 if (sign < 0)
1193 ip = -ip;
1194 return ip;
1195}
1196
966#endif /* no REAL_ARITHMETIC */
967
968/* Split a tree IN into a constant and a variable part
969 that could be combined with CODE to make IN.
970 CODE must be a commutative arithmetic operation.
971 Store the constant part into *CONP and the variable in &VARP.
972 Return 1 if this was done; zero means the tree IN did not decompose
973 this way.

--- 268 unchanged lines hidden (view full) ---

1242 || TREE_INT_CST_LOW (t) != low))
1243 TREE_OVERFLOW (t) = 1;
1244 TREE_CONSTANT_OVERFLOW (t) = (TREE_OVERFLOW (t)
1245 | TREE_CONSTANT_OVERFLOW (arg1)
1246 | TREE_CONSTANT_OVERFLOW (arg2));
1247 return t;
1248}
1249
1197#endif /* no REAL_ARITHMETIC */
1198
1199/* Split a tree IN into a constant and a variable part
1200 that could be combined with CODE to make IN.
1201 CODE must be a commutative arithmetic operation.
1202 Store the constant part into *CONP and the variable in &VARP.
1203 Return 1 if this was done; zero means the tree IN did not decompose
1204 this way.

--- 268 unchanged lines hidden (view full) ---

1473 || TREE_INT_CST_LOW (t) != low))
1474 TREE_OVERFLOW (t) = 1;
1475 TREE_CONSTANT_OVERFLOW (t) = (TREE_OVERFLOW (t)
1476 | TREE_CONSTANT_OVERFLOW (arg1)
1477 | TREE_CONSTANT_OVERFLOW (arg2));
1478 return t;
1479}
1480
1481struct cb_args
1482{
1483 /* Input */
1484 tree arg1;
1485 REAL_VALUE_TYPE d1, d2;
1486 enum tree_code code;
1487 /* Output */
1488 tree t;
1489};
1490
1491static void
1492const_binop_1 (data)
1493 PTR data;
1494{
1495 struct cb_args * args = (struct cb_args *) data;
1496 REAL_VALUE_TYPE value;
1497
1498#ifdef REAL_ARITHMETIC
1499 REAL_ARITHMETIC (value, args->code, args->d1, args->d2);
1500#else
1501 switch (args->code)
1502 {
1503 case PLUS_EXPR:
1504 value = args->d1 + args->d2;
1505 break;
1506
1507 case MINUS_EXPR:
1508 value = args->d1 - args->d2;
1509 break;
1510
1511 case MULT_EXPR:
1512 value = args->d1 * args->d2;
1513 break;
1514
1515 case RDIV_EXPR:
1516#ifndef REAL_INFINITY
1517 if (args->d2 == 0)
1518 abort ();
1519#endif
1520
1521 value = args->d1 / args->d2;
1522 break;
1523
1524 case MIN_EXPR:
1525 value = MIN (args->d1, args->d2);
1526 break;
1527
1528 case MAX_EXPR:
1529 value = MAX (args->d1, args->d2);
1530 break;
1531
1532 default:
1533 abort ();
1534 }
1535#endif /* no REAL_ARITHMETIC */
1536 args->t =
1537 build_real (TREE_TYPE (args->arg1),
1538 real_value_truncate (TYPE_MODE (TREE_TYPE (args->arg1)),
1539 value));
1540}
1541
1250/* Combine two constants ARG1 and ARG2 under operation CODE
1251 to produce a new constant.
1252 We assume ARG1 and ARG2 have the same data type,
1253 or at least are the same kind of constant and the same machine mode.
1254
1255 If NOTRUNC is nonzero, do not truncate the result to fit the data type. */
1256
1257static tree

--- 8 unchanged lines hidden (view full) ---

1266 return int_const_binop (code, arg1, arg2, notrunc, 0);
1267
1268#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1269 if (TREE_CODE (arg1) == REAL_CST)
1270 {
1271 REAL_VALUE_TYPE d1;
1272 REAL_VALUE_TYPE d2;
1273 int overflow = 0;
1542/* Combine two constants ARG1 and ARG2 under operation CODE
1543 to produce a new constant.
1544 We assume ARG1 and ARG2 have the same data type,
1545 or at least are the same kind of constant and the same machine mode.
1546
1547 If NOTRUNC is nonzero, do not truncate the result to fit the data type. */
1548
1549static tree

--- 8 unchanged lines hidden (view full) ---

1558 return int_const_binop (code, arg1, arg2, notrunc, 0);
1559
1560#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1561 if (TREE_CODE (arg1) == REAL_CST)
1562 {
1563 REAL_VALUE_TYPE d1;
1564 REAL_VALUE_TYPE d2;
1565 int overflow = 0;
1274 REAL_VALUE_TYPE value;
1275 tree t;
1566 tree t;
1567 struct cb_args args;
1276
1277 d1 = TREE_REAL_CST (arg1);
1278 d2 = TREE_REAL_CST (arg2);
1279
1280 /* If either operand is a NaN, just return it. Otherwise, set up
1281 for floating-point trap; we return an overflow. */
1282 if (REAL_VALUE_ISNAN (d1))
1283 return arg1;
1284 else if (REAL_VALUE_ISNAN (d2))
1285 return arg2;
1568
1569 d1 = TREE_REAL_CST (arg1);
1570 d2 = TREE_REAL_CST (arg2);
1571
1572 /* If either operand is a NaN, just return it. Otherwise, set up
1573 for floating-point trap; we return an overflow. */
1574 if (REAL_VALUE_ISNAN (d1))
1575 return arg1;
1576 else if (REAL_VALUE_ISNAN (d2))
1577 return arg2;
1286 else if (setjmp (float_error))
1578
1579 /* Setup input for const_binop_1() */
1580 args.arg1 = arg1;
1581 args.d1 = d1;
1582 args.d2 = d2;
1583 args.code = code;
1584
1585 if (do_float_handler (const_binop_1, (PTR) &args))
1287 {
1586 {
1587 /* Receive output from const_binop_1() */
1588 t = args.t;
1589 }
1590 else
1591 {
1592 /* We got an exception from const_binop_1() */
1288 t = copy_node (arg1);
1289 overflow = 1;
1593 t = copy_node (arg1);
1594 overflow = 1;
1290 goto got_float;
1291 }
1292
1595 }
1596
1293 set_float_handler (float_error);
1294
1295#ifdef REAL_ARITHMETIC
1296 REAL_ARITHMETIC (value, code, d1, d2);
1297#else
1298 switch (code)
1299 {
1300 case PLUS_EXPR:
1301 value = d1 + d2;
1302 break;
1303
1304 case MINUS_EXPR:
1305 value = d1 - d2;
1306 break;
1307
1308 case MULT_EXPR:
1309 value = d1 * d2;
1310 break;
1311
1312 case RDIV_EXPR:
1313#ifndef REAL_INFINITY
1314 if (d2 == 0)
1315 abort ();
1316#endif
1317
1318 value = d1 / d2;
1319 break;
1320
1321 case MIN_EXPR:
1322 value = MIN (d1, d2);
1323 break;
1324
1325 case MAX_EXPR:
1326 value = MAX (d1, d2);
1327 break;
1328
1329 default:
1330 abort ();
1331 }
1332#endif /* no REAL_ARITHMETIC */
1333 t = build_real (TREE_TYPE (arg1),
1334 real_value_truncate (TYPE_MODE (TREE_TYPE (arg1)), value));
1335 got_float:
1336 set_float_handler (NULL_PTR);
1337
1338 TREE_OVERFLOW (t)
1339 = (force_fit_type (t, overflow)
1340 | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
1341 TREE_CONSTANT_OVERFLOW (t)
1342 = TREE_OVERFLOW (t)
1343 | TREE_CONSTANT_OVERFLOW (arg1)
1344 | TREE_CONSTANT_OVERFLOW (arg2);
1345 return t;

--- 173 unchanged lines hidden (view full) ---

1519 }
1520
1521 if (arg0 == error_mark_node || arg1 == error_mark_node)
1522 return error_mark_node;
1523
1524 return fold (build (code, ssizetype, arg0, arg1));
1525}
1526
1597 TREE_OVERFLOW (t)
1598 = (force_fit_type (t, overflow)
1599 | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
1600 TREE_CONSTANT_OVERFLOW (t)
1601 = TREE_OVERFLOW (t)
1602 | TREE_CONSTANT_OVERFLOW (arg1)
1603 | TREE_CONSTANT_OVERFLOW (arg2);
1604 return t;

--- 173 unchanged lines hidden (view full) ---

1778 }
1779
1780 if (arg0 == error_mark_node || arg1 == error_mark_node)
1781 return error_mark_node;
1782
1783 return fold (build (code, ssizetype, arg0, arg1));
1784}
1785
1786struct fc_args
1787{
1788 /* Input */
1789 tree arg1, type;
1790 /* Output */
1791 tree t;
1792};
1793
1794static void
1795fold_convert_1 (data)
1796 PTR data;
1797{
1798 struct fc_args * args = (struct fc_args *) data;
1799
1800 args->t = build_real (args->type,
1801 real_value_truncate (TYPE_MODE (args->type),
1802 TREE_REAL_CST (args->arg1)));
1803}
1804
1527/* Given T, a tree representing type conversion of ARG1, a constant,
1528 return a constant tree representing the result of conversion. */
1529
1530static tree
1531fold_convert (t, arg1)
1532 register tree t;
1533 register tree arg1;
1534{

--- 109 unchanged lines hidden (view full) ---

1644 else if (TREE_CODE (type) == REAL_TYPE)
1645 {
1646#if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1647 if (TREE_CODE (arg1) == INTEGER_CST)
1648 return build_real_from_int_cst (type, arg1);
1649#endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
1650 if (TREE_CODE (arg1) == REAL_CST)
1651 {
1805/* Given T, a tree representing type conversion of ARG1, a constant,
1806 return a constant tree representing the result of conversion. */
1807
1808static tree
1809fold_convert (t, arg1)
1810 register tree t;
1811 register tree arg1;
1812{

--- 109 unchanged lines hidden (view full) ---

1922 else if (TREE_CODE (type) == REAL_TYPE)
1923 {
1924#if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1925 if (TREE_CODE (arg1) == INTEGER_CST)
1926 return build_real_from_int_cst (type, arg1);
1927#endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
1928 if (TREE_CODE (arg1) == REAL_CST)
1929 {
1930 struct fc_args args;
1931
1652 if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)))
1653 {
1654 t = arg1;
1655 TREE_TYPE (arg1) = type;
1656 return t;
1657 }
1932 if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)))
1933 {
1934 t = arg1;
1935 TREE_TYPE (arg1) = type;
1936 return t;
1937 }
1658 else if (setjmp (float_error))
1938
1939 /* Setup input for fold_convert_1() */
1940 args.arg1 = arg1;
1941 args.type = type;
1942
1943 if (do_float_handler (fold_convert_1, (PTR) &args))
1659 {
1944 {
1945 /* Receive output from fold_convert_1() */
1946 t = args.t;
1947 }
1948 else
1949 {
1950 /* We got an exception from fold_convert_1() */
1660 overflow = 1;
1661 t = copy_node (arg1);
1951 overflow = 1;
1952 t = copy_node (arg1);
1662 goto got_it;
1663 }
1953 }
1664 set_float_handler (float_error);
1665
1954
1666 t = build_real (type, real_value_truncate (TYPE_MODE (type),
1667 TREE_REAL_CST (arg1)));
1668 set_float_handler (NULL_PTR);
1669
1670 got_it:
1671 TREE_OVERFLOW (t)
1672 = TREE_OVERFLOW (arg1) | force_fit_type (t, overflow);
1673 TREE_CONSTANT_OVERFLOW (t)
1674 = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
1675 return t;
1676 }
1677 }
1678 TREE_CONSTANT (t) = 1;
1679 return t;
1680}
1681
1955 TREE_OVERFLOW (t)
1956 = TREE_OVERFLOW (arg1) | force_fit_type (t, overflow);
1957 TREE_CONSTANT_OVERFLOW (t)
1958 = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
1959 return t;
1960 }
1961 }
1962 TREE_CONSTANT (t) = 1;
1963 return t;
1964}
1965
1682/* Return an expr equal to X but certainly not valid as an lvalue.
1683 Also make sure it is not valid as an null pointer constant. */
1966/* Return an expr equal to X but certainly not valid as an lvalue. */
1684
1685tree
1686non_lvalue (x)
1687 tree x;
1688{
1689 tree result;
1690
1691 /* These things are certainly not lvalues. */
1692 if (TREE_CODE (x) == NON_LVALUE_EXPR
1693 || TREE_CODE (x) == INTEGER_CST
1694 || TREE_CODE (x) == REAL_CST
1695 || TREE_CODE (x) == STRING_CST
1696 || TREE_CODE (x) == ADDR_EXPR)
1967
1968tree
1969non_lvalue (x)
1970 tree x;
1971{
1972 tree result;
1973
1974 /* These things are certainly not lvalues. */
1975 if (TREE_CODE (x) == NON_LVALUE_EXPR
1976 || TREE_CODE (x) == INTEGER_CST
1977 || TREE_CODE (x) == REAL_CST
1978 || TREE_CODE (x) == STRING_CST
1979 || TREE_CODE (x) == ADDR_EXPR)
1697 {
1698 if (TREE_CODE (x) == INTEGER_CST && integer_zerop (x))
1699 {
1700 /* Use NOP_EXPR instead of NON_LVALUE_EXPR
1701 so convert_for_assignment won't strip it.
1702 This is so this 0 won't be treated as a null pointer constant. */
1703 result = build1 (NOP_EXPR, TREE_TYPE (x), x);
1704 TREE_CONSTANT (result) = TREE_CONSTANT (x);
1705 return result;
1706 }
1707 return x;
1708 }
1980 return x;
1709
1710 result = build1 (NON_LVALUE_EXPR, TREE_TYPE (x), x);
1711 TREE_CONSTANT (result) = TREE_CONSTANT (x);
1712 return result;
1713}
1714
1715/* Nonzero means lvalues are limited to those valid in pedantic ANSI C.
1716 Zero means allow extended lvalues. */

--- 206 unchanged lines hidden (view full) ---

1923 TREE_OPERAND (arg1, 0), 0)
1924 && operand_equal_p (TREE_OPERAND (arg0, 1),
1925 TREE_OPERAND (arg1, 1), 0)
1926 && operand_equal_p (TREE_OPERAND (arg0, 2),
1927 TREE_OPERAND (arg1, 2), 0));
1928 default:
1929 return 0;
1930 }
1981
1982 result = build1 (NON_LVALUE_EXPR, TREE_TYPE (x), x);
1983 TREE_CONSTANT (result) = TREE_CONSTANT (x);
1984 return result;
1985}
1986
1987/* Nonzero means lvalues are limited to those valid in pedantic ANSI C.
1988 Zero means allow extended lvalues. */

--- 206 unchanged lines hidden (view full) ---

2195 TREE_OPERAND (arg1, 0), 0)
2196 && operand_equal_p (TREE_OPERAND (arg0, 1),
2197 TREE_OPERAND (arg1, 1), 0)
2198 && operand_equal_p (TREE_OPERAND (arg0, 2),
2199 TREE_OPERAND (arg1, 2), 0));
2200 default:
2201 return 0;
2202 }
2203
2204 case 'e':
2205 if (TREE_CODE (arg0) == RTL_EXPR)
2206 return rtx_equal_p (RTL_EXPR_RTL (arg0), RTL_EXPR_RTL (arg1));
2207 return 0;
1931
1932 default:
1933 return 0;
1934 }
1935}
1936
1937/* Similar to operand_equal_p, but see if ARG0 might have been made by
1938 shorten_compare from ARG1 when ARG1 was being compared with OTHER.

--- 207 unchanged lines hidden (view full) ---

2146 old0, new0, old1, new1),
2147 eval_subst (TREE_OPERAND (arg, 1),
2148 old0, new0, old1, new1),
2149 eval_subst (TREE_OPERAND (arg, 2),
2150 old0, new0, old1, new1)));
2151 default:
2152 break;
2153 }
2208
2209 default:
2210 return 0;
2211 }
2212}
2213
2214/* Similar to operand_equal_p, but see if ARG0 might have been made by
2215 shorten_compare from ARG1 when ARG1 was being compared with OTHER.

--- 207 unchanged lines hidden (view full) ---

2423 old0, new0, old1, new1),
2424 eval_subst (TREE_OPERAND (arg, 1),
2425 old0, new0, old1, new1),
2426 eval_subst (TREE_OPERAND (arg, 2),
2427 old0, new0, old1, new1)));
2428 default:
2429 break;
2430 }
2154 /* fall through (???) */
2431 /* fall through - ??? */
2155
2156 case '<':
2157 {
2158 tree arg0 = TREE_OPERAND (arg, 0);
2159 tree arg1 = TREE_OPERAND (arg, 1);
2160
2161 /* We need to check both for exact equality and tree equality. The
2162 former will be true if the operand has a side-effect. In that

--- 68 unchanged lines hidden (view full) ---

2231
2232 /* If this is a comparison, we can simply invert it, except for
2233 floating-point non-equality comparisons, in which case we just
2234 enclose a TRUTH_NOT_EXPR around what we have. */
2235
2236 if (TREE_CODE_CLASS (code) == '<')
2237 {
2238 if (FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
2432
2433 case '<':
2434 {
2435 tree arg0 = TREE_OPERAND (arg, 0);
2436 tree arg1 = TREE_OPERAND (arg, 1);
2437
2438 /* We need to check both for exact equality and tree equality. The
2439 former will be true if the operand has a side-effect. In that

--- 68 unchanged lines hidden (view full) ---

2508
2509 /* If this is a comparison, we can simply invert it, except for
2510 floating-point non-equality comparisons, in which case we just
2511 enclose a TRUTH_NOT_EXPR around what we have. */
2512
2513 if (TREE_CODE_CLASS (code) == '<')
2514 {
2515 if (FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
2239 && code != NE_EXPR && code != EQ_EXPR)
2516 && !flag_fast_math && code != NE_EXPR && code != EQ_EXPR)
2240 return build1 (TRUTH_NOT_EXPR, type, arg);
2241 else
2242 return build (invert_tree_comparison (code), type,
2243 TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1));
2244 }
2245
2246 switch (code)
2247 {

--- 284 unchanged lines hidden (view full) ---

2532 the sign bit. */
2533
2534 if (lunsignedp)
2535 {
2536 if (! integer_zerop (const_binop (RSHIFT_EXPR,
2537 convert (unsigned_type, rhs),
2538 size_int (lbitsize), 0)))
2539 {
2517 return build1 (TRUTH_NOT_EXPR, type, arg);
2518 else
2519 return build (invert_tree_comparison (code), type,
2520 TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1));
2521 }
2522
2523 switch (code)
2524 {

--- 284 unchanged lines hidden (view full) ---

2809 the sign bit. */
2810
2811 if (lunsignedp)
2812 {
2813 if (! integer_zerop (const_binop (RSHIFT_EXPR,
2814 convert (unsigned_type, rhs),
2815 size_int (lbitsize), 0)))
2816 {
2540 warning ("comparison is always %s due to width of bitfield",
2541 code == NE_EXPR ? "one" : "zero");
2817 warning ("comparison is always %d due to width of bitfield",
2818 code == NE_EXPR);
2542 return convert (compare_type,
2543 (code == NE_EXPR
2544 ? integer_one_node : integer_zero_node));
2545 }
2546 }
2547 else
2548 {
2549 tree tem = const_binop (RSHIFT_EXPR, convert (signed_type, rhs),
2550 size_int (lbitsize - 1), 0);
2551 if (! integer_zerop (tem) && ! integer_all_onesp (tem))
2552 {
2819 return convert (compare_type,
2820 (code == NE_EXPR
2821 ? integer_one_node : integer_zero_node));
2822 }
2823 }
2824 else
2825 {
2826 tree tem = const_binop (RSHIFT_EXPR, convert (signed_type, rhs),
2827 size_int (lbitsize - 1), 0);
2828 if (! integer_zerop (tem) && ! integer_all_onesp (tem))
2829 {
2553 warning ("comparison is always %s due to width of bitfield",
2554 code == NE_EXPR ? "one" : "zero");
2830 warning ("comparison is always %d due to width of bitfield",
2831 code == NE_EXPR);
2555 return convert (compare_type,
2556 (code == NE_EXPR
2557 ? integer_one_node : integer_zero_node));
2558 }
2559 }
2560
2561 /* Single-bit compares should always be against zero. */
2562 if (lbitsize == 1 && ! integer_zerop (rhs))

--- 264 unchanged lines hidden (view full) ---

2827
2828static tree
2829make_range (exp, pin_p, plow, phigh)
2830 tree exp;
2831 int *pin_p;
2832 tree *plow, *phigh;
2833{
2834 enum tree_code code;
2832 return convert (compare_type,
2833 (code == NE_EXPR
2834 ? integer_one_node : integer_zero_node));
2835 }
2836 }
2837
2838 /* Single-bit compares should always be against zero. */
2839 if (lbitsize == 1 && ! integer_zerop (rhs))

--- 264 unchanged lines hidden (view full) ---

3104
3105static tree
3106make_range (exp, pin_p, plow, phigh)
3107 tree exp;
3108 int *pin_p;
3109 tree *plow, *phigh;
3110{
3111 enum tree_code code;
2835 tree arg0, arg1, type = NULL_TREE;
3112 tree arg0 = NULL_TREE, arg1 = NULL_TREE, type = NULL_TREE;
2836 tree orig_type = NULL_TREE;
2837 int in_p, n_in_p;
2838 tree low, high, n_low, n_high;
2839
2840 /* Start with simply saying "EXP != 0" and then look at the code of EXP
2841 and see if we can refine the range. Some of the cases below may not
2842 happen, but it doesn't seem worth worrying about this. We "continue"
2843 the outer loop when we've changed something; otherwise we "break"

--- 14 unchanged lines hidden (view full) ---

2858 type = TREE_TYPE (arg0);
2859 if (TREE_CODE_CLASS (code) == '2'
2860 || TREE_CODE_CLASS (code) == '<'
2861 || (TREE_CODE_CLASS (code) == 'e'
2862 && tree_code_length[(int) code] > 1))
2863 arg1 = TREE_OPERAND (exp, 1);
2864 }
2865
3113 tree orig_type = NULL_TREE;
3114 int in_p, n_in_p;
3115 tree low, high, n_low, n_high;
3116
3117 /* Start with simply saying "EXP != 0" and then look at the code of EXP
3118 and see if we can refine the range. Some of the cases below may not
3119 happen, but it doesn't seem worth worrying about this. We "continue"
3120 the outer loop when we've changed something; otherwise we "break"

--- 14 unchanged lines hidden (view full) ---

3135 type = TREE_TYPE (arg0);
3136 if (TREE_CODE_CLASS (code) == '2'
3137 || TREE_CODE_CLASS (code) == '<'
3138 || (TREE_CODE_CLASS (code) == 'e'
3139 && tree_code_length[(int) code] > 1))
3140 arg1 = TREE_OPERAND (exp, 1);
3141 }
3142
3143 /* Set ORIG_TYPE as soon as TYPE is non-null so that we do not
3144 lose a cast by accident. */
3145 if (type != NULL_TREE && orig_type == NULL_TREE)
3146 orig_type = type;
3147
2866 switch (code)
2867 {
2868 case TRUTH_NOT_EXPR:
2869 in_p = ! in_p, exp = arg0;
2870 continue;
2871
2872 case EQ_EXPR: case NE_EXPR:
2873 case LT_EXPR: case LE_EXPR: case GE_EXPR: case GT_EXPR:

--- 102 unchanged lines hidden (view full) ---

2976 }
2977 else
2978 low = n_low, high = n_high;
2979
2980 exp = arg0;
2981 continue;
2982
2983 case NOP_EXPR: case NON_LVALUE_EXPR: case CONVERT_EXPR:
3148 switch (code)
3149 {
3150 case TRUTH_NOT_EXPR:
3151 in_p = ! in_p, exp = arg0;
3152 continue;
3153
3154 case EQ_EXPR: case NE_EXPR:
3155 case LT_EXPR: case LE_EXPR: case GE_EXPR: case GT_EXPR:

--- 102 unchanged lines hidden (view full) ---

3258 }
3259 else
3260 low = n_low, high = n_high;
3261
3262 exp = arg0;
3263 continue;
3264
3265 case NOP_EXPR: case NON_LVALUE_EXPR: case CONVERT_EXPR:
2984 if (orig_type == NULL_TREE)
2985 orig_type = type;
2986 if (TYPE_PRECISION (type) > TYPE_PRECISION (orig_type))
2987 break;
2988
2989 if (! INTEGRAL_TYPE_P (type)
2990 || (low != 0 && ! int_fits_type_p (low, type))
2991 || (high != 0 && ! int_fits_type_p (high, type)))
2992 break;
2993

--- 331 unchanged lines hidden (view full) ---

3325 or_op ? ! in1_p : in1_p,
3326 low1, high1))))
3327 return build (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
3328 ? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
3329 TREE_TYPE (exp), lhs, rhs);
3330 }
3331 }
3332
3266 if (TYPE_PRECISION (type) > TYPE_PRECISION (orig_type))
3267 break;
3268
3269 if (! INTEGRAL_TYPE_P (type)
3270 || (low != 0 && ! int_fits_type_p (low, type))
3271 || (high != 0 && ! int_fits_type_p (high, type)))
3272 break;
3273

--- 331 unchanged lines hidden (view full) ---

3605 or_op ? ! in1_p : in1_p,
3606 low1, high1))))
3607 return build (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
3608 ? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
3609 TREE_TYPE (exp), lhs, rhs);
3610 }
3611 }
3612
3333
3334 return 0;
3335}
3336
3337/* Subroutine for fold_truthop: C is an INTEGER_CST interpreted as a P
3338 bit value. Arrange things so the extra bits will be set to zero if and
3339 only if C is signed-extended to its full width. If MASK is nonzero,
3340 it is an INTEGER_CST that should be AND'ed with the extra bits. */
3341

--- 84 unchanged lines hidden (view full) ---

3426 int xll_bitpos, xlr_bitpos, xrl_bitpos, xrr_bitpos;
3427 int lnbitsize, lnbitpos, rnbitsize, rnbitpos;
3428 int ll_unsignedp, lr_unsignedp, rl_unsignedp, rr_unsignedp;
3429 enum machine_mode ll_mode, lr_mode, rl_mode, rr_mode;
3430 enum machine_mode lnmode, rnmode;
3431 tree ll_mask, lr_mask, rl_mask, rr_mask;
3432 tree ll_and_mask, lr_and_mask, rl_and_mask, rr_and_mask;
3433 tree l_const, r_const;
3613 return 0;
3614}
3615
3616/* Subroutine for fold_truthop: C is an INTEGER_CST interpreted as a P
3617 bit value. Arrange things so the extra bits will be set to zero if and
3618 only if C is signed-extended to its full width. If MASK is nonzero,
3619 it is an INTEGER_CST that should be AND'ed with the extra bits. */
3620

--- 84 unchanged lines hidden (view full) ---

3705 int xll_bitpos, xlr_bitpos, xrl_bitpos, xrr_bitpos;
3706 int lnbitsize, lnbitpos, rnbitsize, rnbitpos;
3707 int ll_unsignedp, lr_unsignedp, rl_unsignedp, rr_unsignedp;
3708 enum machine_mode ll_mode, lr_mode, rl_mode, rr_mode;
3709 enum machine_mode lnmode, rnmode;
3710 tree ll_mask, lr_mask, rl_mask, rr_mask;
3711 tree ll_and_mask, lr_and_mask, rl_and_mask, rr_and_mask;
3712 tree l_const, r_const;
3434 tree type, result;
3713 tree lntype, rntype, result;
3435 int first_bit, end_bit;
3436 int volatilep;
3437
3438 /* Start by getting the comparison codes. Fail if anything is volatile.
3439 If one operand is a BIT_AND_EXPR with the constant one, treat it as if
3440 it were surrounded with a NE_EXPR. */
3441
3442 if (TREE_SIDE_EFFECTS (lhs) || TREE_SIDE_EFFECTS (rhs))

--- 79 unchanged lines hidden (view full) ---

3522 fail. However, we can convert a one-bit comparison against zero into
3523 the opposite comparison against that bit being set in the field. */
3524
3525 wanted_code = (code == TRUTH_AND_EXPR ? EQ_EXPR : NE_EXPR);
3526 if (lcode != wanted_code)
3527 {
3528 if (l_const && integer_zerop (l_const) && integer_pow2p (ll_mask))
3529 {
3714 int first_bit, end_bit;
3715 int volatilep;
3716
3717 /* Start by getting the comparison codes. Fail if anything is volatile.
3718 If one operand is a BIT_AND_EXPR with the constant one, treat it as if
3719 it were surrounded with a NE_EXPR. */
3720
3721 if (TREE_SIDE_EFFECTS (lhs) || TREE_SIDE_EFFECTS (rhs))

--- 79 unchanged lines hidden (view full) ---

3801 fail. However, we can convert a one-bit comparison against zero into
3802 the opposite comparison against that bit being set in the field. */
3803
3804 wanted_code = (code == TRUTH_AND_EXPR ? EQ_EXPR : NE_EXPR);
3805 if (lcode != wanted_code)
3806 {
3807 if (l_const && integer_zerop (l_const) && integer_pow2p (ll_mask))
3808 {
3530 if (ll_unsignedp || tree_log2 (ll_mask) + 1 < ll_bitsize)
3531 l_const = ll_mask;
3532 else
3533 /* Since ll_arg is a single bit bit mask, we can sign extend
3534 it appropriately with a NEGATE_EXPR.
3535 l_const is made a signed value here, but since for l_const != NULL
3536 lr_unsignedp is not used, we don't need to clear the latter. */
3537 l_const = fold (build1 (NEGATE_EXPR, TREE_TYPE (ll_arg),
3538 convert (TREE_TYPE (ll_arg), ll_mask)));
3809 /* Make the left operand unsigned, since we are only interested
3810 in the value of one bit. Otherwise we are doing the wrong
3811 thing below. */
3812 ll_unsignedp = 1;
3813 l_const = ll_mask;
3539 }
3540 else
3541 return 0;
3542 }
3543
3814 }
3815 else
3816 return 0;
3817 }
3818
3819 /* This is analogous to the code for l_const above. */
3544 if (rcode != wanted_code)
3545 {
3546 if (r_const && integer_zerop (r_const) && integer_pow2p (rl_mask))
3547 {
3820 if (rcode != wanted_code)
3821 {
3822 if (r_const && integer_zerop (r_const) && integer_pow2p (rl_mask))
3823 {
3548 if (rl_unsignedp || tree_log2 (rl_mask) + 1 < rl_bitsize)
3549 r_const = rl_mask;
3550 else
3551 /* This is analogous to the code for l_const above. */
3552 r_const = fold (build1 (NEGATE_EXPR, TREE_TYPE (rl_arg),
3553 convert (TREE_TYPE (rl_arg), rl_mask)));
3824 rl_unsignedp = 1;
3825 r_const = rl_mask;
3554 }
3555 else
3556 return 0;
3557 }
3558
3559 /* See if we can find a mode that contains both fields being compared on
3560 the left. If we can't, fail. Otherwise, update all constants and masks
3561 to be relative to a field of that size. */
3562 first_bit = MIN (ll_bitpos, rl_bitpos);
3563 end_bit = MAX (ll_bitpos + ll_bitsize, rl_bitpos + rl_bitsize);
3564 lnmode = get_best_mode (end_bit - first_bit, first_bit,
3565 TYPE_ALIGN (TREE_TYPE (ll_inner)), word_mode,
3566 volatilep);
3567 if (lnmode == VOIDmode)
3568 return 0;
3569
3570 lnbitsize = GET_MODE_BITSIZE (lnmode);
3571 lnbitpos = first_bit & ~ (lnbitsize - 1);
3826 }
3827 else
3828 return 0;
3829 }
3830
3831 /* See if we can find a mode that contains both fields being compared on
3832 the left. If we can't, fail. Otherwise, update all constants and masks
3833 to be relative to a field of that size. */
3834 first_bit = MIN (ll_bitpos, rl_bitpos);
3835 end_bit = MAX (ll_bitpos + ll_bitsize, rl_bitpos + rl_bitsize);
3836 lnmode = get_best_mode (end_bit - first_bit, first_bit,
3837 TYPE_ALIGN (TREE_TYPE (ll_inner)), word_mode,
3838 volatilep);
3839 if (lnmode == VOIDmode)
3840 return 0;
3841
3842 lnbitsize = GET_MODE_BITSIZE (lnmode);
3843 lnbitpos = first_bit & ~ (lnbitsize - 1);
3572 type = type_for_size (lnbitsize, 1);
3844 lntype = type_for_size (lnbitsize, 1);
3573 xll_bitpos = ll_bitpos - lnbitpos, xrl_bitpos = rl_bitpos - lnbitpos;
3574
3575 if (BYTES_BIG_ENDIAN)
3576 {
3577 xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize;
3578 xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize;
3579 }
3580
3845 xll_bitpos = ll_bitpos - lnbitpos, xrl_bitpos = rl_bitpos - lnbitpos;
3846
3847 if (BYTES_BIG_ENDIAN)
3848 {
3849 xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize;
3850 xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize;
3851 }
3852
3581 ll_mask = const_binop (LSHIFT_EXPR, convert (type, ll_mask),
3853 ll_mask = const_binop (LSHIFT_EXPR, convert (lntype, ll_mask),
3582 size_int (xll_bitpos), 0);
3854 size_int (xll_bitpos), 0);
3583 rl_mask = const_binop (LSHIFT_EXPR, convert (type, rl_mask),
3855 rl_mask = const_binop (LSHIFT_EXPR, convert (lntype, rl_mask),
3584 size_int (xrl_bitpos), 0);
3585
3586 if (l_const)
3587 {
3856 size_int (xrl_bitpos), 0);
3857
3858 if (l_const)
3859 {
3588 l_const = convert (type, l_const);
3860 l_const = convert (lntype, l_const);
3589 l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask);
3590 l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos), 0);
3591 if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
3592 fold (build1 (BIT_NOT_EXPR,
3861 l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask);
3862 l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos), 0);
3863 if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
3864 fold (build1 (BIT_NOT_EXPR,
3593 type, ll_mask)),
3865 lntype, ll_mask)),
3594 0)))
3595 {
3866 0)))
3867 {
3596 warning ("comparison is always %s",
3597 wanted_code == NE_EXPR ? "one" : "zero");
3868 warning ("comparison is always %d", wanted_code == NE_EXPR);
3598
3599 return convert (truth_type,
3600 wanted_code == NE_EXPR
3601 ? integer_one_node : integer_zero_node);
3602 }
3603 }
3604 if (r_const)
3605 {
3869
3870 return convert (truth_type,
3871 wanted_code == NE_EXPR
3872 ? integer_one_node : integer_zero_node);
3873 }
3874 }
3875 if (r_const)
3876 {
3606 r_const = convert (type, r_const);
3877 r_const = convert (lntype, r_const);
3607 r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
3608 r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos), 0);
3609 if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
3610 fold (build1 (BIT_NOT_EXPR,
3878 r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
3879 r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos), 0);
3880 if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
3881 fold (build1 (BIT_NOT_EXPR,
3611 type, rl_mask)),
3882 lntype, rl_mask)),
3612 0)))
3613 {
3883 0)))
3884 {
3614 warning ("comparison is always %s",
3615 wanted_code == NE_EXPR ? "one" : "zero");
3616
3885 warning ("comparison is always %d", wanted_code == NE_EXPR);
3886
3617 return convert (truth_type,
3618 wanted_code == NE_EXPR
3619 ? integer_one_node : integer_zero_node);
3620 }
3621 }
3622
3623 /* If the right sides are not constant, do the same for it. Also,
3624 disallow this optimization if a size or signedness mismatch occurs

--- 12 unchanged lines hidden (view full) ---

3637 rnmode = get_best_mode (end_bit - first_bit, first_bit,
3638 TYPE_ALIGN (TREE_TYPE (lr_inner)), word_mode,
3639 volatilep);
3640 if (rnmode == VOIDmode)
3641 return 0;
3642
3643 rnbitsize = GET_MODE_BITSIZE (rnmode);
3644 rnbitpos = first_bit & ~ (rnbitsize - 1);
3887 return convert (truth_type,
3888 wanted_code == NE_EXPR
3889 ? integer_one_node : integer_zero_node);
3890 }
3891 }
3892
3893 /* If the right sides are not constant, do the same for it. Also,
3894 disallow this optimization if a size or signedness mismatch occurs

--- 12 unchanged lines hidden (view full) ---

3907 rnmode = get_best_mode (end_bit - first_bit, first_bit,
3908 TYPE_ALIGN (TREE_TYPE (lr_inner)), word_mode,
3909 volatilep);
3910 if (rnmode == VOIDmode)
3911 return 0;
3912
3913 rnbitsize = GET_MODE_BITSIZE (rnmode);
3914 rnbitpos = first_bit & ~ (rnbitsize - 1);
3915 rntype = type_for_size (rnbitsize, 1);
3645 xlr_bitpos = lr_bitpos - rnbitpos, xrr_bitpos = rr_bitpos - rnbitpos;
3646
3647 if (BYTES_BIG_ENDIAN)
3648 {
3649 xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize;
3650 xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize;
3651 }
3652
3916 xlr_bitpos = lr_bitpos - rnbitpos, xrr_bitpos = rr_bitpos - rnbitpos;
3917
3918 if (BYTES_BIG_ENDIAN)
3919 {
3920 xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize;
3921 xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize;
3922 }
3923
3653 lr_mask = const_binop (LSHIFT_EXPR, convert (type, lr_mask),
3924 lr_mask = const_binop (LSHIFT_EXPR, convert (rntype, lr_mask),
3654 size_int (xlr_bitpos), 0);
3925 size_int (xlr_bitpos), 0);
3655 rr_mask = const_binop (LSHIFT_EXPR, convert (type, rr_mask),
3926 rr_mask = const_binop (LSHIFT_EXPR, convert (rntype, rr_mask),
3656 size_int (xrr_bitpos), 0);
3657
3658 /* Make a mask that corresponds to both fields being compared.
3927 size_int (xrr_bitpos), 0);
3928
3929 /* Make a mask that corresponds to both fields being compared.
3659 Do this for both items being compared. If the masks agree,
3660 we can do this by masking both and comparing the masked
3930 Do this for both items being compared. If the operands are the
3931 same size and the bits being compared are in the same position
3932 then we can do this by masking both and comparing the masked
3661 results. */
3662 ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
3663 lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask, 0);
3933 results. */
3934 ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
3935 lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask, 0);
3664 if (operand_equal_p (ll_mask, lr_mask, 0) && lnbitsize == rnbitsize)
3936 if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos)
3665 {
3937 {
3666 lhs = make_bit_field_ref (ll_inner, type, lnbitsize, lnbitpos,
3938 lhs = make_bit_field_ref (ll_inner, lntype, lnbitsize, lnbitpos,
3667 ll_unsignedp || rl_unsignedp);
3939 ll_unsignedp || rl_unsignedp);
3668 rhs = make_bit_field_ref (lr_inner, type, rnbitsize, rnbitpos,
3669 lr_unsignedp || rr_unsignedp);
3670 if (! all_ones_mask_p (ll_mask, lnbitsize))
3940 if (! all_ones_mask_p (ll_mask, lnbitsize))
3671 {
3672 lhs = build (BIT_AND_EXPR, type, lhs, ll_mask);
3673 rhs = build (BIT_AND_EXPR, type, rhs, ll_mask);
3674 }
3941 lhs = build (BIT_AND_EXPR, lntype, lhs, ll_mask);
3942
3943 rhs = make_bit_field_ref (lr_inner, rntype, rnbitsize, rnbitpos,
3944 lr_unsignedp || rr_unsignedp);
3945 if (! all_ones_mask_p (lr_mask, rnbitsize))
3946 rhs = build (BIT_AND_EXPR, rntype, rhs, lr_mask);
3947
3675 return build (wanted_code, truth_type, lhs, rhs);
3676 }
3677
3678 /* There is still another way we can do something: If both pairs of
3679 fields being compared are adjacent, we may be able to make a wider
3948 return build (wanted_code, truth_type, lhs, rhs);
3949 }
3950
3951 /* There is still another way we can do something: If both pairs of
3952 fields being compared are adjacent, we may be able to make a wider
3680 field containing them both. */
3953 field containing them both.
3954
3955 Note that we still must mask the lhs/rhs expressions. Furthermore,
3956 the mask must be shifted to account for the shift done by
3957 make_bit_field_ref. */
3681 if ((ll_bitsize + ll_bitpos == rl_bitpos
3682 && lr_bitsize + lr_bitpos == rr_bitpos)
3683 || (ll_bitpos == rl_bitpos + rl_bitsize
3684 && lr_bitpos == rr_bitpos + rr_bitsize))
3958 if ((ll_bitsize + ll_bitpos == rl_bitpos
3959 && lr_bitsize + lr_bitpos == rr_bitpos)
3960 || (ll_bitpos == rl_bitpos + rl_bitsize
3961 && lr_bitpos == rr_bitpos + rr_bitsize))
3685 return build (wanted_code, truth_type,
3686 make_bit_field_ref (ll_inner, type,
3687 ll_bitsize + rl_bitsize,
3688 MIN (ll_bitpos, rl_bitpos),
3689 ll_unsignedp),
3690 make_bit_field_ref (lr_inner, type,
3691 lr_bitsize + rr_bitsize,
3692 MIN (lr_bitpos, rr_bitpos),
3693 lr_unsignedp));
3962 {
3963 tree type;
3694
3964
3965 lhs = make_bit_field_ref (ll_inner, lntype, ll_bitsize + rl_bitsize,
3966 MIN (ll_bitpos, rl_bitpos), ll_unsignedp);
3967 rhs = make_bit_field_ref (lr_inner, rntype, lr_bitsize + rr_bitsize,
3968 MIN (lr_bitpos, rr_bitpos), lr_unsignedp);
3969
3970 ll_mask = const_binop (RSHIFT_EXPR, ll_mask,
3971 size_int (MIN (xll_bitpos, xrl_bitpos)), 0);
3972 lr_mask = const_binop (RSHIFT_EXPR, lr_mask,
3973 size_int (MIN (xlr_bitpos, xrr_bitpos)), 0);
3974
3975 /* Convert to the smaller type before masking out unwanted bits. */
3976 type = lntype;
3977 if (lntype != rntype)
3978 {
3979 if (lnbitsize > rnbitsize)
3980 {
3981 lhs = convert (rntype, lhs);
3982 ll_mask = convert (rntype, ll_mask);
3983 type = rntype;
3984 }
3985 else if (lnbitsize < rnbitsize)
3986 {
3987 rhs = convert (lntype, rhs);
3988 lr_mask = convert (lntype, lr_mask);
3989 type = lntype;
3990 }
3991 }
3992
3993 if (! all_ones_mask_p (ll_mask, ll_bitsize + rl_bitsize))
3994 lhs = build (BIT_AND_EXPR, type, lhs, ll_mask);
3995
3996 if (! all_ones_mask_p (lr_mask, lr_bitsize + rr_bitsize))
3997 rhs = build (BIT_AND_EXPR, type, rhs, lr_mask);
3998
3999 return build (wanted_code, truth_type, lhs, rhs);
4000 }
4001
3695 return 0;
3696 }
3697
3698 /* Handle the case of comparisons with constants. If there is something in
3699 common between the masks, those bits of the constants must be the same.
3700 If not, the condition is always false. Test for this to avoid generating
3701 incorrect code below. */
3702 result = const_binop (BIT_AND_EXPR, ll_mask, rl_mask, 0);
3703 if (! integer_zerop (result)
3704 && simple_cst_equal (const_binop (BIT_AND_EXPR, result, l_const, 0),
3705 const_binop (BIT_AND_EXPR, result, r_const, 0)) != 1)
3706 {
3707 if (wanted_code == NE_EXPR)
3708 {
3709 warning ("`or' of unmatched not-equal tests is always 1");
3710 return convert (truth_type, integer_one_node);
3711 }
3712 else
3713 {
4002 return 0;
4003 }
4004
4005 /* Handle the case of comparisons with constants. If there is something in
4006 common between the masks, those bits of the constants must be the same.
4007 If not, the condition is always false. Test for this to avoid generating
4008 incorrect code below. */
4009 result = const_binop (BIT_AND_EXPR, ll_mask, rl_mask, 0);
4010 if (! integer_zerop (result)
4011 && simple_cst_equal (const_binop (BIT_AND_EXPR, result, l_const, 0),
4012 const_binop (BIT_AND_EXPR, result, r_const, 0)) != 1)
4013 {
4014 if (wanted_code == NE_EXPR)
4015 {
4016 warning ("`or' of unmatched not-equal tests is always 1");
4017 return convert (truth_type, integer_one_node);
4018 }
4019 else
4020 {
3714 warning ("`and' of mutually exclusive equal-tests is always zero");
4021 warning ("`and' of mutually exclusive equal-tests is always 0");
3715 return convert (truth_type, integer_zero_node);
3716 }
3717 }
3718
3719 /* Construct the expression we will return. First get the component
3720 reference we will make. Unless the mask is all ones the width of
3721 that field, perform the mask operation. Then compare with the
3722 merged constant. */
4022 return convert (truth_type, integer_zero_node);
4023 }
4024 }
4025
4026 /* Construct the expression we will return. First get the component
4027 reference we will make. Unless the mask is all ones the width of
4028 that field, perform the mask operation. Then compare with the
4029 merged constant. */
3723 result = make_bit_field_ref (ll_inner, type, lnbitsize, lnbitpos,
4030 result = make_bit_field_ref (ll_inner, lntype, lnbitsize, lnbitpos,
3724 ll_unsignedp || rl_unsignedp);
3725
3726 ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
3727 if (! all_ones_mask_p (ll_mask, lnbitsize))
4031 ll_unsignedp || rl_unsignedp);
4032
4033 ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
4034 if (! all_ones_mask_p (ll_mask, lnbitsize))
3728 result = build (BIT_AND_EXPR, type, result, ll_mask);
4035 result = build (BIT_AND_EXPR, lntype, result, ll_mask);
3729
3730 return build (wanted_code, truth_type, result,
3731 const_binop (BIT_IOR_EXPR, l_const, r_const, 0));
3732}
3733
3734/* If T contains a COMPOUND_EXPR which was inserted merely to evaluate
3735 S, a SAVE_EXPR, return the expression actually being evaluated. Note
3736 that we may sometimes modify the tree. */

--- 46 unchanged lines hidden (view full) ---

3783 else
3784 {
3785 tree t = build_int_2 (value, 0);
3786 TREE_TYPE (t) = type;
3787 return t;
3788 }
3789}
3790
4036
4037 return build (wanted_code, truth_type, result,
4038 const_binop (BIT_IOR_EXPR, l_const, r_const, 0));
4039}
4040
4041/* If T contains a COMPOUND_EXPR which was inserted merely to evaluate
4042 S, a SAVE_EXPR, return the expression actually being evaluated. Note
4043 that we may sometimes modify the tree. */

--- 46 unchanged lines hidden (view full) ---

4090 else
4091 {
4092 tree t = build_int_2 (value, 0);
4093 TREE_TYPE (t) = type;
4094 return t;
4095 }
4096}
4097
4098/* Utility function for the following routine, to see how complex a nesting of
4099 COND_EXPRs can be. EXPR is the expression and LIMIT is a count beyond which
4100 we don't care (to avoid spending too much time on complex expressions.). */
4101
4102static int
4103count_cond (expr, lim)
4104 tree expr;
4105 int lim;
4106{
4107 int true, false;
4108
4109 if (TREE_CODE (expr) != COND_EXPR)
4110 return 0;
4111 else if (lim <= 0)
4112 return 0;
4113
4114 true = count_cond (TREE_OPERAND (expr, 1), lim - 1);
4115 false = count_cond (TREE_OPERAND (expr, 2), lim - 1 - true);
4116 return MIN (lim, 1 + true + false);
4117}
4118
3791/* Perform constant folding and related simplification of EXPR.
3792 The related simplifications include x*1 => x, x*0 => 0, etc.,
3793 and application of the associative law.
3794 NOP_EXPR conversions may be removed freely (as long as we
3795 are careful not to change the C type of the overall expression)
3796 We cannot simplify through a CONVERT_EXPR, FIX_EXPR or FLOAT_EXPR,
3797 but we can constant-fold them if they have constant operands. */
3798

--- 207 unchanged lines hidden (view full) ---

4006 {
4007 if (TREE_CODE (arg1) == COMPOUND_EXPR)
4008 return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
4009 fold (build (code, type,
4010 arg0, TREE_OPERAND (arg1, 1))));
4011 else if ((TREE_CODE (arg1) == COND_EXPR
4012 || (TREE_CODE_CLASS (TREE_CODE (arg1)) == '<'
4013 && TREE_CODE_CLASS (code) != '<'))
4119/* Perform constant folding and related simplification of EXPR.
4120 The related simplifications include x*1 => x, x*0 => 0, etc.,
4121 and application of the associative law.
4122 NOP_EXPR conversions may be removed freely (as long as we
4123 are careful not to change the C type of the overall expression)
4124 We cannot simplify through a CONVERT_EXPR, FIX_EXPR or FLOAT_EXPR,
4125 but we can constant-fold them if they have constant operands. */
4126

--- 207 unchanged lines hidden (view full) ---

4334 {
4335 if (TREE_CODE (arg1) == COMPOUND_EXPR)
4336 return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
4337 fold (build (code, type,
4338 arg0, TREE_OPERAND (arg1, 1))));
4339 else if ((TREE_CODE (arg1) == COND_EXPR
4340 || (TREE_CODE_CLASS (TREE_CODE (arg1)) == '<'
4341 && TREE_CODE_CLASS (code) != '<'))
4342 && (TREE_CODE (arg0) != COND_EXPR
4343 || count_cond (arg0, 25) + count_cond (arg1, 25) <= 25)
4014 && (! TREE_SIDE_EFFECTS (arg0)
4015 || (current_function_decl != 0
4016 && ! contains_placeholder_p (arg0))))
4017 {
4018 tree test, true_value, false_value;
4019 tree lhs = 0, rhs = 0;
4020
4021 if (TREE_CODE (arg1) == COND_EXPR)

--- 57 unchanged lines hidden (view full) ---

4079 }
4080
4081 else if (TREE_CODE (arg0) == COMPOUND_EXPR)
4082 return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
4083 fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
4084 else if ((TREE_CODE (arg0) == COND_EXPR
4085 || (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
4086 && TREE_CODE_CLASS (code) != '<'))
4344 && (! TREE_SIDE_EFFECTS (arg0)
4345 || (current_function_decl != 0
4346 && ! contains_placeholder_p (arg0))))
4347 {
4348 tree test, true_value, false_value;
4349 tree lhs = 0, rhs = 0;
4350
4351 if (TREE_CODE (arg1) == COND_EXPR)

--- 57 unchanged lines hidden (view full) ---

4409 }
4410
4411 else if (TREE_CODE (arg0) == COMPOUND_EXPR)
4412 return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
4413 fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
4414 else if ((TREE_CODE (arg0) == COND_EXPR
4415 || (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
4416 && TREE_CODE_CLASS (code) != '<'))
4417 && (TREE_CODE (arg1) != COND_EXPR
4418 || count_cond (arg0, 25) + count_cond (arg1, 25) <= 25)
4087 && (! TREE_SIDE_EFFECTS (arg1)
4088 || (current_function_decl != 0
4089 && ! contains_placeholder_p (arg1))))
4090 {
4091 tree test, true_value, false_value;
4092 tree lhs = 0, rhs = 0;
4093
4094 if (TREE_CODE (arg0) == COND_EXPR)

--- 325 unchanged lines hidden (view full) ---

4420 && integer_zerop (const_binop (BIT_AND_EXPR,
4421 TREE_OPERAND (arg0, 1),
4422 TREE_OPERAND (arg1, 1), 0)))
4423 {
4424 code = BIT_IOR_EXPR;
4425 goto bit_ior;
4426 }
4427
4419 && (! TREE_SIDE_EFFECTS (arg1)
4420 || (current_function_decl != 0
4421 && ! contains_placeholder_p (arg1))))
4422 {
4423 tree test, true_value, false_value;
4424 tree lhs = 0, rhs = 0;
4425
4426 if (TREE_CODE (arg0) == COND_EXPR)

--- 325 unchanged lines hidden (view full) ---

4752 && integer_zerop (const_binop (BIT_AND_EXPR,
4753 TREE_OPERAND (arg0, 1),
4754 TREE_OPERAND (arg1, 1), 0)))
4755 {
4756 code = BIT_IOR_EXPR;
4757 goto bit_ior;
4758 }
4759
4428 /* (A * C) + (B * C) -> (A+B) * C. Since we are most concerned
4429 about the case where C is a constant, just try one of the
4430 four possibilities. */
4760 if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR)
4761 {
4762 tree arg00, arg01, arg10, arg11;
4763 tree alt0 = NULL_TREE, alt1 = NULL_TREE, same;
4431
4764
4432 if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR
4433 && operand_equal_p (TREE_OPERAND (arg0, 1),
4434 TREE_OPERAND (arg1, 1), 0))
4435 return fold (build (MULT_EXPR, type,
4436 fold (build (PLUS_EXPR, type,
4437 TREE_OPERAND (arg0, 0),
4438 TREE_OPERAND (arg1, 0))),
4439 TREE_OPERAND (arg0, 1)));
4765 /* (A * C) + (B * C) -> (A+B) * C.
4766 We are most concerned about the case where C is a constant,
4767 but other combinations show up during loop reduction. Since
4768 it is not difficult, try all four possibilities. */
4769
4770 arg00 = TREE_OPERAND (arg0, 0);
4771 arg01 = TREE_OPERAND (arg0, 1);
4772 arg10 = TREE_OPERAND (arg1, 0);
4773 arg11 = TREE_OPERAND (arg1, 1);
4774 same = NULL_TREE;
4775
4776 if (operand_equal_p (arg01, arg11, 0))
4777 same = arg01, alt0 = arg00, alt1 = arg10;
4778 else if (operand_equal_p (arg00, arg10, 0))
4779 same = arg00, alt0 = arg01, alt1 = arg11;
4780 else if (operand_equal_p (arg00, arg11, 0))
4781 same = arg00, alt0 = arg01, alt1 = arg10;
4782 else if (operand_equal_p (arg01, arg10, 0))
4783 same = arg01, alt0 = arg00, alt1 = arg11;
4784
4785 if (same)
4786 return fold (build (MULT_EXPR, type,
4787 fold (build (PLUS_EXPR, type, alt0, alt1)),
4788 same));
4789 }
4440 }
4441 /* In IEEE floating point, x+0 may not equal x. */
4442 else if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
4443 || flag_fast_math)
4444 && real_zerop (arg1))
4445 return non_lvalue (convert (type, arg0));
4446 associate:
4447 /* In most languages, can't associate operations on floats

--- 237 unchanged lines hidden (view full) ---

4685 && operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1,0), 0)
4686 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
4687 {
4688 register tree tree01, tree11;
4689 register enum tree_code code01, code11;
4690
4691 tree01 = TREE_OPERAND (arg0, 1);
4692 tree11 = TREE_OPERAND (arg1, 1);
4790 }
4791 /* In IEEE floating point, x+0 may not equal x. */
4792 else if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
4793 || flag_fast_math)
4794 && real_zerop (arg1))
4795 return non_lvalue (convert (type, arg0));
4796 associate:
4797 /* In most languages, can't associate operations on floats

--- 237 unchanged lines hidden (view full) ---

5035 && operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1,0), 0)
5036 && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
5037 {
5038 register tree tree01, tree11;
5039 register enum tree_code code01, code11;
5040
5041 tree01 = TREE_OPERAND (arg0, 1);
5042 tree11 = TREE_OPERAND (arg1, 1);
5043 STRIP_NOPS (tree01);
5044 STRIP_NOPS (tree11);
4693 code01 = TREE_CODE (tree01);
4694 code11 = TREE_CODE (tree11);
4695 if (code01 == INTEGER_CST
4696 && code11 == INTEGER_CST
4697 && TREE_INT_CST_HIGH (tree01) == 0
4698 && TREE_INT_CST_HIGH (tree11) == 0
4699 && ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW (tree11))
4700 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))))
4701 return build (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0),
4702 code0 == LSHIFT_EXPR ? tree01 : tree11);
5045 code01 = TREE_CODE (tree01);
5046 code11 = TREE_CODE (tree11);
5047 if (code01 == INTEGER_CST
5048 && code11 == INTEGER_CST
5049 && TREE_INT_CST_HIGH (tree01) == 0
5050 && TREE_INT_CST_HIGH (tree11) == 0
5051 && ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW (tree11))
5052 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))))
5053 return build (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0),
5054 code0 == LSHIFT_EXPR ? tree01 : tree11);
4703 else if (code11 == MINUS_EXPR
4704 && TREE_CODE (TREE_OPERAND (tree11, 0)) == INTEGER_CST
4705 && TREE_INT_CST_HIGH (TREE_OPERAND (tree11, 0)) == 0
4706 && TREE_INT_CST_LOW (TREE_OPERAND (tree11, 0))
4707 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))
4708 && operand_equal_p (tree01, TREE_OPERAND (tree11, 1), 0))
4709 return build (code0 == LSHIFT_EXPR ? LROTATE_EXPR : RROTATE_EXPR,
4710 type, TREE_OPERAND (arg0, 0), tree01);
4711 else if (code01 == MINUS_EXPR
4712 && TREE_CODE (TREE_OPERAND (tree01, 0)) == INTEGER_CST
4713 && TREE_INT_CST_HIGH (TREE_OPERAND (tree01, 0)) == 0
4714 && TREE_INT_CST_LOW (TREE_OPERAND (tree01, 0))
4715 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))
4716 && operand_equal_p (tree11, TREE_OPERAND (tree01, 1), 0))
4717 return build (code0 != LSHIFT_EXPR ? LROTATE_EXPR : RROTATE_EXPR,
4718 type, TREE_OPERAND (arg0, 0), tree11);
5055 else if (code11 == MINUS_EXPR)
5056 {
5057 tree tree110, tree111;
5058 tree110 = TREE_OPERAND (tree11, 0);
5059 tree111 = TREE_OPERAND (tree11, 1);
5060 STRIP_NOPS (tree110);
5061 STRIP_NOPS (tree111);
5062 if (TREE_CODE (tree110) == INTEGER_CST
5063 && TREE_INT_CST_HIGH (tree110) == 0
5064 && (TREE_INT_CST_LOW (tree110)
5065 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0))))
5066 && operand_equal_p (tree01, tree111, 0))
5067 return build ((code0 == LSHIFT_EXPR
5068 ? LROTATE_EXPR
5069 : RROTATE_EXPR),
5070 type, TREE_OPERAND (arg0, 0), tree01);
5071 }
5072 else if (code01 == MINUS_EXPR)
5073 {
5074 tree tree010, tree011;
5075 tree010 = TREE_OPERAND (tree01, 0);
5076 tree011 = TREE_OPERAND (tree01, 1);
5077 STRIP_NOPS (tree010);
5078 STRIP_NOPS (tree011);
5079 if (TREE_CODE (tree010) == INTEGER_CST
5080 && TREE_INT_CST_HIGH (tree010) == 0
5081 && (TREE_INT_CST_LOW (tree010)
5082 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0))))
5083 && operand_equal_p (tree11, tree011, 0))
5084 return build ((code0 != LSHIFT_EXPR
5085 ? LROTATE_EXPR
5086 : RROTATE_EXPR),
5087 type, TREE_OPERAND (arg0, 0), tree11);
5088 }
4719 }
4720
4721 goto associate;
4722 }
4723
4724 case BIT_XOR_EXPR:
4725 if (integer_zerop (arg1))
4726 return non_lvalue (convert (type, arg0));

--- 1092 unchanged lines hidden (view full) ---

5819 anything. */
5820 tem = invert_truthvalue (arg0);
5821
5822 if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
5823 {
5824 t = build (code, type, tem,
5825 TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
5826 arg0 = tem;
5089 }
5090
5091 goto associate;
5092 }
5093
5094 case BIT_XOR_EXPR:
5095 if (integer_zerop (arg1))
5096 return non_lvalue (convert (type, arg0));

--- 1092 unchanged lines hidden (view full) ---

6189 anything. */
6190 tem = invert_truthvalue (arg0);
6191
6192 if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
6193 {
6194 t = build (code, type, tem,
6195 TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
6196 arg0 = tem;
5827 arg1 = TREE_OPERAND (t, 2);
6197 /* arg1 should be the first argument of the new T. */
6198 arg1 = TREE_OPERAND (t, 1);
5828 STRIP_NOPS (arg1);
5829 }
5830 }
5831
5832 /* If we have A op B ? A : C, we may be able to convert this to a
5833 simpler expression, depending on the operation and the values
5834 of B and C. IEEE floating point prevents this though,
5835 because A or B might be -0.0 or a NaN. */

--- 21 unchanged lines hidden (view full) ---

5857 {
5858 case EQ_EXPR:
5859 return pedantic_non_lvalue
5860 (fold (build1 (NEGATE_EXPR, type, arg1)));
5861 case NE_EXPR:
5862 return pedantic_non_lvalue (convert (type, arg1));
5863 case GE_EXPR:
5864 case GT_EXPR:
6199 STRIP_NOPS (arg1);
6200 }
6201 }
6202
6203 /* If we have A op B ? A : C, we may be able to convert this to a
6204 simpler expression, depending on the operation and the values
6205 of B and C. IEEE floating point prevents this though,
6206 because A or B might be -0.0 or a NaN. */

--- 21 unchanged lines hidden (view full) ---

6228 {
6229 case EQ_EXPR:
6230 return pedantic_non_lvalue
6231 (fold (build1 (NEGATE_EXPR, type, arg1)));
6232 case NE_EXPR:
6233 return pedantic_non_lvalue (convert (type, arg1));
6234 case GE_EXPR:
6235 case GT_EXPR:
6236 if (TREE_UNSIGNED (TREE_TYPE (arg1)))
6237 arg1 = convert (signed_type (TREE_TYPE (arg1)), arg1);
5865 return pedantic_non_lvalue
5866 (convert (type, fold (build1 (ABS_EXPR,
5867 TREE_TYPE (arg1), arg1))));
5868 case LE_EXPR:
5869 case LT_EXPR:
6238 return pedantic_non_lvalue
6239 (convert (type, fold (build1 (ABS_EXPR,
6240 TREE_TYPE (arg1), arg1))));
6241 case LE_EXPR:
6242 case LT_EXPR:
6243 if (TREE_UNSIGNED (TREE_TYPE (arg1)))
6244 arg1 = convert (signed_type (TREE_TYPE (arg1)), arg1);
5870 return pedantic_non_lvalue
5871 (fold (build1 (NEGATE_EXPR, type,
5872 convert (type,
5873 fold (build1 (ABS_EXPR,
5874 TREE_TYPE (arg1),
5875 arg1))))));
5876 default:
5877 abort ();

--- 130 unchanged lines hidden (view full) ---

6008 anything. */
6009 tem = invert_truthvalue (arg0);
6010
6011 if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
6012 {
6013 t = build (code, type, tem,
6014 TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
6015 arg0 = tem;
6245 return pedantic_non_lvalue
6246 (fold (build1 (NEGATE_EXPR, type,
6247 convert (type,
6248 fold (build1 (ABS_EXPR,
6249 TREE_TYPE (arg1),
6250 arg1))))));
6251 default:
6252 abort ();

--- 130 unchanged lines hidden (view full) ---

6383 anything. */
6384 tem = invert_truthvalue (arg0);
6385
6386 if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
6387 {
6388 t = build (code, type, tem,
6389 TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
6390 arg0 = tem;
6016 arg1 = TREE_OPERAND (t, 2);
6391 /* arg1 should be the first argument of the new T. */
6392 arg1 = TREE_OPERAND (t, 1);
6017 STRIP_NOPS (arg1);
6018 }
6019 }
6020
6021 /* Convert A ? 1 : 0 to simply A. */
6022 if (integer_onep (TREE_OPERAND (t, 1))
6023 && integer_zerop (TREE_OPERAND (t, 2))
6024 /* If we try to convert TREE_OPERAND (t, 0) to our type, the

--- 19 unchanged lines hidden (view full) ---

6044
6045 case COMPOUND_EXPR:
6046 /* When pedantic, a compound expression can be neither an lvalue
6047 nor an integer constant expression. */
6048 if (TREE_SIDE_EFFECTS (arg0) || pedantic)
6049 return t;
6050 /* Don't let (0, 0) be null pointer constant. */
6051 if (integer_zerop (arg1))
6393 STRIP_NOPS (arg1);
6394 }
6395 }
6396
6397 /* Convert A ? 1 : 0 to simply A. */
6398 if (integer_onep (TREE_OPERAND (t, 1))
6399 && integer_zerop (TREE_OPERAND (t, 2))
6400 /* If we try to convert TREE_OPERAND (t, 0) to our type, the

--- 19 unchanged lines hidden (view full) ---

6420
6421 case COMPOUND_EXPR:
6422 /* When pedantic, a compound expression can be neither an lvalue
6423 nor an integer constant expression. */
6424 if (TREE_SIDE_EFFECTS (arg0) || pedantic)
6425 return t;
6426 /* Don't let (0, 0) be null pointer constant. */
6427 if (integer_zerop (arg1))
6052 return non_lvalue (arg1);
6428 return build1 (NOP_EXPR, TREE_TYPE (arg1), arg1);
6053 return arg1;
6054
6055 case COMPLEX_EXPR:
6056 if (wins)
6057 return build_complex (type, arg0, arg1);
6058 return t;
6059
6060 case REALPART_EXPR:

--- 177 unchanged lines hidden ---
6429 return arg1;
6430
6431 case COMPLEX_EXPR:
6432 if (wins)
6433 return build_complex (type, arg0, arg1);
6434 return t;
6435
6436 case REALPART_EXPR:

--- 177 unchanged lines hidden ---