OSDN Git Service

(operand_equal_p): Constants are not equal if there has been an overflow.
[pf3gnuchains/gcc-fork.git] / gcc / fold-const.c
index becfb4a..84e098a 100644 (file)
@@ -1,5 +1,5 @@
 /* Fold a constant sub-tree into a single node for C-compiler
-   Copyright (C) 1987, 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1987, 88, 92-96, 1997 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 /*@@ This file should be rewritten to use an arbitrary precision
   @@ representation for "struct tree_int_cst" and "struct tree_real_cst".
@@ -46,44 +47,51 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Handle floating overflow for `const_binop'.  */
 static jmp_buf float_error;
 
-static void encode     PROTO((HOST_WIDE_INT *, HOST_WIDE_INT, HOST_WIDE_INT));
-static void decode     PROTO((HOST_WIDE_INT *, HOST_WIDE_INT *, HOST_WIDE_INT *));
-static int div_and_round_double PROTO((enum tree_code, int, HOST_WIDE_INT,
+static void encode             PROTO((HOST_WIDE_INT *,
+                                      HOST_WIDE_INT, HOST_WIDE_INT));
+static void decode             PROTO((HOST_WIDE_INT *,
+                                      HOST_WIDE_INT *, HOST_WIDE_INT *));
+int div_and_round_double       PROTO((enum tree_code, int, HOST_WIDE_INT,
                                       HOST_WIDE_INT, HOST_WIDE_INT,
                                       HOST_WIDE_INT, HOST_WIDE_INT *,
                                       HOST_WIDE_INT *, HOST_WIDE_INT *,
                                       HOST_WIDE_INT *));
-static int split_tree  PROTO((tree, enum tree_code, tree *, tree *, int *));
-static tree const_binop PROTO((enum tree_code, tree, tree, int));
-static tree fold_convert PROTO((tree, tree));
+static int split_tree          PROTO((tree, enum tree_code, tree *,
+                                      tree *, int *));
+static tree const_binop                PROTO((enum tree_code, tree, tree, int));
+static tree fold_convert       PROTO((tree, tree));
 static enum tree_code invert_tree_comparison PROTO((enum tree_code));
 static enum tree_code swap_tree_comparison PROTO((enum tree_code));
-static int truth_value_p PROTO((enum tree_code));
+static int truth_value_p       PROTO((enum tree_code));
 static int operand_equal_for_comparison_p PROTO((tree, tree, tree));
-static int twoval_comparison_p PROTO((tree, tree *, tree *, int *));
-static tree eval_subst PROTO((tree, tree, tree, tree, tree));
-static tree omit_one_operand PROTO((tree, tree, tree));
+static int twoval_comparison_p PROTO((tree, tree *, tree *, int *));
+static tree eval_subst         PROTO((tree, tree, tree, tree, tree));
+static tree omit_one_operand   PROTO((tree, tree, tree));
+static tree pedantic_omit_one_operand PROTO((tree, tree, tree));
 static tree distribute_bit_expr PROTO((enum tree_code, tree, tree, tree));
-static tree make_bit_field_ref PROTO((tree, tree, int, int, int));
+static tree make_bit_field_ref PROTO((tree, tree, int, int, int));
 static tree optimize_bit_field_compare PROTO((enum tree_code, tree,
                                              tree, tree));
 static tree decode_field_reference PROTO((tree, int *, int *,
                                          enum machine_mode *, int *,
-                                         int *, tree *));
-static int all_ones_mask_p PROTO((tree, int));
-static int simple_operand_p PROTO((tree));
-static tree range_test PROTO((enum tree_code, tree, enum tree_code,
-                              enum tree_code, tree, tree, tree));
-static tree fold_truthop PROTO((enum tree_code, tree, tree, tree));
+                                         int *, tree *, tree *));
+static int all_ones_mask_p     PROTO((tree, int));
+static int simple_operand_p    PROTO((tree));
+static tree range_binop                PROTO((enum tree_code, tree, tree, int,
+                                      tree, int));
+static tree make_range         PROTO((tree, int *, tree *, tree *));
+static tree build_range_check  PROTO((tree, tree, int, tree, tree));
+static int merge_ranges                PROTO((int *, tree *, tree *, int, tree, tree,
+                                      int, tree, tree));
+static tree fold_range_test    PROTO((tree));
+static tree unextend           PROTO((tree, int, int, tree));
+static tree fold_truthop       PROTO((enum tree_code, tree, tree, tree));
 static tree strip_compound_expr PROTO((tree, tree));
 
 #ifndef BRANCH_COST
 #define BRANCH_COST 1
 #endif
 
-/* Yield nonzero if a signed left shift of A by B bits overflows.  */
-#define left_shift_overflows(a, b)  ((a)  !=  ((a) << (b)) >> (b))
-
 /* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
    Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
    Then this yields nonzero if overflow occurred during the addition.
@@ -185,7 +193,7 @@ force_fit_type (t, overflow)
 
   /* Unsigned types do not suffer sign extension or overflow.  */
   if (TREE_UNSIGNED (TREE_TYPE (t)))
-    return 0;
+    return overflow;
 
   /* If the value's sign bit is set, extend the sign.  */
   if (prec != 2 * HOST_BITS_PER_WIDE_INT
@@ -335,8 +343,10 @@ lshift_double (l1, h1, count, prec, lv, hv, arith)
       return;
     }
   
-  if (count >= prec)
-    count = (unsigned HOST_WIDE_INT) count & prec;
+#ifdef SHIFT_COUNT_TRUNCATED
+  if (SHIFT_COUNT_TRUNCATED)
+    count %= prec;
+#endif
 
   if (count >= HOST_BITS_PER_WIDE_INT)
     {
@@ -368,8 +378,10 @@ rshift_double (l1, h1, count, prec, lv, hv, arith)
              ? -((unsigned HOST_WIDE_INT) h1 >> (HOST_BITS_PER_WIDE_INT - 1))
              : 0);
 
-  if (count >= prec)
-    count = (unsigned HOST_WIDE_INT) count % prec;
+#ifdef SHIFT_COUNT_TRUNCATED
+  if (SHIFT_COUNT_TRUNCATED)
+    count %= prec;
+#endif
 
   if (count >= HOST_BITS_PER_WIDE_INT)
     {
@@ -397,34 +409,16 @@ lrotate_double (l1, h1, count, prec, lv, hv)
      int prec;
      HOST_WIDE_INT *lv, *hv;
 {
-  HOST_WIDE_INT arg1[4];
-  register int i;
-  register int carry;
+  HOST_WIDE_INT s1l, s1h, s2l, s2h;
 
+  count %= prec;
   if (count < 0)
-    {
-      rrotate_double (l1, h1, - count, prec, lv, hv);
-      return;
-    }
-
-  encode (arg1, l1, h1);
-
-  if (count > prec)
-    count = prec;
+    count += prec;
 
-  carry = arg1[4 - 1] >> 16 - 1;
-  while (count > 0)
-    {
-      for (i = 0; i < 4; i++)
-       {
-         carry += arg1[i] << 1;
-         arg1[i] = LOWPART (carry);
-         carry = HIGHPART (carry);
-       }
-      count--;
-    }
-
-  decode (arg1, lv, hv);
+  lshift_double (l1, h1, count, prec, &s1l, &s1h, 0);
+  rshift_double (l1, h1, prec - count, prec, &s2l, &s2h, 0);
+  *lv = s1l | s2l;
+  *hv = s1h | s2h;
 }
 
 /* Rotate the doubleword integer in L1, H1 left by COUNT places
@@ -437,28 +431,16 @@ rrotate_double (l1, h1, count, prec, lv, hv)
      int prec;
      HOST_WIDE_INT *lv, *hv;
 {
-  HOST_WIDE_INT arg1[4];
-  register int i;
-  register int carry;
+  HOST_WIDE_INT s1l, s1h, s2l, s2h;
 
-  encode (arg1, l1, h1);
-
-  if (count > prec)
-    count = prec;
-
-  carry = arg1[0] & 1;
-  while (count > 0)
-    {
-      for (i = 4 - 1; i >= 0; i--)
-       {
-         carry *= BASE;
-         carry += arg1[i];
-         arg1[i] = LOWPART (carry >> 1);
-       }
-      count--;
-    }
+  count %= prec;
+  if (count < 0)
+    count += prec;
 
-  decode (arg1, lv, hv);
+  rshift_double (l1, h1, count, prec, &s1l, &s1h, 0);
+  lshift_double (l1, h1, prec - count, prec, &s2l, &s2h, 0);
+  *lv = s1l | s2l;
+  *hv = s1h | s2h;
 }
 \f
 /* Divide doubleword integer LNUM, HNUM by doubleword integer LDEN, HDEN
@@ -470,7 +452,7 @@ rrotate_double (l1, h1, count, prec, lv, hv)
    Return nonzero if the operation overflows.
    UNS nonzero says do unsigned division.  */
 
-static int
+int
 div_and_round_double (code, uns,
                      lnum_orig, hnum_orig, lden_orig, hden_orig,
                      lquo, hquo, lrem, hrem)
@@ -485,7 +467,7 @@ div_and_round_double (code, uns,
   HOST_WIDE_INT den[4], quo[4];
   register int i, j;
   unsigned HOST_WIDE_INT work;
-  register int carry = 0;
+  register unsigned HOST_WIDE_INT carry = 0;
   HOST_WIDE_INT lnum = lnum_orig;
   HOST_WIDE_INT hnum = hnum_orig;
   HOST_WIDE_INT lden = lden_orig;
@@ -552,7 +534,8 @@ div_and_round_double (code, uns,
     {
       /* Full double precision division,
         with thanks to Don Knuth's "Seminumerical Algorithms".  */
-    int quo_est, scale, num_hi_sig, den_hi_sig;
+    int num_hi_sig, den_hi_sig;
+    unsigned HOST_WIDE_INT quo_est, scale;
 
     /* Find the highest non-zero divisor digit.  */
     for (i = 4 - 1; ; i--)
@@ -884,6 +867,94 @@ target_negative (x)
   return x < 0;
 }
 #endif /* Target not IEEE */
+
+/* Try to change R into its exact multiplicative inverse in machine mode
+   MODE.  Return nonzero function value if successful.  */
+
+int
+exact_real_inverse (mode, r)
+     enum machine_mode mode;
+     REAL_VALUE_TYPE *r;
+{
+  union
+    {
+      double d;
+      unsigned short i[4];
+    }x, t, y;
+  int i;
+
+  /* Usually disable if bounds checks are not reliable.  */
+  if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT) && !flag_pretend_float)
+    return 0;
+
+  /* Set array index to the less significant bits in the unions, depending
+     on the endian-ness of the host doubles.
+     Disable if insufficient information on the data structure.  */
+#if HOST_FLOAT_FORMAT == UNKNOWN_FLOAT_FORMAT
+  return 0;
+#else
+#if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
+#define K 2
+#else
+#if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
+#define K 2
+#else
+#define K (2 * HOST_FLOAT_WORDS_BIG_ENDIAN)
+#endif
+#endif
+#endif
+
+  if (setjmp (float_error))
+    {
+      /* Don't do the optimization if there was an arithmetic error.  */
+fail:
+      set_float_handler (NULL_PTR);
+      return 0;
+    }
+  set_float_handler (float_error);
+
+  /* Domain check the argument.  */
+  x.d = *r;
+  if (x.d == 0.0)
+    goto fail;
+
+#ifdef REAL_INFINITY
+  if (REAL_VALUE_ISINF (x.d) || REAL_VALUE_ISNAN (x.d))
+    goto fail;
+#endif
+
+  /* Compute the reciprocal and check for numerical exactness.
+     It is unnecessary to check all the significand bits to determine
+     whether X is a power of 2.  If X is not, then it is impossible for
+     the bottom half significand of both X and 1/X to be all zero bits.
+     Hence we ignore the data structure of the top half and examine only
+     the low order bits of the two significands.  */
+  t.d = 1.0 / x.d;
+  if (x.i[K] != 0 || x.i[K + 1] != 0 || t.i[K] != 0 || t.i[K + 1] != 0)
+    goto fail;
+
+  /* Truncate to the required mode and range-check the result.  */
+  y.d = REAL_VALUE_TRUNCATE (mode, t.d);
+#ifdef CHECK_FLOAT_VALUE
+  i = 0;
+  if (CHECK_FLOAT_VALUE (mode, y.d, i))
+    goto fail;
+#endif
+
+  /* Fail if truncation changed the value.  */
+  if (y.d != t.d || y.d == 0.0)
+    goto fail;
+
+#ifdef REAL_INFINITY
+  if (REAL_VALUE_ISINF (y.d) || REAL_VALUE_ISNAN (y.d))
+    goto fail;
+#endif
+
+  /* Output the reciprocal and return success flag.  */
+  set_float_handler (NULL_PTR);
+  *r = y.d;
+  return 1;
+}
 #endif /* no REAL_ARITHMETIC */
 \f
 /* Split a tree IN into a constant and a variable part
@@ -975,7 +1046,7 @@ split_tree (in, code, varp, conp, varsignp)
   return 0;
 }
 \f
-/* Combine two constants NUM and ARG2 under operation CODE
+/* Combine two constants ARG1 and ARG2 under operation CODE
    to produce a new constant.
    We assume ARG1 and ARG2 have the same data type,
    or at least are the same kind of constant and the same machine mode.
@@ -988,6 +1059,8 @@ const_binop (code, arg1, arg2, notrunc)
      register tree arg1, arg2;
      int notrunc;
 {
+  STRIP_NOPS (arg1); STRIP_NOPS (arg2);
+
   if (TREE_CODE (arg1) == INTEGER_CST)
     {
       register HOST_WIDE_INT int1l = TREE_INT_CST_LOW (arg1);
@@ -999,23 +1072,24 @@ const_binop (code, arg1, arg2, notrunc)
       register tree t;
       int uns = TREE_UNSIGNED (TREE_TYPE (arg1));
       int overflow = 0;
+      int no_overflow = 0;
 
       switch (code)
        {
        case BIT_IOR_EXPR:
-         t = build_int_2 (int1l | int2l, int1h | int2h);
+         low = int1l | int2l, hi = int1h | int2h;
          break;
 
        case BIT_XOR_EXPR:
-         t = build_int_2 (int1l ^ int2l, int1h ^ int2h);
+         low = int1l ^ int2l, hi = int1h ^ int2h;
          break;
 
        case BIT_AND_EXPR:
-         t = build_int_2 (int1l & int2l, int1h & int2h);
+         low = int1l & int2l, hi = int1h & int2h;
          break;
 
        case BIT_ANDTC_EXPR:
-         t = build_int_2 (int1l & ~int2l, int1h & ~int2h);
+         low = int1l & ~int2l, hi = int1h & ~int2h;
          break;
 
        case RSHIFT_EXPR:
@@ -1028,14 +1102,8 @@ const_binop (code, arg1, arg2, notrunc)
                         TYPE_PRECISION (TREE_TYPE (arg1)),
                         &low, &hi,
                         !uns);
-         t = build_int_2 (low, hi);
-         TREE_TYPE (t) = TREE_TYPE (arg1);
-         if (!notrunc)
-           force_fit_type (t, 0);
-         TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2);
-         TREE_CONSTANT_OVERFLOW (t)
-           = TREE_CONSTANT_OVERFLOW (arg1) | TREE_CONSTANT_OVERFLOW (arg2);
-         return t;
+         no_overflow = 1;
+         break;
 
        case RROTATE_EXPR:
          int2l = - int2l;
@@ -1043,92 +1111,76 @@ const_binop (code, arg1, arg2, notrunc)
          lrotate_double (int1l, int1h, int2l,
                          TYPE_PRECISION (TREE_TYPE (arg1)),
                          &low, &hi);
-         t = build_int_2 (low, hi);
          break;
 
        case PLUS_EXPR:
-         if (int1h == 0)
-           {
-             int2l += int1l;
-             if ((unsigned HOST_WIDE_INT) int2l < int1l)
-               {
-                 hi = int2h++;
-                 overflow = int2h < hi;
-               }
-             t = build_int_2 (int2l, int2h);
-             break;
-           }
-         if (int2h == 0)
-           {
-             int1l += int2l;
-             if ((unsigned HOST_WIDE_INT) int1l < int2l)
-               {
-                 hi = int1h++;
-                 overflow = int1h < hi;
-               }
-             t = build_int_2 (int1l, int1h);
-             break;
-           }
          overflow = add_double (int1l, int1h, int2l, int2h, &low, &hi);
-         t = build_int_2 (low, hi);
          break;
 
        case MINUS_EXPR:
-         if (int2h == 0 && int2l == 0)
-           {
-             t = build_int_2 (int1l, int1h);
-             break;
-           }
          neg_double (int2l, int2h, &low, &hi);
          add_double (int1l, int1h, low, hi, &low, &hi);
          overflow = overflow_sum_sign (hi, int2h, int1h);
-         t = build_int_2 (low, hi);
          break;
 
        case MULT_EXPR:
          overflow = mul_double (int1l, int1h, int2l, int2h, &low, &hi);
-         t = build_int_2 (low, hi);
          break;
 
        case TRUNC_DIV_EXPR:
        case FLOOR_DIV_EXPR: case CEIL_DIV_EXPR:
        case EXACT_DIV_EXPR:
-         /* This is a shortcut for a common special case.
-            It reduces the number of tree nodes generated
-            and saves time.  */
+         /* This is a shortcut for a common special case.  */
          if (int2h == 0 && int2l > 0
-             && TREE_TYPE (arg1) == sizetype
+             && ! TREE_CONSTANT_OVERFLOW (arg1)
+             && ! TREE_CONSTANT_OVERFLOW (arg2)
              && int1h == 0 && int1l >= 0)
            {
              if (code == CEIL_DIV_EXPR)
-               int1l += int2l-1;
-             return size_int (int1l / int2l);
+               int1l += int2l - 1;
+             low = int1l / int2l, hi = 0;
+             break;
            }
+
+         /* ... fall through ... */
+
        case ROUND_DIV_EXPR: 
          if (int2h == 0 && int2l == 1)
            {
-             t = build_int_2 (int1l, int1h);
+             low = int1l, hi = int1h;
              break;
            }
-         if (int1l == int2l && int1h == int2h)
+         if (int1l == int2l && int1h == int2h
+             && ! (int1l == 0 && int1h == 0))
            {
-             if ((int1l | int1h) == 0)
-               abort ();
-             t = build_int_2 (1, 0);
+             low = 1, hi = 0;
              break;
            }
          overflow = div_and_round_double (code, uns,
                                           int1l, int1h, int2l, int2h,
                                           &low, &hi, &garbagel, &garbageh);
-         t = build_int_2 (low, hi);
          break;
 
-       case TRUNC_MOD_EXPR: case ROUND_MOD_EXPR: 
+       case TRUNC_MOD_EXPR:
        case FLOOR_MOD_EXPR: case CEIL_MOD_EXPR:
+         /* This is a shortcut for a common special case.  */
+         if (int2h == 0 && int2l > 0
+             && ! TREE_CONSTANT_OVERFLOW (arg1)
+             && ! TREE_CONSTANT_OVERFLOW (arg2)
+             && int1h == 0 && int1l >= 0)
+           {
+             if (code == CEIL_MOD_EXPR)
+               int1l += int2l - 1;
+             low = int1l % int2l, hi = 0;
+             break;
+           }
+
+         /* ... fall through ... */
+
+       case ROUND_MOD_EXPR: 
          overflow = div_and_round_double (code, uns,
                                           int1l, int1h, int2l, int2h,
                                           &garbagel, &garbageh, &low, &hi);
-         t = build_int_2 (low, hi);
          break;
 
        case MIN_EXPR:
@@ -1150,18 +1202,29 @@ const_binop (code, arg1, arg2, notrunc)
                             < (unsigned HOST_WIDE_INT) int2l)));
            }
          if (low == (code == MIN_EXPR))
-           t = build_int_2 (int1l, int1h);
+           low = int1l, hi = int1h;
          else
-           t = build_int_2 (int2l, int2h);
+           low = int2l, hi = int2h;
          break;
 
        default:
          abort ();
        }
     got_it:
-      TREE_TYPE (t) = TREE_TYPE (arg1);
+      if (TREE_TYPE (arg1) == sizetype && hi == 0
+         && low >= 0 && low <= TREE_INT_CST_LOW (TYPE_MAX_VALUE (sizetype))
+         && ! overflow
+         && ! TREE_OVERFLOW (arg1) && ! TREE_OVERFLOW (arg2))
+       t = size_int (low);
+      else
+       {
+         t = build_int_2 (low, hi);
+         TREE_TYPE (t) = TREE_TYPE (arg1);
+       }
+
       TREE_OVERFLOW (t)
-       = ((notrunc ? !uns && overflow : force_fit_type (t, overflow))
+       = ((notrunc ? !uns && overflow
+           : force_fit_type (t, overflow && !uns) && ! no_overflow)
           | TREE_OVERFLOW (arg1)
           | TREE_OVERFLOW (arg2));
       TREE_CONSTANT_OVERFLOW (t) = (TREE_OVERFLOW (t)
@@ -1251,6 +1314,7 @@ const_binop (code, arg1, arg2, notrunc)
 #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
   if (TREE_CODE (arg1) == COMPLEX_CST)
     {
+      register tree type = TREE_TYPE (arg1);
       register tree r1 = TREE_REALPART (arg1);
       register tree i1 = TREE_IMAGPART (arg1);
       register tree r2 = TREE_REALPART (arg2);
@@ -1260,17 +1324,20 @@ const_binop (code, arg1, arg2, notrunc)
       switch (code)
        {
        case PLUS_EXPR:
-         t = build_complex (const_binop (PLUS_EXPR, r1, r2, notrunc),
+         t = build_complex (type,
+                            const_binop (PLUS_EXPR, r1, r2, notrunc),
                             const_binop (PLUS_EXPR, i1, i2, notrunc));
          break;
 
        case MINUS_EXPR:
-         t = build_complex (const_binop (MINUS_EXPR, r1, r2, notrunc),
+         t = build_complex (type,
+                            const_binop (MINUS_EXPR, r1, r2, notrunc),
                             const_binop (MINUS_EXPR, i1, i2, notrunc));
          break;
 
        case MULT_EXPR:
-         t = build_complex (const_binop (MINUS_EXPR,
+         t = build_complex (type,
+                            const_binop (MINUS_EXPR,
                                          const_binop (MULT_EXPR,
                                                       r1, r2, notrunc),
                                          const_binop (MULT_EXPR,
@@ -1292,32 +1359,33 @@ const_binop (code, arg1, arg2, notrunc)
                             const_binop (MULT_EXPR, i2, i2, notrunc),
                             notrunc);
 
-           t = build_complex
-             (const_binop (INTEGRAL_TYPE_P (TREE_TYPE (r1))
-                           ? TRUNC_DIV_EXPR : RDIV_EXPR,
-                           const_binop (PLUS_EXPR,
-                                        const_binop (MULT_EXPR, r1, r2,
-                                                     notrunc),
-                                        const_binop (MULT_EXPR, i1, i2,
-                                                     notrunc),
-                                        notrunc),
-                           magsquared, notrunc),
-              const_binop (INTEGRAL_TYPE_P (TREE_TYPE (r1))
-                           ? TRUNC_DIV_EXPR : RDIV_EXPR,
-                           const_binop (MINUS_EXPR,
-                                        const_binop (MULT_EXPR, i1, r2,
-                                                     notrunc),
-                                        const_binop (MULT_EXPR, r1, i2,
-                                                     notrunc),
-                                        notrunc),
-                           magsquared, notrunc));
+           t = build_complex (type,
+                              const_binop
+                              (INTEGRAL_TYPE_P (TREE_TYPE (r1))
+                               ? TRUNC_DIV_EXPR : RDIV_EXPR,
+                               const_binop (PLUS_EXPR,
+                                            const_binop (MULT_EXPR, r1, r2,
+                                                         notrunc),
+                                            const_binop (MULT_EXPR, i1, i2,
+                                                         notrunc),
+                                            notrunc),
+                               magsquared, notrunc),
+                              const_binop
+                              (INTEGRAL_TYPE_P (TREE_TYPE (r1))
+                               ? TRUNC_DIV_EXPR : RDIV_EXPR,
+                               const_binop (MINUS_EXPR,
+                                            const_binop (MULT_EXPR, i1, r2,
+                                                         notrunc),
+                                            const_binop (MULT_EXPR, r1, i2,
+                                                         notrunc),
+                                            notrunc),
+                               magsquared, notrunc));
          }
          break;
 
        default:
          abort ();
        }
-      TREE_TYPE (t) = TREE_TYPE (arg1);
       return t;
     }
   return 0;
@@ -1327,7 +1395,7 @@ const_binop (code, arg1, arg2, notrunc)
 
 tree
 size_int (number)
-     unsigned int number;
+     unsigned HOST_WIDE_INT number;
 {
   register tree t;
   /* Type-size nodes already made for small sizes.  */
@@ -1350,6 +1418,7 @@ size_int (number)
     {
       t = build_int_2 (number, 0);
       TREE_TYPE (t) = sizetype;
+      TREE_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (t) = force_fit_type (t, 0);
     }
   return t;
 }
@@ -1367,20 +1436,16 @@ size_binop (code, arg0, arg1)
   if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
     {
       /* And some specific cases even faster than that.  */
-      if (code == PLUS_EXPR
-         && TREE_INT_CST_LOW (arg0) == 0
-         && TREE_INT_CST_HIGH (arg0) == 0)
+      if (code == PLUS_EXPR && integer_zerop (arg0))
        return arg1;
-      if (code == MINUS_EXPR
-         && TREE_INT_CST_LOW (arg1) == 0
-         && TREE_INT_CST_HIGH (arg1) == 0)
+      else if ((code == MINUS_EXPR || code == PLUS_EXPR)
+              && integer_zerop (arg1))
        return arg0;
-      if (code == MULT_EXPR
-         && TREE_INT_CST_LOW (arg0) == 1
-         && TREE_INT_CST_HIGH (arg0) == 0)
+      else if (code == MULT_EXPR && integer_onep (arg0))
        return arg1;
+
       /* Handle general case of two integer constants.  */
-      return const_binop (code, arg0, arg1, 1);
+      return const_binop (code, arg0, arg1, 0);
     }
 
   if (arg0 == error_mark_node || arg1 == error_mark_node)
@@ -1404,6 +1469,11 @@ fold_convert (t, arg1)
     {
       if (TREE_CODE (arg1) == INTEGER_CST)
        {
+         /* If we would build a constant wider than GCC supports,
+            leave the conversion unfolded.  */
+         if (TYPE_PRECISION (type) > 2 * HOST_BITS_PER_WIDE_INT)
+           return t;
+
          /* Given an integer constant, make new constant with new type,
             appropriately sign-extended or truncated.  */
          t = build_int_2 (TREE_INT_CST_LOW (arg1),
@@ -1430,10 +1500,11 @@ fold_convert (t, arg1)
          REAL_VALUE_TYPE x;
          REAL_VALUE_TYPE l;
          REAL_VALUE_TYPE u;
+         tree type1 = TREE_TYPE (arg1);
 
          x = TREE_REAL_CST (arg1);
-         l = real_value_from_int_cst (TYPE_MIN_VALUE (type));
-         u = real_value_from_int_cst (TYPE_MAX_VALUE (type));
+         l = real_value_from_int_cst (type1, TYPE_MIN_VALUE (type));
+         u = real_value_from_int_cst (type1, TYPE_MAX_VALUE (type));
          /* See if X will be in range after truncation towards 0.
             To compensate for truncation, move the bounds away from 0,
             but reject if X exactly equals the adjusted bounds.  */
@@ -1498,7 +1569,11 @@ fold_convert (t, arg1)
       if (TREE_CODE (arg1) == REAL_CST)
        {
          if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)))
-           return arg1;
+           {
+             t = arg1;
+             TREE_TYPE (arg1) = type;
+             return t;
+           }
          else if (setjmp (float_error))
            {
              overflow = 1;
@@ -1556,6 +1631,11 @@ non_lvalue (x)
   return result;
 }
 
+/* Nonzero means lvalues are limited to those valid in pedantic ANSI C.
+   Zero means allow extended lvalues.  */
+
+int pedantic_lvalues;
+
 /* When pedantic, return an expr equal to X but certainly not valid as a
    pedantic lvalue.  Otherwise, return X.  */
 
@@ -1563,7 +1643,7 @@ tree
 pedantic_non_lvalue (x)
      tree x;
 {
-  if (pedantic)
+  if (pedantic_lvalues)
     return non_lvalue (x);
   else
     return x;
@@ -1655,46 +1735,61 @@ operand_equal_p (arg0, arg1, only_const)
   STRIP_NOPS (arg0);
   STRIP_NOPS (arg1);
 
-  /* If ARG0 and ARG1 are the same SAVE_EXPR, they are necessarily equal.
-     We don't care about side effects in that case because the SAVE_EXPR
-     takes care of that for us.  */
-  if (TREE_CODE (arg0) == SAVE_EXPR && arg0 == arg1)
-    return ! only_const;
-
-  if (TREE_SIDE_EFFECTS (arg0) || TREE_SIDE_EFFECTS (arg1))
+  if (TREE_CODE (arg0) != TREE_CODE (arg1)
+      /* This is needed for conversions and for COMPONENT_REF.
+        Might as well play it safe and always test this.  */
+      || TYPE_MODE (TREE_TYPE (arg0)) != TYPE_MODE (TREE_TYPE (arg1)))
     return 0;
 
-  if (TREE_CODE (arg0) == TREE_CODE (arg1)
-      && TREE_CODE (arg0) == ADDR_EXPR
-      && TREE_OPERAND (arg0, 0) == TREE_OPERAND (arg1, 0))
-    return 1;
-
-  if (TREE_CODE (arg0) == TREE_CODE (arg1)
-      && TREE_CODE (arg0) == INTEGER_CST
-      && TREE_INT_CST_LOW (arg0) == TREE_INT_CST_LOW (arg1)
-      && TREE_INT_CST_HIGH (arg0) == TREE_INT_CST_HIGH (arg1))
+  /* If ARG0 and ARG1 are the same SAVE_EXPR, they are necessarily equal.
+     We don't care about side effects in that case because the SAVE_EXPR
+     takes care of that for us. In all other cases, two expressions are
+     equal if they have no side effects.  If we have two identical
+     expressions with side effects that should be treated the same due
+     to the only side effects being identical SAVE_EXPR's, that will
+     be detected in the recursive calls below.  */
+  if (arg0 == arg1 && ! only_const
+      && (TREE_CODE (arg0) == SAVE_EXPR
+         || (! TREE_SIDE_EFFECTS (arg0) && ! TREE_SIDE_EFFECTS (arg1))))
     return 1;
 
-  /* Detect when real constants are equal.  */
-  if (TREE_CODE (arg0) == TREE_CODE (arg1)
-      && TREE_CODE (arg0) == REAL_CST)
-    return !bcmp ((char *) &TREE_REAL_CST (arg0),
-                 (char *) &TREE_REAL_CST (arg1),
-                 sizeof (REAL_VALUE_TYPE));
+  /* Next handle constant cases, those for which we can return 1 even
+     if ONLY_CONST is set.  */
+  if (TREE_CONSTANT (arg0) && TREE_CONSTANT (arg1))
+    switch (TREE_CODE (arg0))
+      {
+      case INTEGER_CST:
+       return (! TREE_CONSTANT_OVERFLOW (arg0)
+               && ! TREE_CONSTANT_OVERFLOW (arg1)
+               && TREE_INT_CST_LOW (arg0) == TREE_INT_CST_LOW (arg1)
+               && TREE_INT_CST_HIGH (arg0) == TREE_INT_CST_HIGH (arg1));
+
+      case REAL_CST:
+       return (! TREE_CONSTANT_OVERFLOW (arg0)
+               && ! TREE_CONSTANT_OVERFLOW (arg1)
+               && REAL_VALUES_EQUAL (TREE_REAL_CST (arg0),
+                                     TREE_REAL_CST (arg1)));
+
+      case COMPLEX_CST:
+       return (operand_equal_p (TREE_REALPART (arg0), TREE_REALPART (arg1),
+                                only_const)
+               && operand_equal_p (TREE_IMAGPART (arg0), TREE_IMAGPART (arg1),
+                                   only_const));
+
+      case STRING_CST:
+       return (TREE_STRING_LENGTH (arg0) == TREE_STRING_LENGTH (arg1)
+               && ! strncmp (TREE_STRING_POINTER (arg0),
+                             TREE_STRING_POINTER (arg1),
+                             TREE_STRING_LENGTH (arg0)));
+
+      case ADDR_EXPR:
+       return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0),
+                               0);
+      }
 
   if (only_const)
     return 0;
 
-  if (arg0 == arg1)
-    return 1;
-
-  if (TREE_CODE (arg0) != TREE_CODE (arg1))
-    return 0;
-  /* This is needed for conversions and for COMPONENT_REF.
-     Might as well play it safe and always test this.  */
-  if (TYPE_MODE (TREE_TYPE (arg0)) != TYPE_MODE (TREE_TYPE (arg1)))
-    return 0;
-
   switch (TREE_CODE_CLASS (TREE_CODE (arg0)))
     {
     case '1':
@@ -1709,10 +1804,22 @@ operand_equal_p (arg0, arg1, only_const)
 
     case '<':
     case '2':
-      return (operand_equal_p (TREE_OPERAND (arg0, 0),
-                              TREE_OPERAND (arg1, 0), 0)
+      if (operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0), 0)
+         && operand_equal_p (TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 1),
+                             0))
+       return 1;
+
+      /* For commutative ops, allow the other order.  */
+      return ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MULT_EXPR
+              || TREE_CODE (arg0) == MIN_EXPR || TREE_CODE (arg0) == MAX_EXPR
+              || TREE_CODE (arg0) == BIT_IOR_EXPR
+              || TREE_CODE (arg0) == BIT_XOR_EXPR
+              || TREE_CODE (arg0) == BIT_AND_EXPR
+              || TREE_CODE (arg0) == NE_EXPR || TREE_CODE (arg0) == EQ_EXPR)
+             && operand_equal_p (TREE_OPERAND (arg0, 0),
+                                 TREE_OPERAND (arg1, 1), 0)
              && operand_equal_p (TREE_OPERAND (arg0, 1),
-                                 TREE_OPERAND (arg1, 1), 0));
+                                 TREE_OPERAND (arg1, 0), 0));
 
     case 'r':
       switch (TREE_CODE (arg0))
@@ -1759,7 +1866,8 @@ operand_equal_for_comparison_p (arg0, arg1, other)
   if (operand_equal_p (arg0, arg1, 0))
     return 1;
 
-  if (! INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
+  if (! INTEGRAL_TYPE_P (TREE_TYPE (arg0))
+      || ! INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
     return 0;
 
   /* Duplicate what shorten_compare does to ARG1 and see if that gives the
@@ -1992,6 +2100,22 @@ omit_one_operand (type, result, omitted)
 
   return non_lvalue (t);
 }
+
+/* Similar, but call pedantic_non_lvalue instead of non_lvalue.  */
+
+static tree
+pedantic_omit_one_operand (type, result, omitted)
+     tree type, result, omitted;
+{
+  tree t = convert (type, result);
+
+  if (TREE_SIDE_EFFECTS (omitted))
+    return build (COMPOUND_EXPR, type, omitted, t);
+
+  return pedantic_non_lvalue (t);
+}
+
+
 \f
 /* Return a simplified tree node for the truth-negation of ARG.  This
    never alters ARG itself.  We assume that ARG is an operation that
@@ -2089,6 +2213,10 @@ invert_truthvalue (arg)
 
     case SAVE_EXPR:
       return build1 (TRUTH_NOT_EXPR, type, arg);
+
+    case CLEANUP_POINT_EXPR:
+      return build1 (CLEANUP_POINT_EXPR, type,
+                    invert_truthvalue (TREE_OPERAND (arg, 0)));
     }
   if (TREE_CODE (TREE_TYPE (arg)) != BOOLEAN_TYPE)
     abort ();
@@ -2202,6 +2330,7 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
   enum machine_mode lmode, rmode, lnmode, rnmode;
   int lunsignedp, runsignedp;
   int lvolatilep = 0, rvolatilep = 0;
+  int alignment;
   tree linner, rinner;
   tree mask;
   tree offset;
@@ -2210,7 +2339,7 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
      if the same as the size of the underlying object, we aren't doing an
      extraction at all and so can do nothing.  */
   linner = get_inner_reference (lhs, &lbitsize, &lbitpos, &offset, &lmode,
-                               &lunsignedp, &lvolatilep);
+                               &lunsignedp, &lvolatilep, &alignment);
   if (linner == lhs || lbitsize == GET_MODE_BITSIZE (lmode) || lbitsize < 0
       || offset != 0)
     return 0;
@@ -2219,8 +2348,8 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
    {
      /* If this is not a constant, we can only do something if bit positions,
        sizes, and signedness are the same.   */
-     rinner = get_inner_reference (rhs, &rbitsize, &rbitpos, &offset,
-                                  &rmode, &runsignedp, &rvolatilep);
+     rinner = get_inner_reference (rhs, &rbitsize, &rbitpos, &offset, &rmode,
+                                  &runsignedp, &rvolatilep, &alignment);
 
      if (rinner == rhs || lbitpos != rbitpos || lbitsize != rbitsize
         || lunsignedp != runsignedp || offset != 0)
@@ -2267,9 +2396,8 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
        return 0;
     }
 
-#if BYTES_BIG_ENDIAN
-  lbitpos = lnbitsize - lbitsize - lbitpos;
-#endif
+  if (BYTES_BIG_ENDIAN)
+    lbitpos = lnbitsize - lbitsize - lbitpos;
 
   /* Make the mask to be used against the extracted field.  */
   mask = build_int_2 (~0, ~0);
@@ -2375,21 +2503,26 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
    *PMASK is set to the mask used.  This is either contained in a
    BIT_AND_EXPR or derived from the width of the field.
 
+   *PAND_MASK is set the the mask found in a BIT_AND_EXPR, if any.
+
    Return 0 if this is not a component reference or is one that we can't
    do anything with.  */
 
 static tree
 decode_field_reference (exp, pbitsize, pbitpos, pmode, punsignedp,
-                       pvolatilep, pmask)
+                       pvolatilep, pmask, pand_mask)
      tree exp;
      int *pbitsize, *pbitpos;
      enum machine_mode *pmode;
      int *punsignedp, *pvolatilep;
      tree *pmask;
+     tree *pand_mask;
 {
-  tree mask = 0;
-  tree inner;
-  tree offset;
+  tree and_mask = 0;
+  tree mask, inner, offset;
+  tree unsigned_type;
+  int precision;
+  int alignment;
 
   /* All the optimizations using this function assume integer fields.  
      There are problems with FP fields since the type_for_size call
@@ -2401,35 +2534,37 @@ decode_field_reference (exp, pbitsize, pbitpos, pmode, punsignedp,
 
   if (TREE_CODE (exp) == BIT_AND_EXPR)
     {
-      mask = TREE_OPERAND (exp, 1);
+      and_mask = TREE_OPERAND (exp, 1);
       exp = TREE_OPERAND (exp, 0);
-      STRIP_NOPS (exp); STRIP_NOPS (mask);
-      if (TREE_CODE (mask) != INTEGER_CST)
+      STRIP_NOPS (exp); STRIP_NOPS (and_mask);
+      if (TREE_CODE (and_mask) != INTEGER_CST)
        return 0;
     }
 
-  if (TREE_CODE (exp) != COMPONENT_REF && TREE_CODE (exp) != ARRAY_REF
-      && TREE_CODE (exp) != BIT_FIELD_REF)
-    return 0;
 
   inner = get_inner_reference (exp, pbitsize, pbitpos, &offset, pmode,
-                              punsignedp, pvolatilep);
-  if (inner == exp || *pbitsize < 0 || offset != 0)
+                              punsignedp, pvolatilep, &alignment);
+  if ((inner == exp && and_mask == 0)
+      || *pbitsize < 0 || offset != 0)
     return 0;
   
-  if (mask == 0)
-    {
-      tree unsigned_type = type_for_size (*pbitsize, 1);
-      int precision = TYPE_PRECISION (unsigned_type);
-
-      mask = build_int_2 (~0, ~0);
-      TREE_TYPE (mask) = unsigned_type;
-      force_fit_type (mask, 0);
-      mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
-      mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
-    }
+  /* Compute the mask to access the bitfield.  */
+  unsigned_type = type_for_size (*pbitsize, 1);
+  precision = TYPE_PRECISION (unsigned_type);
+
+  mask = build_int_2 (~0, ~0);
+  TREE_TYPE (mask) = unsigned_type;
+  force_fit_type (mask, 0);
+  mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
+  mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
+
+  /* Merge it with the mask we found in the BIT_AND_EXPR, if any.  */
+  if (and_mask != 0)
+    mask = fold (build (BIT_AND_EXPR, unsigned_type,
+                       convert (unsigned_type, and_mask), mask));
 
   *pmask = mask;
+  *pand_mask = and_mask;
   return inner;
 }
 
@@ -2449,12 +2584,12 @@ all_ones_mask_p (mask, size)
   TREE_TYPE (tmask) = signed_type (type);
   force_fit_type (tmask, 0);
   return
-    operand_equal_p (mask, 
-                    const_binop (RSHIFT_EXPR,
-                                 const_binop (LSHIFT_EXPR, tmask,
-                                              size_int (precision - size), 0),
-                                 size_int (precision - size), 0),
-                    0);
+    tree_int_cst_equal (mask, 
+                       const_binop (RSHIFT_EXPR,
+                                    const_binop (LSHIFT_EXPR, tmask,
+                                                 size_int (precision - size),
+                                                 0),
+                                    size_int (precision - size), 0));
 }
 
 /* Subroutine for fold_truthop: determine if an operand is simple enough
@@ -2486,128 +2621,555 @@ simple_operand_p (exp)
              && (! TREE_STATIC (exp) || DECL_REGISTER (exp))));
 }
 \f
-/* Subroutine for fold_truthop: try to optimize a range test.
+/* The following functions are subroutines to fold_range_test and allow it to
+   try to change a logical combination of comparisons into a range test.
+
+   For example, both
+       X == 2 && X == 3 && X == 4 && X == 5
+   and
+       X >= 2 && X <= 5
+   are converted to
+       (unsigned) (X - 2) <= 3
+
+   We decribe each set of comparisons as being either inside or outside
+   a range, using a variable named like IN_P, and then describe the
+   range with a lower and upper bound.  If one of the bounds is omitted,
+   it represents either the highest or lowest value of the type.
+
+   In the comments below, we represent a range by two numbers in brackets
+   preceeded by a "+" to designate being inside that range, or a "-" to
+   designate being outside that range, so the condition can be inverted by
+   flipping the prefix.  An omitted bound is represented by a "-".  For
+   example, "- [-, 10]" means being outside the range starting at the lowest
+   possible value and ending at 10, in other words, being greater than 10.
+   The range "+ [-, -]" is always true and hence the range "- [-, -]" is
+   always false.
+
+   We set up things so that the missing bounds are handled in a consistent
+   manner so neither a missing bound nor "true" and "false" need to be
+   handled using a special case.  */
+
+/* Return the result of applying CODE to ARG0 and ARG1, but handle the case
+   of ARG0 and/or ARG1 being omitted, meaning an unlimited range. UPPER0_P
+   and UPPER1_P are nonzero if the respective argument is an upper bound
+   and zero for a lower.  TYPE, if nonzero, is the type of the result; it
+   must be specified for a comparison.  ARG1 will be converted to ARG0's
+   type if both are specified.  */
 
-   For example, "i >= 2 && i =< 9" can be done as "(unsigned) (i - 2) <= 7".
+static tree
+range_binop (code, type, arg0, upper0_p, arg1, upper1_p)
+     enum tree_code code;
+     tree type;
+     tree arg0, arg1;
+     int upper0_p, upper1_p;
+{
+  tree tem;
+  int result;
+  int sgn0, sgn1;
 
-   JCODE is the logical combination of the two terms.  It is TRUTH_AND_EXPR
-   (representing TRUTH_ANDIF_EXPR and TRUTH_AND_EXPR) or TRUTH_OR_EXPR
-   (representing TRUTH_ORIF_EXPR and TRUTH_OR_EXPR).  TYPE is the type of
-   the result.
+  /* If neither arg represents infinity, do the normal operation.
+     Else, if not a comparison, return infinity.  Else handle the special
+     comparison rules. Note that most of the cases below won't occur, but
+     are handled for consistency.  */
 
-   VAR is the value being tested.  LO_CODE and HI_CODE are the comparison
-   operators comparing VAR to LO_CST and HI_CST.  LO_CST is known to be no
-   larger than HI_CST (they may be equal).
+  if (arg0 != 0 && arg1 != 0)
+    {
+      tem = fold (build (code, type != 0 ? type : TREE_TYPE (arg0),
+                        arg0, convert (TREE_TYPE (arg0), arg1)));
+      STRIP_NOPS (tem);
+      return TREE_CODE (tem) == INTEGER_CST ? tem : 0;
+    }
 
-   We return the simplified tree or 0 if no optimization is possible.  */
+  if (TREE_CODE_CLASS (code) != '<')
+    return 0;
+
+  /* Set SGN[01] to -1 if ARG[01] is a lower bound, 1 for upper, and 0
+     for neither.  Then compute our result treating them as never equal
+     and comparing bounds to non-bounds as above.  */
+  sgn0 = arg0 != 0 ? 0 : (upper0_p ? 1 : -1);
+  sgn1 = arg1 != 0 ? 0 : (upper1_p ? 1 : -1);
+  switch (code)
+    {
+    case EQ_EXPR:  case NE_EXPR:
+      result = (code == NE_EXPR);
+      break;
+    case LT_EXPR:  case LE_EXPR:
+      result = sgn0 < sgn1;
+      break;
+    case GT_EXPR:  case GE_EXPR:
+      result = sgn0 > sgn1;
+      break;
+    }
+
+  return convert (type, result ? integer_one_node : integer_zero_node);
+}
+\f      
+/* Given EXP, a logical expression, set the range it is testing into
+   variables denoted by PIN_P, PLOW, and PHIGH.  Return the expression
+   actually being tested.  *PLOW and *PHIGH will have be made the same type
+   as the returned expression.  If EXP is not a comparison, we will most
+   likely not be returning a useful value and range.  */
 
 static tree
-range_test (jcode, type, lo_code, hi_code, var, lo_cst, hi_cst)
-     enum tree_code jcode, lo_code, hi_code;
-     tree type, var, lo_cst, hi_cst;
+make_range (exp, pin_p, plow, phigh)
+     tree exp;
+     int *pin_p;
+     tree *plow, *phigh;
 {
-  tree utype;
-  enum tree_code rcode;
+  enum tree_code code;
+  tree arg0, arg1, type;
+  int in_p, n_in_p;
+  tree low, high, n_low, n_high;
+
+  /* Start with simply saying "EXP != 0" and then look at the code of EXP
+     and see if we can refine the range.  Some of the cases below may not
+     happen, but it doesn't seem worth worrying about this.  We "continue"
+     the outer loop when we've changed something; otherwise we "break"
+     the switch, which will "break" the while.  */
 
-  /* See if this is a range test and normalize the constant terms.  */
+  in_p = 0, low = high = convert (TREE_TYPE (exp), integer_zero_node);
 
-  if (jcode == TRUTH_AND_EXPR)
+  while (1)
     {
-      switch (lo_code)
+      code = TREE_CODE (exp);
+      arg0 = TREE_OPERAND (exp, 0), arg1 = TREE_OPERAND (exp, 1);
+      if (TREE_CODE_CLASS (code) == '<' || TREE_CODE_CLASS (code) == '1'
+         || TREE_CODE_CLASS (code) == '2')
+       type = TREE_TYPE (arg0);
+
+      switch (code)
        {
-       case NE_EXPR:
-         /* See if we have VAR != CST && VAR != CST+1.  */
-         if (! (hi_code == NE_EXPR
-                && TREE_INT_CST_LOW (hi_cst) - TREE_INT_CST_LOW (lo_cst) == 1
-                && tree_int_cst_equal (integer_one_node,
-                                       const_binop (MINUS_EXPR,
-                                                    hi_cst, lo_cst, 0))))
-           return 0;
+       case TRUTH_NOT_EXPR:
+         in_p = ! in_p, exp = arg0;
+         continue;
+
+       case EQ_EXPR: case NE_EXPR:
+       case LT_EXPR: case LE_EXPR: case GE_EXPR: case GT_EXPR:
+         /* We can only do something if the range is testing for zero
+            and if the second operand is an integer constant.  Note that
+            saying something is "in" the range we make is done by
+            complementing IN_P since it will set in the initial case of
+            being not equal to zero; "out" is leaving it alone.  */
+         if (low == 0 || high == 0
+             || ! integer_zerop (low) || ! integer_zerop (high)
+             || TREE_CODE (arg1) != INTEGER_CST)
+           break;
 
-         rcode = GT_EXPR;
-         break;
+         switch (code)
+           {
+           case NE_EXPR:  /* - [c, c]  */
+             low = high = arg1;
+             break;
+           case EQ_EXPR:  /* + [c, c]  */
+             in_p = ! in_p, low = high = arg1;
+             break;
+           case GT_EXPR:  /* - [-, c] */
+             low = 0, high = arg1;
+             break;
+           case GE_EXPR:  /* + [c, -] */
+             in_p = ! in_p, low = arg1, high = 0;
+             break;
+           case LT_EXPR:  /* - [c, -] */
+             low = arg1, high = 0;
+             break;
+           case LE_EXPR:  /* + [-, c] */
+             in_p = ! in_p, low = 0, high = arg1;
+             break;
+           }
 
-       case GT_EXPR:
-       case GE_EXPR:
-         if (hi_code == LT_EXPR)
-           hi_cst = const_binop (MINUS_EXPR, hi_cst, integer_one_node, 0);
-         else if (hi_code != LE_EXPR)
-           return 0;
+         exp = arg0;
 
-         if (lo_code == GT_EXPR)
-           lo_cst = const_binop (PLUS_EXPR, lo_cst, integer_one_node, 0);
+         /* If this is an unsigned comparison, we also know that EXP is
+            greater than or equal to zero.  We base the range tests we make
+            on that fact, so we record it here so we can parse existing
+            range tests.  */
+         if (TREE_UNSIGNED (type) && (low == 0 || high == 0))
+           {
+             if (! merge_ranges (&n_in_p, &n_low, &n_high, in_p, low, high,
+                                 1, convert (type, integer_zero_node),
+                                 NULL_TREE))
+               break;
 
-         /* We now have VAR >= LO_CST && VAR <= HI_CST.  */
-         rcode = LE_EXPR;
-         break;
+             in_p = n_in_p, low = n_low, high = n_high;
 
-       default:
-         return 0;
+             /* If the high bound is missing, reverse the range so it
+                goes from zero to the low bound minus 1.  */
+             if (high == 0)
+               {
+                 in_p = ! in_p;
+                 high = range_binop (MINUS_EXPR, NULL_TREE, low, 0,
+                                     integer_one_node, 0);
+                 low = convert (type, integer_zero_node);
+               }
+           }
+         continue;
+
+       case NEGATE_EXPR:
+         /* (-x) IN [a,b] -> x in [-b, -a]  */
+         n_low = range_binop (MINUS_EXPR, type,
+                              convert (type, integer_zero_node), 0, high, 1);
+         n_high = range_binop (MINUS_EXPR, type,
+                               convert (type, integer_zero_node), 0, low, 0);
+         low = n_low, high = n_high;
+         exp = arg0;
+         continue;
+
+       case BIT_NOT_EXPR:
+         /* ~ X -> -X - 1  */
+         exp = build (MINUS_EXPR, type, build1 (NEGATE_EXPR, type, arg0),
+                      convert (type, integer_one_node));
+         continue;
+
+       case PLUS_EXPR:  case MINUS_EXPR:
+         if (TREE_CODE (arg1) != INTEGER_CST)
+           break;
+
+         /* If EXP is signed, any overflow in the computation is undefined,
+            so we don't worry about it so long as our computations on
+            the bounds don't overflow.  For unsigned, overflow is defined
+            and this is exactly the right thing.  */
+         n_low = range_binop (code == MINUS_EXPR ? PLUS_EXPR : MINUS_EXPR,
+                              type, low, 0, arg1, 0);
+         n_high = range_binop (code == MINUS_EXPR ? PLUS_EXPR : MINUS_EXPR,
+                               type, high, 1, arg1, 0);
+         if ((n_low != 0 && TREE_OVERFLOW (n_low))
+             || (n_high != 0 && TREE_OVERFLOW (n_high)))
+           break;
+
+         /* Check for an unsigned range which has wrapped around the maximum
+            value thus making n_high < n_low, and normalize it.  */
+         if (n_low && n_high && tree_int_cst_lt (n_high, n_low))
+           {
+             low = range_binop (PLUS_EXPR, type, n_high, 0,
+                                integer_one_node, 0);
+             high = range_binop (MINUS_EXPR, type, n_low, 0,
+                                integer_one_node, 0);
+             in_p = ! in_p;
+           }
+         else
+           low = n_low, high = n_high;
+
+         exp = arg0;
+         continue;
+
+       case NOP_EXPR:  case NON_LVALUE_EXPR:  case CONVERT_EXPR:
+         if (! INTEGRAL_TYPE_P (type)
+             || (low != 0 && ! int_fits_type_p (low, type))
+             || (high != 0 && ! int_fits_type_p (high, type)))
+           break;
+
+         if (low != 0)
+           low = convert (type, low);
+
+         if (high != 0)
+           high = convert (type, high);
+
+         exp = arg0;
+         continue;
        }
+
+      break;
     }
-  else
+
+  /* If EXP is a constant, we can evaluate whether this is true or false.  */
+  if (TREE_CODE (exp) == INTEGER_CST)
     {
-      switch (lo_code)
-       {
-       case EQ_EXPR:
-         /* See if we have VAR == CST || VAR == CST+1.  */
-         if (! (hi_code == EQ_EXPR
-                && TREE_INT_CST_LOW (hi_cst) - TREE_INT_CST_LOW (lo_cst) == 1
-                && tree_int_cst_equal (integer_one_node,
-                                       const_binop (MINUS_EXPR,
-                                                    hi_cst, lo_cst, 0))))
-           return 0;
+      in_p = in_p == (integer_onep (range_binop (GE_EXPR, integer_type_node,
+                                                exp, 0, low, 0))
+                     && integer_onep (range_binop (LE_EXPR, integer_type_node,
+                                                   exp, 1, high, 1)));
+      low = high = 0;
+      exp = 0;
+    }
 
-         rcode = LE_EXPR;
-         break;
+  *pin_p = in_p, *plow = low, *phigh = high;
+  return exp;
+}
+\f
+/* Given a range, LOW, HIGH, and IN_P, an expression, EXP, and a result
+   type, TYPE, return an expression to test if EXP is in (or out of, depending
+   on IN_P) the range.  */
 
-       case LE_EXPR:
-       case LT_EXPR:
-         if (hi_code == GE_EXPR)
-           hi_cst = const_binop (MINUS_EXPR, hi_cst, integer_one_node, 0);
-         else if (hi_code != GT_EXPR)
-           return 0;
+static tree
+build_range_check (type, exp, in_p, low, high)
+     tree type;
+     tree exp;
+     int in_p;
+     tree low, high;
+{
+  tree etype = TREE_TYPE (exp);
+  tree utype, value;
 
-         if (lo_code == LE_EXPR)
-           lo_cst = const_binop (PLUS_EXPR, lo_cst, integer_one_node, 0);
+  if (! in_p
+      && (0 != (value = build_range_check (type, exp, 1, low, high))))
+    return invert_truthvalue (value);
 
-         /* We now have VAR < LO_CST || VAR > HI_CST.  */
-         rcode = GT_EXPR;
-         break;
+  else if (low == 0 && high == 0)
+    return convert (type, integer_one_node);
 
-       default:
-         return 0;
-       }
+  else if (low == 0)
+    return fold (build (LE_EXPR, type, exp, high));
+
+  else if (high == 0)
+    return fold (build (GE_EXPR, type, exp, low));
+
+  else if (operand_equal_p (low, high, 0))
+    return fold (build (EQ_EXPR, type, exp, low));
+
+  else if (TREE_UNSIGNED (etype) && integer_zerop (low))
+    return build_range_check (type, exp, 1, 0, high);
+
+  else if (integer_zerop (low))
+    {
+      utype = unsigned_type (etype);
+      return build_range_check (type, convert (utype, exp), 1, 0,
+                               convert (utype, high));
     }
 
-  /* When normalizing, it is possible to both increment the smaller constant
-     and decrement the larger constant.  See if they are still ordered.  */
-  if (tree_int_cst_lt (hi_cst, lo_cst))
+  else if (0 != (value = const_binop (MINUS_EXPR, high, low, 0))
+          && ! TREE_OVERFLOW (value))
+    return build_range_check (type,
+                             fold (build (MINUS_EXPR, etype, exp, low)),
+                             1, convert (etype, integer_zero_node), value);
+  else
     return 0;
+}
+\f
+/* Given two ranges, see if we can merge them into one.  Return 1 if we 
+   can, 0 if we can't.  Set the output range into the specified parameters.  */
 
-  /* Fail if VAR isn't an integer.  */
-  utype = TREE_TYPE (var);
-  if (! INTEGRAL_TYPE_P (utype))
-    return 0;
+static int
+merge_ranges (pin_p, plow, phigh, in0_p, low0, high0, in1_p, low1, high1)
+     int *pin_p;
+     tree *plow, *phigh;
+     int in0_p, in1_p;
+     tree low0, high0, low1, high1;
+{
+  int no_overlap;
+  int subset;
+  int temp;
+  tree tem;
+  int in_p;
+  tree low, high;
+
+  /* Make range 0 be the range that starts first.  Swap them if it isn't.  */
+  if (integer_onep (range_binop (GT_EXPR, integer_type_node, 
+                                low0, 0, low1, 0))
+      || (((low0 == 0 && low1 == 0)
+          || integer_onep (range_binop (EQ_EXPR, integer_type_node,
+                                        low0, 0, low1, 0)))
+         && integer_onep (range_binop (GT_EXPR, integer_type_node,
+                                       high0, 1, high1, 1))))
+    {
+      temp = in0_p, in0_p = in1_p, in1_p = temp;
+      tem = low0, low0 = low1, low1 = tem;
+      tem = high0, high0 = high1, high1 = tem;
+    }
 
-  /* The range test is invalid if subtracting the two constants results
-     in overflow.  This can happen in traditional mode.  */
-  if (! int_fits_type_p (hi_cst, TREE_TYPE (var))
-      || ! int_fits_type_p (lo_cst, TREE_TYPE (var)))
-    return 0;
+  /* Now flag two cases, whether the ranges are disjoint or whether the
+     second range is totally subsumed in the first.  Note that the tests
+     below are simplified by the ones above.  */
+  no_overlap = integer_onep (range_binop (LT_EXPR, integer_type_node,
+                                         high0, 1, low1, 0));
+  subset = integer_onep (range_binop (LE_EXPR, integer_type_node,
+                                     high1, 1, high0, 1));
+
+  /* We now have four cases, depending on whether we are including or
+     excluding the two ranges.  */
+  if (in0_p && in1_p)
+    {
+      /* If they don't overlap, the result is false.  If the second range
+        is a subset it is the result.  Otherwise, the range is from the start
+        of the second to the end of the first.  */
+      if (no_overlap)
+       in_p = 0, low = high = 0;
+      else if (subset)
+       in_p = 1, low = low1, high = high1;
+      else
+       in_p = 1, low = low1, high = high0;
+    }
 
-  if (! TREE_UNSIGNED (utype))
+  else if (in0_p && ! in1_p)
     {
-      utype = unsigned_type (utype);
-      var = convert (utype, var);
-      lo_cst = convert (utype, lo_cst);
-      hi_cst = convert (utype, hi_cst);
+      /* If they don't overlap, the result is the first range.  If the
+        second range is a subset of the first, we can't describe this as
+        a single range unless both ranges end at the same place.  If both
+        ranges start in the same place, then the result is false.
+        Otherwise, we go from the start of the first range to just before
+        the start of the second.  */
+      if (no_overlap)
+       in_p = 1, low = low0, high = high0;
+      else if (subset
+              && integer_zerop (range_binop (EQ_EXPR, integer_type_node,
+                                             high0, 1, high1, 0)))
+       return 0;
+      else if (integer_onep (range_binop (EQ_EXPR, integer_type_node,
+                                         low0, 0, low1, 0)))
+       in_p = 0, low = high = 0;
+      else
+       {
+         in_p = 1, low = low0;
+         high = range_binop (MINUS_EXPR, NULL_TREE, low1, 0,
+                             integer_one_node, 0);
+       }
     }
 
-  return fold (convert (type,
-                       build (rcode, utype,
-                              build (MINUS_EXPR, utype, var, lo_cst),
-                              const_binop (MINUS_EXPR, hi_cst, lo_cst, 0))));
+  else if (! in0_p && in1_p)
+    {
+      /* If they don't overlap, the result is the second range.  If the second
+        is a subset of the first, the result is false.  Otherwise,
+        the range starts just after the first range and ends at the
+        end of the second.  */
+      if (no_overlap)
+       in_p = 1, low = low1, high = high1;
+      else if (subset)
+       in_p = 0, low = high = 0;
+      else
+       {
+         in_p = 1, high = high1;
+         low = range_binop (PLUS_EXPR, NULL_TREE, high0, 1,
+                            integer_one_node, 0);
+       }
+    }
+
+  else
+    {
+      /* The case where we are excluding both ranges.  Here the complex case
+        is if they don't overlap.  In that case, the only time we have a
+        range is if they are adjacent.  If the second is a subset of the
+        first, the result is the first.  Otherwise, the range to exclude
+        starts at the beginning of the first range and ends at the end of the
+        second.  */
+      if (no_overlap)
+       {
+         if (integer_onep (range_binop (EQ_EXPR, integer_type_node,
+                                        range_binop (PLUS_EXPR, NULL_TREE,
+                                                     high0, 1,
+                                                     integer_one_node, 1),
+                                        1, low1, 0)))
+           in_p = 0, low = low0, high = high1;
+         else
+           return 0;
+       }
+      else if (subset)
+       in_p = 0, low = low0, high = high0;
+      else
+       in_p = 0, low = low0, high = high1;
+    }
+
+  *pin_p = in_p, *plow = low, *phigh = high;
+  return 1;
+}
+\f
+/* EXP is some logical combination of boolean tests.  See if we can
+   merge it into some range test.  Return the new tree if so.  */
+
+static tree
+fold_range_test (exp)
+     tree exp;
+{
+  int or_op = (TREE_CODE (exp) == TRUTH_ORIF_EXPR
+              || TREE_CODE (exp) == TRUTH_OR_EXPR);
+  int in0_p, in1_p, in_p;
+  tree low0, low1, low, high0, high1, high;
+  tree lhs = make_range (TREE_OPERAND (exp, 0), &in0_p, &low0, &high0);
+  tree rhs = make_range (TREE_OPERAND (exp, 1), &in1_p, &low1, &high1);
+  tree tem;
+
+  /* If this is an OR operation, invert both sides; we will invert
+     again at the end.  */
+  if (or_op)
+    in0_p = ! in0_p, in1_p = ! in1_p;
+
+  /* If both expressions are the same, if we can merge the ranges, and we
+     can build the range test, return it or it inverted.  If one of the
+     ranges is always true or always false, consider it to be the same
+     expression as the other.  */
+  if ((lhs == 0 || rhs == 0 || operand_equal_p (lhs, rhs, 0))
+      && merge_ranges (&in_p, &low, &high, in0_p, low0, high0,
+                      in1_p, low1, high1)
+      && 0 != (tem = (build_range_check (TREE_TYPE (exp),
+                                        lhs != 0 ? lhs
+                                        : rhs != 0 ? rhs : integer_zero_node,
+                                        in_p, low, high))))
+    return or_op ? invert_truthvalue (tem) : tem;
+
+  /* On machines where the branch cost is expensive, if this is a
+     short-circuited branch and the underlying object on both sides
+     is the same, make a non-short-circuit operation.  */
+  else if (BRANCH_COST >= 2
+          && (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
+              || TREE_CODE (exp) == TRUTH_ORIF_EXPR)
+          && operand_equal_p (lhs, rhs, 0))
+    {
+      /* If simple enough, just rewrite.  Otherwise, make a SAVE_EXPR.  */
+      if (simple_operand_p (lhs))
+       return build (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
+                     ? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
+                     TREE_TYPE (exp), TREE_OPERAND (exp, 0),
+                     TREE_OPERAND (exp, 1));
+      else
+       {
+         tree common = save_expr (lhs);
+
+         if (0 != (lhs = build_range_check (TREE_TYPE (exp), common,
+                                            or_op ? ! in0_p : in0_p,
+                                            low0, high0))
+             && (0 != (rhs = build_range_check (TREE_TYPE (exp), common,
+                                                or_op ? ! in1_p : in1_p,
+                                                low1, high1))))
+           return build (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
+                         ? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
+                         TREE_TYPE (exp), lhs, rhs);
+       }
+    }
+  else
+    return 0;
+}
+\f
+/* Subroutine for fold_truthop: C is an INTEGER_CST interpreted as a P
+   bit value.  Arrange things so the extra bits will be set to zero if and
+   only if C is signed-extended to its full width.  If MASK is nonzero,
+   it is an INTEGER_CST that should be AND'ed with the extra bits.  */
+
+static tree
+unextend (c, p, unsignedp, mask)
+     tree c;
+     int p;
+     int unsignedp;
+     tree mask;
+{
+  tree type = TREE_TYPE (c);
+  int modesize = GET_MODE_BITSIZE (TYPE_MODE (type));
+  tree temp;
+
+  if (p == modesize || unsignedp)
+    return c;
+
+  /* We work by getting just the sign bit into the low-order bit, then
+     into the high-order bit, then sign-extend.  We then XOR that value
+     with C.  */
+  temp = const_binop (RSHIFT_EXPR, c, size_int (p - 1), 0);
+  temp = const_binop (BIT_AND_EXPR, temp, size_int (1), 0);
+
+  /* We must use a signed type in order to get an arithmetic right shift.
+     However, we must also avoid introducing accidental overflows, so that
+     a subsequent call to integer_zerop will work.  Hence we must 
+     do the type conversion here.  At this point, the constant is either
+     zero or one, and the conversion to a signed type can never overflow.
+     We could get an overflow if this conversion is done anywhere else.  */
+  if (TREE_UNSIGNED (type))
+    temp = convert (signed_type (type), temp);
+
+  temp = const_binop (LSHIFT_EXPR, temp, size_int (modesize - 1), 0);
+  temp = const_binop (RSHIFT_EXPR, temp, size_int (modesize - p - 1), 0);
+  if (mask != 0)
+    temp = const_binop (BIT_AND_EXPR, temp, convert (TREE_TYPE (c), mask), 0);
+  /* If necessary, convert the type back to match the type of C.  */
+  if (TREE_UNSIGNED (type))
+    temp = convert (type, temp);
+
+  return convert (type, const_binop (BIT_XOR_EXPR, c, temp, 0));
 }
 \f
 /* Find ways of folding logical expressions of LHS and RHS:
@@ -2660,18 +3222,17 @@ fold_truthop (code, truth_type, lhs, rhs)
   enum machine_mode ll_mode, lr_mode, rl_mode, rr_mode;
   enum machine_mode lnmode, rnmode;
   tree ll_mask, lr_mask, rl_mask, rr_mask;
+  tree ll_and_mask, lr_and_mask, rl_and_mask, rr_and_mask;
   tree l_const, r_const;
   tree type, result;
   int first_bit, end_bit;
   int volatilep;
 
-  /* Start by getting the comparison codes and seeing if this looks like
-     a range test.  Fail if anything is volatile.  If one operand is a
-     BIT_AND_EXPR with the constant one, treat it as if it were surrounded
-     with a NE_EXPR.  */
+  /* Start by getting the comparison codes.  Fail if anything is volatile.
+     If one operand is a BIT_AND_EXPR with the constant one, treat it as if
+     it were surrounded with a NE_EXPR.  */
 
-  if (TREE_SIDE_EFFECTS (lhs)
-      || TREE_SIDE_EFFECTS (rhs))
+  if (TREE_SIDE_EFFECTS (lhs) || TREE_SIDE_EFFECTS (rhs))
     return 0;
 
   lcode = TREE_CODE (lhs);
@@ -2683,8 +3244,7 @@ fold_truthop (code, truth_type, lhs, rhs)
   if (rcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (rhs, 1)))
     rcode = NE_EXPR, rhs = build (NE_EXPR, truth_type, rhs, integer_zero_node);
 
-  if (TREE_CODE_CLASS (lcode) != '<'
-      || TREE_CODE_CLASS (rcode) != '<')
+  if (TREE_CODE_CLASS (lcode) != '<' || TREE_CODE_CLASS (rcode) != '<')
     return 0;
 
   code = ((code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR)
@@ -2695,36 +3255,6 @@ fold_truthop (code, truth_type, lhs, rhs)
   rl_arg = TREE_OPERAND (rhs, 0);
   rr_arg = TREE_OPERAND (rhs, 1);
   
-  if (TREE_CODE (lr_arg) == INTEGER_CST
-      && TREE_CODE (rr_arg) == INTEGER_CST
-      && operand_equal_p (ll_arg, rl_arg, 0))
-    {
-      if (tree_int_cst_lt (lr_arg, rr_arg))
-       result = range_test (code, truth_type, lcode, rcode,
-                            ll_arg, lr_arg, rr_arg);
-      else
-       result = range_test (code, truth_type, rcode, lcode,
-                            ll_arg, rr_arg, lr_arg);
-
-      /* If this isn't a range test, it also isn't a comparison that
-        can be merged.  However, it wins to evaluate the RHS unconditionally
-        on machines with expensive branches.   */
-
-      if (result == 0 && BRANCH_COST >= 2)
-       {
-         if (TREE_CODE (ll_arg) != VAR_DECL
-             && TREE_CODE (ll_arg) != PARM_DECL)
-           {
-             /* Avoid evaluating the variable part twice.  */
-             ll_arg = save_expr (ll_arg);
-             lhs = build (lcode, TREE_TYPE (lhs), ll_arg, lr_arg);
-             rhs = build (rcode, TREE_TYPE (rhs), ll_arg, rr_arg);
-           }
-         return build (code, truth_type, lhs, rhs);
-       }
-      return result;
-    }
-
   /* If the RHS can be evaluated unconditionally and its operands are
      simple, it wins to evaluate the RHS unconditionally on machines
      with expensive branches.  In this case, this isn't a comparison
@@ -2749,16 +3279,20 @@ fold_truthop (code, truth_type, lhs, rhs)
   volatilep = 0;
   ll_inner = decode_field_reference (ll_arg,
                                     &ll_bitsize, &ll_bitpos, &ll_mode,
-                                    &ll_unsignedp, &volatilep, &ll_mask);
+                                    &ll_unsignedp, &volatilep, &ll_mask,
+                                    &ll_and_mask);
   lr_inner = decode_field_reference (lr_arg,
                                     &lr_bitsize, &lr_bitpos, &lr_mode,
-                                    &lr_unsignedp, &volatilep, &lr_mask);
+                                    &lr_unsignedp, &volatilep, &lr_mask,
+                                    &lr_and_mask);
   rl_inner = decode_field_reference (rl_arg,
                                     &rl_bitsize, &rl_bitpos, &rl_mode,
-                                    &rl_unsignedp, &volatilep, &rl_mask);
+                                    &rl_unsignedp, &volatilep, &rl_mask,
+                                    &rl_and_mask);
   rr_inner = decode_field_reference (rr_arg,
                                     &rr_bitsize, &rr_bitpos, &rr_mode,
-                                    &rr_unsignedp, &volatilep, &rr_mask);
+                                    &rr_unsignedp, &volatilep, &rr_mask,
+                                    &rr_and_mask);
 
   /* It must be true that the inner operation on the lhs of each
      comparison must be the same if we are to be able to do anything.
@@ -2814,30 +3348,52 @@ fold_truthop (code, truth_type, lhs, rhs)
   type = type_for_size (lnbitsize, 1);
   xll_bitpos = ll_bitpos - lnbitpos, xrl_bitpos = rl_bitpos - lnbitpos;
 
-#if BYTES_BIG_ENDIAN
-  xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize;
-  xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize;
-#endif
+  if (BYTES_BIG_ENDIAN)
+    {
+      xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize;
+      xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize;
+    }
 
   ll_mask = const_binop (LSHIFT_EXPR, convert (type, ll_mask),
                         size_int (xll_bitpos), 0);
   rl_mask = const_binop (LSHIFT_EXPR, convert (type, rl_mask),
                         size_int (xrl_bitpos), 0);
 
-  /* Make sure the constants are interpreted as unsigned, so we
-     don't have sign bits outside the range of their type.  */
-
   if (l_const)
     {
-      l_const = convert (unsigned_type (TREE_TYPE (l_const)), l_const);
-      l_const = const_binop (LSHIFT_EXPR, convert (type, l_const),
-                            size_int (xll_bitpos), 0);
+      l_const = convert (type, l_const);
+      l_const = unextend (l_const,  ll_bitsize, ll_unsignedp, ll_and_mask);
+      l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos), 0);
+      if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
+                                       fold (build1 (BIT_NOT_EXPR,
+                                                     type, ll_mask)),
+                                       0)))
+       {
+         warning ("comparison is always %s",
+                  wanted_code == NE_EXPR ? "one" : "zero");
+         
+         return convert (truth_type,
+                         wanted_code == NE_EXPR
+                         ? integer_one_node : integer_zero_node);
+       }
     }
   if (r_const)
     {
-      r_const = convert (unsigned_type (TREE_TYPE (r_const)), r_const);
-      r_const = const_binop (LSHIFT_EXPR, convert (type, r_const),
-                            size_int (xrl_bitpos), 0);
+      r_const = convert (type, r_const);
+      r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
+      r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos), 0);
+      if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
+                                       fold (build1 (BIT_NOT_EXPR,
+                                                     type, rl_mask)),
+                                       0)))
+       {
+         warning ("comparison is always %s",
+                  wanted_code == NE_EXPR ? "one" : "zero");
+         
+         return convert (truth_type,
+                         wanted_code == NE_EXPR
+                         ? integer_one_node : integer_zero_node);
+       }
     }
 
   /* If the right sides are not constant, do the same for it.  Also,
@@ -2864,10 +3420,11 @@ fold_truthop (code, truth_type, lhs, rhs)
       rnbitpos = first_bit & ~ (rnbitsize - 1);
       xlr_bitpos = lr_bitpos - rnbitpos, xrr_bitpos = rr_bitpos - rnbitpos;
 
-#if BYTES_BIG_ENDIAN
-      xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize;
-      xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize;
-#endif
+      if (BYTES_BIG_ENDIAN)
+       {
+         xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize;
+         xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize;
+       }
 
       lr_mask = const_binop (LSHIFT_EXPR, convert (type, lr_mask),
                             size_int (xlr_bitpos), 0);
@@ -3013,8 +3570,9 @@ fold (expr)
 
   int wins = 1;
 
-  /* Don't try to process an RTL_EXPR since its operands aren't trees.  */
-  if (code == RTL_EXPR)
+  /* Don't try to process an RTL_EXPR since its operands aren't trees. 
+     Likewise for a SAVE_EXPR that's already been evaluated.  */
+  if (code == RTL_EXPR || (code == SAVE_EXPR && SAVE_EXPR_RTL (t)) != 0)
     return t;
 
   /* Return right away if already constant.  */
@@ -3164,9 +3722,13 @@ fold (expr)
                           fold (build1 (code, type, TREE_OPERAND (arg0, 2)))));
 
          /* If this was a conversion, and all we did was to move into
-            inside the COND_EXPR, bring it back out.  Then return so we
-            don't get into an infinite recursion loop taking the conversion
-            out and then back in.  */
+            inside the COND_EXPR, bring it back out.  But leave it if
+            it is a conversion from integer to integer and the
+            result precision is no wider than a word since such a
+            conversion is cheap and may be optimized away by combine,
+            while it couldn't if it were outside the COND_EXPR.  Then return
+            so we don't get into an infinite recursion loop taking the
+            conversion out and then back in.  */
 
          if ((code == NOP_EXPR || code == CONVERT_EXPR
               || code == NON_LVALUE_EXPR)
@@ -3174,7 +3736,10 @@ fold (expr)
              && TREE_CODE (TREE_OPERAND (t, 1)) == code
              && TREE_CODE (TREE_OPERAND (t, 2)) == code
              && (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0))
-                 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 2), 0))))
+                 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 2), 0)))
+             && ! (INTEGRAL_TYPE_P (TREE_TYPE (t))
+                   && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0)))
+                   && TYPE_PRECISION (TREE_TYPE (t)) <= BITS_PER_WORD))
            t = build1 (code, type,
                        build (COND_EXPR,
                               TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0)),
@@ -3196,7 +3761,8 @@ fold (expr)
                      fold (build (code, type,
                                   arg0, TREE_OPERAND (arg1, 1))));
       else if (TREE_CODE (arg1) == COND_EXPR
-              || TREE_CODE_CLASS (TREE_CODE (arg1)) == '<')
+              || (TREE_CODE_CLASS (TREE_CODE (arg1)) == '<'
+                  && TREE_CODE_CLASS (code) != '<'))
        {
          tree test, true_value, false_value;
 
@@ -3208,9 +3774,10 @@ fold (expr)
            }
          else
            {
+             tree testtype = TREE_TYPE (arg1);
              test = arg1;
-             true_value = integer_one_node;
-             false_value = integer_zero_node;
+             true_value = convert (testtype, integer_one_node);
+             false_value = convert (testtype, integer_zero_node);
            }
 
          /* If ARG0 is complex we want to make sure we only evaluate
@@ -3219,7 +3786,7 @@ fold (expr)
             succeed in folding one part to a constant, we do not need
             to make this SAVE_EXPR.  Since we do this optimization
             primarily to see if we do end up with constant and this
-            SAVE_EXPR interfers with later optimizations, suppressing
+            SAVE_EXPR interferes with later optimizations, suppressing
             it when we can is important.  */
 
          if (TREE_CODE (arg0) != SAVE_EXPR
@@ -3251,7 +3818,8 @@ fold (expr)
        return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
                      fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
       else if (TREE_CODE (arg0) == COND_EXPR
-              || TREE_CODE_CLASS (TREE_CODE (arg0)) == '<')
+              || (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
+                  && TREE_CODE_CLASS (code) != '<'))
        {
          tree test, true_value, false_value;
 
@@ -3263,9 +3831,10 @@ fold (expr)
            }
          else
            {
+             tree testtype = TREE_TYPE (arg0);
              test = arg0;
-             true_value = integer_one_node;
-             false_value = integer_zero_node;
+             true_value = convert (testtype, integer_one_node);
+             false_value = convert (testtype, integer_zero_node);
            }
 
          if (TREE_CODE (arg1) != SAVE_EXPR
@@ -3321,59 +3890,80 @@ fold (expr)
     case FIX_TRUNC_EXPR:
       /* Other kinds of FIX are not handled properly by fold_convert.  */
 
-      /* In addition to the cases of two conversions in a row 
-        handled below, if we are converting something to its own
-        type via an object of identical or wider precision, neither
-        conversion is needed.  */
-      if ((TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
-          || TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)
-         && TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) == TREE_TYPE (t)
-         && ((INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0)))
-              && INTEGRAL_TYPE_P (TREE_TYPE (t)))
-             || (FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0)))
-                 && FLOAT_TYPE_P (TREE_TYPE (t))))
-         && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (t, 0)))
-             >= TYPE_PRECISION (TREE_TYPE (t))))
-       return TREE_OPERAND (TREE_OPERAND (t, 0), 0);
-
-      /* Two conversions in a row are not needed unless:
-        - the intermediate type is narrower than both initial and final, or
-        - the intermediate type and innermost type differ in signedness,
-          and the outermost type is wider than the intermediate, or
-        - the initial type is a pointer type and the precisions of the
-          intermediate and final types differ, or
-        - the final type is a pointer type and the precisions of the 
-         initial and intermediate types differ.  */
-      if ((TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
-          || TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)
-         && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (t, 0)))
-             > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
-             ||
-             TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (t, 0)))
-             > TYPE_PRECISION (TREE_TYPE (t)))
-         && ! ((TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
-                == INTEGER_TYPE)
-               && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
-                   == INTEGER_TYPE)
-               && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t, 0)))
-                   != TREE_UNSIGNED (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
-               && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (t, 0)))
-                   < TYPE_PRECISION (TREE_TYPE (t))))
-         && ((TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t, 0)))
-              && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (t, 0)))
-                  > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))))
-             ==
-             (TREE_UNSIGNED (TREE_TYPE (t))
-              && (TYPE_PRECISION (TREE_TYPE (t))
-                  > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (t, 0))))))
-         && ! ((TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
-                == POINTER_TYPE)
-               && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (t, 0)))
-                   != TYPE_PRECISION (TREE_TYPE (t))))
-         && ! (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
-               && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
-                   != TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (t, 0))))))
-       return convert (TREE_TYPE (t), TREE_OPERAND (TREE_OPERAND (t, 0), 0));
+      if (TREE_TYPE (TREE_OPERAND (t, 0)) == TREE_TYPE (t))
+       return TREE_OPERAND (t, 0);
+
+      /* Handle cases of two conversions in a row.  */
+      if (TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
+         || TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)
+       {
+         tree inside_type = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
+         tree inter_type = TREE_TYPE (TREE_OPERAND (t, 0));
+         tree final_type = TREE_TYPE (t);
+         int inside_int = INTEGRAL_TYPE_P (inside_type);
+         int inside_ptr = POINTER_TYPE_P (inside_type);
+         int inside_float = FLOAT_TYPE_P (inside_type);
+         int inside_prec = TYPE_PRECISION (inside_type);
+         int inside_unsignedp = TREE_UNSIGNED (inside_type);
+         int inter_int = INTEGRAL_TYPE_P (inter_type);
+         int inter_ptr = POINTER_TYPE_P (inter_type);
+         int inter_float = FLOAT_TYPE_P (inter_type);
+         int inter_prec = TYPE_PRECISION (inter_type);
+         int inter_unsignedp = TREE_UNSIGNED (inter_type);
+         int final_int = INTEGRAL_TYPE_P (final_type);
+         int final_ptr = POINTER_TYPE_P (final_type);
+         int final_float = FLOAT_TYPE_P (final_type);
+         int final_prec = TYPE_PRECISION (final_type);
+         int final_unsignedp = TREE_UNSIGNED (final_type);
+
+         /* In addition to the cases of two conversions in a row 
+            handled below, if we are converting something to its own
+            type via an object of identical or wider precision, neither
+            conversion is needed.  */
+         if (inside_type == final_type
+             && ((inter_int && final_int) || (inter_float && final_float))
+             && inter_prec >= final_prec)
+           return TREE_OPERAND (TREE_OPERAND (t, 0), 0);
+
+         /* Likewise, if the intermediate and final types are either both
+            float or both integer, we don't need the middle conversion if
+            it is wider than the final type and doesn't change the signedness
+            (for integers).  Avoid this if the final type is a pointer
+            since then we sometimes need the inner conversion.  Likewise if
+            the outer has a precision not equal to the size of its mode.  */
+         if ((((inter_int || inter_ptr) && (inside_int || inside_ptr))
+              || (inter_float && inside_float))
+             && inter_prec >= inside_prec
+             && (inter_float || inter_unsignedp == inside_unsignedp)
+             && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (final_type))
+                   && TYPE_MODE (final_type) == TYPE_MODE (inter_type))
+             && ! final_ptr)
+           return convert (final_type, TREE_OPERAND (TREE_OPERAND (t, 0), 0));
+
+         /* Two conversions in a row are not needed unless:
+            - some conversion is floating-point (overstrict for now), or
+            - the intermediate type is narrower than both initial and
+              final, or
+            - the intermediate type and innermost type differ in signedness,
+              and the outermost type is wider than the intermediate, or
+            - the initial type is a pointer type and the precisions of the
+              intermediate and final types differ, or
+            - the final type is a pointer type and the precisions of the 
+              initial and intermediate types differ.  */
+         if (! inside_float && ! inter_float && ! final_float
+             && (inter_prec > inside_prec || inter_prec > final_prec)
+             && ! (inside_int && inter_int
+                   && inter_unsignedp != inside_unsignedp
+                   && inter_prec < final_prec)
+             && ((inter_unsignedp && inter_prec > inside_prec)
+                 == (final_unsignedp && final_prec > inter_prec))
+             && ! (inside_ptr && inter_prec != final_prec)
+             && ! (final_ptr && inside_prec != inter_prec)
+             && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (final_type))
+                   && TYPE_MODE (final_type) == TYPE_MODE (inter_type))
+             && ! final_ptr)
+           return convert (final_type, TREE_OPERAND (TREE_OPERAND (t, 0), 0));
+       }
 
       if (TREE_CODE (TREE_OPERAND (t, 0)) == MODIFY_EXPR
          && TREE_CONSTANT (TREE_OPERAND (TREE_OPERAND (t, 0), 1))
@@ -3416,6 +4006,15 @@ fold (expr)
       return t;
 #endif /* 0 */
 
+    case COMPONENT_REF:
+      if (TREE_CODE (arg0) == CONSTRUCTOR)
+       {
+         tree m = purpose_member (arg1, CONSTRUCTOR_ELTS (arg0));
+         if (m)
+           t = TREE_VALUE (m);
+       }
+      return t;
+
     case RANGE_EXPR:
       TREE_CONSTANT (t) = wins;
       return t;
@@ -3433,13 +4032,12 @@ fold (expr)
              TREE_TYPE (t) = type;
              TREE_OVERFLOW (t)
                = (TREE_OVERFLOW (arg0)
-                  | force_fit_type (t, overflow));
+                  | force_fit_type (t, overflow && !TREE_UNSIGNED (type)));
              TREE_CONSTANT_OVERFLOW (t)
                = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0);
            }
          else if (TREE_CODE (arg0) == REAL_CST)
            t = build_real (type, REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
-         TREE_TYPE (t) = type;
        }
       else if (TREE_CODE (arg0) == NEGATE_EXPR)
        return TREE_OPERAND (arg0, 0);
@@ -3478,7 +4076,6 @@ fold (expr)
                t = build_real (type,
                                REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
            }
-         TREE_TYPE (t) = type;
        }
       else if (TREE_CODE (arg0) == ABS_EXPR || TREE_CODE (arg0) == NEGATE_EXPR)
        return build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0));
@@ -3494,7 +4091,7 @@ fold (expr)
                                    TREE_TYPE (TREE_TYPE (arg0)),
                                    TREE_OPERAND (arg0, 1))));
       else if (TREE_CODE (arg0) == COMPLEX_CST)
-       return build_complex (TREE_OPERAND (arg0, 0),
+       return build_complex (type, TREE_OPERAND (arg0, 0),
                              fold (build1 (NEGATE_EXPR,
                                            TREE_TYPE (TREE_TYPE (arg0)),
                                            TREE_OPERAND (arg0, 1))));
@@ -3511,9 +4108,8 @@ fold (expr)
     case BIT_NOT_EXPR:
       if (wins)
        {
-         if (TREE_CODE (arg0) == INTEGER_CST)
-           t = build_int_2 (~ TREE_INT_CST_LOW (arg0),
-                            ~ TREE_INT_CST_HIGH (arg0));
+         t = build_int_2 (~ TREE_INT_CST_LOW (arg0),
+                          ~ TREE_INT_CST_HIGH (arg0));
          TREE_TYPE (t) = type;
          force_fit_type (t, 0);
          TREE_OVERFLOW (t) = TREE_OVERFLOW (arg0);
@@ -3600,10 +4196,8 @@ fold (expr)
                    return t;
 
                  /* Otherwise return (CON +- ARG1) - VAR.  */
-                 TREE_SET_CODE (t, MINUS_EXPR);
-                 TREE_OPERAND (t, 1) = var;
-                 TREE_OPERAND (t, 0)
-                   = fold (build (code, TREE_TYPE (t), con, arg1));
+                 t = build (MINUS_EXPR, type,
+                            fold (build (code, type, con, arg1)), var);
                }
              else
                {
@@ -3619,9 +4213,9 @@ fold (expr)
                    return t;
 
                  /* Otherwise return VAR +- (ARG1 +- CON).  */
-                 TREE_OPERAND (t, 1) = tem
-                   = fold (build (code, TREE_TYPE (t), arg1, con));
-                 TREE_OPERAND (t, 0) = var;
+                 tem = fold (build (code, type, arg1, con));
+                 t = build (code, type, var, tem);
+
                  if (integer_zerop (tem)
                      && (code == PLUS_EXPR || code == MINUS_EXPR))
                    return convert (type, var);
@@ -3662,9 +4256,9 @@ fold (expr)
                                       convert (TREE_TYPE (t), con)));
                }
 
-             TREE_OPERAND (t, 0)
-               = fold (build (code, TREE_TYPE (t), arg0, con));
-             TREE_OPERAND (t, 1) = var;
+             t = build (TREE_CODE (t), type,
+                        fold (build (code, TREE_TYPE (t), arg0, con)), var);
+
              if (integer_zerop (TREE_OPERAND (t, 0))
                  && TREE_CODE (t) == PLUS_EXPR)
                return convert (TREE_TYPE (t), var);
@@ -3682,7 +4276,9 @@ fold (expr)
        {
          /* The return value should always have
             the same type as the original expression.  */
-         TREE_TYPE (t1) = TREE_TYPE (t);
+         if (TREE_TYPE (t1) != TREE_TYPE (t))
+           t1 = convert (TREE_TYPE (t), t1);
+
          return t1;
        }
       return t;
@@ -3729,8 +4325,8 @@ fold (expr)
         Also note that operand_equal_p is always false if an operand
         is volatile.  */
 
-      if (operand_equal_p (arg0, arg1,
-                          FLOAT_TYPE_P (type) && ! flag_fast_math))
+      if ((! FLOAT_TYPE_P (type) || flag_fast_math)
+         && operand_equal_p (arg0, arg1, 0))
        return convert (type, integer_zero_node);
 
       goto associate;
@@ -3784,6 +4380,9 @@ fold (expr)
 
     case BIT_IOR_EXPR:
     bit_ior:
+      {
+      register enum tree_code code0, code1;
+
       if (integer_all_onesp (arg1))
        return omit_one_operand (type, arg1, arg0);
       if (integer_zerop (arg1))
@@ -3792,28 +4391,53 @@ fold (expr)
       if (t1 != NULL_TREE)
        return t1;
 
-      /* (a << C1) | (a >> C2) if A is unsigned and C1+C2 is the size of A
+      /* (A << C1) | (A >> C2) if A is unsigned and C1+C2 is the size of A
         is a rotate of A by C1 bits.  */
+      /* (A << B) | (A >> (Z - B)) if A is unsigned and Z is the size of A
+        is a rotate of A by B bits.  */
 
-      if ((TREE_CODE (arg0) == RSHIFT_EXPR
-          || TREE_CODE (arg0) == LSHIFT_EXPR)
-         && (TREE_CODE (arg1) == RSHIFT_EXPR
-             || TREE_CODE (arg1) == LSHIFT_EXPR)
-         && TREE_CODE (arg0) != TREE_CODE (arg1)
+      code0 = TREE_CODE (arg0);
+      code1 = TREE_CODE (arg1);
+      if (((code0 == RSHIFT_EXPR && code1 == LSHIFT_EXPR)
+         || (code1 == RSHIFT_EXPR && code0 == LSHIFT_EXPR))
          && operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1,0), 0)
-         && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0)))
-         && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
-         && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
-         && TREE_INT_CST_HIGH (TREE_OPERAND (arg0, 1)) == 0
-         && TREE_INT_CST_HIGH (TREE_OPERAND (arg1, 1)) == 0
-         && ((TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1))
-              + TREE_INT_CST_LOW (TREE_OPERAND (arg1, 1)))
+         && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
+       {
+         register tree tree01, tree11;
+         register enum tree_code code01, code11;
+
+         tree01 = TREE_OPERAND (arg0, 1);
+         tree11 = TREE_OPERAND (arg1, 1);
+         code01 = TREE_CODE (tree01);
+         code11 = TREE_CODE (tree11);
+         if (code01 == INTEGER_CST
+           && code11 == INTEGER_CST
+           && TREE_INT_CST_HIGH (tree01) == 0
+           && TREE_INT_CST_HIGH (tree11) == 0
+           && ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW (tree11))
              == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))))
-       return build (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0),
-                     TREE_CODE (arg0) == LSHIFT_EXPR
-                     ? TREE_OPERAND (arg0, 1) : TREE_OPERAND (arg1, 1));
+           return build (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0),
+                     code0 == LSHIFT_EXPR ? tree01 : tree11);
+         else if (code11 == MINUS_EXPR
+               && TREE_CODE (TREE_OPERAND (tree11, 0)) == INTEGER_CST
+               && TREE_INT_CST_HIGH (TREE_OPERAND (tree11, 0)) == 0
+               && TREE_INT_CST_LOW (TREE_OPERAND (tree11, 0))
+                 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))
+               && operand_equal_p (tree01, TREE_OPERAND (tree11, 1), 0))
+           return build (code0 == LSHIFT_EXPR ? LROTATE_EXPR : RROTATE_EXPR,
+                       type, TREE_OPERAND (arg0, 0), tree01);
+         else if (code01 == MINUS_EXPR
+               && TREE_CODE (TREE_OPERAND (tree01, 0)) == INTEGER_CST
+               && TREE_INT_CST_HIGH (TREE_OPERAND (tree01, 0)) == 0
+               && TREE_INT_CST_LOW (TREE_OPERAND (tree01, 0))
+                 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))
+               && operand_equal_p (tree11, TREE_OPERAND (tree01, 1), 0))
+           return build (code0 != LSHIFT_EXPR ? LROTATE_EXPR : RROTATE_EXPR,
+                       type, TREE_OPERAND (arg0, 0), tree11);
+       }
 
       goto associate;
+      }
 
     case BIT_XOR_EXPR:
       if (integer_zerop (arg1))
@@ -3884,11 +4508,24 @@ fold (expr)
         so only do this if -ffast-math.  We can actually always safely
         do it if ARG1 is a power of two, but it's hard to tell if it is
         or not in a portable manner.  */
-      if (TREE_CODE (arg1) == REAL_CST && flag_fast_math
-         && 0 != (tem = const_binop (code, build_real (type, dconst1),
-                                     arg1, 0)))
-       return fold (build (MULT_EXPR, type, arg0, tem));
-
+      if (TREE_CODE (arg1) == REAL_CST)
+       {
+         if (flag_fast_math
+             && 0 != (tem = const_binop (code, build_real (type, dconst1),
+                                         arg1, 0)))
+           return fold (build (MULT_EXPR, type, arg0, tem));
+         /* Find the reciprocal if optimizing and the result is exact. */
+         else if (optimize)
+           {
+             REAL_VALUE_TYPE r;
+             r = TREE_REAL_CST (arg1);
+             if (exact_real_inverse (TYPE_MODE(TREE_TYPE(arg0)), &r))
+                 {
+                   tem = build_real (type, r);
+                   return fold (build (MULT_EXPR, type, arg0, tem));
+                 }
+           }
+       }
       goto binary;
 
     case TRUNC_DIV_EXPR:
@@ -3934,7 +4571,7 @@ fold (expr)
          tree c2 = integer_zero_node;
          tree xarg0 = arg0;
 
-         if (TREE_CODE (xarg0) == SAVE_EXPR)
+         if (TREE_CODE (xarg0) == SAVE_EXPR && SAVE_EXPR_RTL (xarg0) == 0)
            have_save_expr = 1, xarg0 = TREE_OPERAND (xarg0, 0);
 
          STRIP_NOPS (xarg0);
@@ -3952,7 +4589,7 @@ fold (expr)
              xarg0 = TREE_OPERAND (xarg0, 0);
            }
 
-         if (TREE_CODE (xarg0) == SAVE_EXPR)
+         if (TREE_CODE (xarg0) == SAVE_EXPR && SAVE_EXPR_RTL (xarg0) == 0)
            have_save_expr = 1, xarg0 = TREE_OPERAND (xarg0, 0);
 
          STRIP_NOPS (xarg0);
@@ -4049,8 +4686,51 @@ fold (expr)
        return non_lvalue (convert (type, arg0));
       /* Since negative shift count is not well-defined,
         don't try to compute it in the compiler.  */
-      if (tree_int_cst_sgn (arg1) < 0)
+      if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1) < 0)
        return t;
+      /* Rewrite an LROTATE_EXPR by a constant into an
+        RROTATE_EXPR by a new constant.  */
+      if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST)
+       {
+         TREE_SET_CODE (t, RROTATE_EXPR);
+         code = RROTATE_EXPR;
+         TREE_OPERAND (t, 1) = arg1
+           = const_binop
+             (MINUS_EXPR,
+              convert (TREE_TYPE (arg1),
+                       build_int_2 (GET_MODE_BITSIZE (TYPE_MODE (type)), 0)),
+              arg1, 0);
+         if (tree_int_cst_sgn (arg1) < 0)
+           return t;
+       }
+
+      /* If we have a rotate of a bit operation with the rotate count and
+        the second operand of the bit operation both constant,
+        permute the two operations.  */
+      if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
+         && (TREE_CODE (arg0) == BIT_AND_EXPR
+             || TREE_CODE (arg0) == BIT_ANDTC_EXPR
+             || TREE_CODE (arg0) == BIT_IOR_EXPR
+             || TREE_CODE (arg0) == BIT_XOR_EXPR)
+         && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
+       return fold (build (TREE_CODE (arg0), type,
+                           fold (build (code, type,
+                                        TREE_OPERAND (arg0, 0), arg1)),
+                           fold (build (code, type,
+                                        TREE_OPERAND (arg0, 1), arg1))));
+
+      /* Two consecutive rotates adding up to the width of the mode can
+        be ignored.  */
+      if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
+         && TREE_CODE (arg0) == RROTATE_EXPR
+         && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
+         && TREE_INT_CST_HIGH (arg1) == 0
+         && TREE_INT_CST_HIGH (TREE_OPERAND (arg0, 1)) == 0
+         && ((TREE_INT_CST_LOW (arg1)
+              + TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)))
+             == GET_MODE_BITSIZE (TYPE_MODE (type))))
+       return TREE_OPERAND (arg0, 0);
+
       goto binary;
 
     case MIN_EXPR:
@@ -4074,7 +4754,11 @@ fold (expr)
         and its values must be 0 or 1.
         ("true" is a fixed value perhaps depending on the language,
         but we don't handle values other than 1 correctly yet.)  */
-      return invert_truthvalue (arg0);
+      tem = invert_truthvalue (arg0);
+      /* Avoid infinite recursion.  */
+      if (TREE_CODE (tem) == TRUTH_NOT_EXPR)
+       return t;
+      return convert (type, tem);
 
     case TRUTH_ANDIF_EXPR:
       /* Note that the operands of this must be ints
@@ -4093,6 +4777,10 @@ fold (expr)
         must be evaluated.  */
       if (integer_zerop (arg1))
        return omit_one_operand (type, arg1, arg0);
+      /* Likewise for first arg, but note that only the TRUTH_AND_EXPR
+        case will be handled here.  */
+      if (integer_zerop (arg0))
+       return omit_one_operand (type, arg0, arg1);
 
     truth_andor:
       /* We only do these simplifications if we are optimizing.  */
@@ -4139,6 +4827,10 @@ fold (expr)
                                a01));
        }
 
+      /* See if we can build a range comparison.  */
+      if (0 != (tem = fold_range_test (t)))
+       return tem;
+
       /* Check for the possibility of merging component references.  If our
         lhs is another similar operation, try to merge its rhs with our
         rhs.  Then try to merge our lhs and rhs.  */
@@ -4169,6 +4861,10 @@ fold (expr)
         evaluate first arg.  */
       if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
        return omit_one_operand (type, arg1, arg0);
+      /* Likewise for first arg, but note this only occurs here for
+        TRUTH_OR_EXPR.  */
+      if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
+       return omit_one_operand (type, arg0, arg1);
       goto truth_andor;
 
     case TRUTH_XOR_EXPR:
@@ -4207,12 +4903,12 @@ fold (expr)
         and the other one.  */
       {
        tree constop = 0, varop;
-       tree *constoploc;
+       int constopnum = -1;
 
        if (TREE_CONSTANT (arg1))
-         constoploc = &TREE_OPERAND (t, 1), constop = arg1, varop = arg0;
+         constopnum = 1, constop = arg1, varop = arg0;
        if (TREE_CONSTANT (arg0))
-         constoploc = &TREE_OPERAND (t, 0), constop = arg0, varop = arg1;
+         constopnum = 0, constop = arg0, varop = arg1;
 
        if (constop && TREE_CODE (varop) == POSTINCREMENT_EXPR)
          {
@@ -4228,7 +4924,28 @@ fold (expr)
                  = fold (build (PLUS_EXPR, TREE_TYPE (varop),
                                 constop, TREE_OPERAND (varop, 1)));
                TREE_SET_CODE (varop, PREINCREMENT_EXPR);
-               *constoploc = newconst;
+
+               /* If VAROP is a reference to a bitfield, we must mask
+                  the constant by the width of the field.  */
+               if (TREE_CODE (TREE_OPERAND (varop, 0)) == COMPONENT_REF
+                   && DECL_BIT_FIELD(TREE_OPERAND
+                                     (TREE_OPERAND (varop, 0), 1)))
+                 {
+                   int size
+                     = TREE_INT_CST_LOW (DECL_SIZE
+                                         (TREE_OPERAND
+                                          (TREE_OPERAND (varop, 0), 1)));
+
+                   newconst = fold (build (BIT_AND_EXPR,
+                                           TREE_TYPE (varop), newconst,
+                                           convert (TREE_TYPE (varop),
+                                                    build_int_2 (size, 0))));
+                 }
+                                                        
+
+               t = build (code, type, TREE_OPERAND (t, 0),
+                          TREE_OPERAND (t, 1));
+               TREE_OPERAND (t, constopnum) = newconst;
                return t;
              }
          }
@@ -4242,7 +4959,26 @@ fold (expr)
                  = fold (build (MINUS_EXPR, TREE_TYPE (varop),
                                 constop, TREE_OPERAND (varop, 1)));
                TREE_SET_CODE (varop, PREDECREMENT_EXPR);
-               *constoploc = newconst;
+
+               if (TREE_CODE (TREE_OPERAND (varop, 0)) == COMPONENT_REF
+                   && DECL_BIT_FIELD(TREE_OPERAND
+                                     (TREE_OPERAND (varop, 0), 1)))
+                 {
+                   int size
+                     = TREE_INT_CST_LOW (DECL_SIZE
+                                         (TREE_OPERAND
+                                          (TREE_OPERAND (varop, 0), 1)));
+
+                   newconst = fold (build (BIT_AND_EXPR,
+                                           TREE_TYPE (varop), newconst,
+                                           convert (TREE_TYPE (varop),
+                                                    build_int_2 (size, 0))));
+                 }
+                                                        
+
+               t = build (code, type, TREE_OPERAND (t, 0),
+                          TREE_OPERAND (t, 1));
+               TREE_OPERAND (t, constopnum) = newconst;
                return t;
              }
          }
@@ -4257,16 +4993,15 @@ fold (expr)
            {
            case GE_EXPR:
              code = GT_EXPR;
-             TREE_SET_CODE (t, code);
              arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
-             TREE_OPERAND (t, 1) = arg1;
+             t = build (code, type, TREE_OPERAND (t, 0), arg1);
              break;
 
            case LT_EXPR:
              code = LE_EXPR;
-             TREE_SET_CODE (t, code);
              arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
-             TREE_OPERAND (t, 1) = arg1;
+             t = build (code, type, TREE_OPERAND (t, 0), arg1);
+             break;
            }
        }
 
@@ -4375,6 +5110,9 @@ fold (expr)
            case LE_EXPR:
              if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
                {
+                 if (type == integer_type_node)
+                   return integer_one_node;
+
                  t = build_int_2 (1, 0);
                  TREE_TYPE (t) = type;
                  return t;
@@ -4387,9 +5125,12 @@ fold (expr)
              /* For NE, we can only do this simplification if integer.  */
              if (! INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
                break;
-             /* ... fall through ... */
+             /* ... fall through ...  */
            case GT_EXPR:
            case LT_EXPR:
+             if (type == integer_type_node)
+               return integer_zero_node;
+
              t = build_int_2 (0, 0);
              TREE_TYPE (t) = type;
              return t;
@@ -4524,11 +5265,11 @@ fold (expr)
 
       /* If this is a comparison of a field, we may be able to simplify it.  */
       if ((TREE_CODE (arg0) == COMPONENT_REF
-               || TREE_CODE (arg0) == BIT_FIELD_REF)
-              && (code == EQ_EXPR || code == NE_EXPR)
-              /* Handle the constant case even without -O
-                 to make sure the warnings are given.  */
-              && (optimize || TREE_CODE (arg1) == INTEGER_CST))
+          || TREE_CODE (arg0) == BIT_FIELD_REF)
+         && (code == EQ_EXPR || code == NE_EXPR)
+         /* Handle the constant case even without -O
+            to make sure the warnings are given.  */
+         && (optimize || TREE_CODE (arg1) == INTEGER_CST))
        {
          t1 = optimize_bit_field_compare (code, type, arg0, arg1);
          return t1 ? t1 : t;
@@ -4599,6 +5340,7 @@ fold (expr)
                              0);
        }
 
+#if 0 /* This is no longer useful, but breaks some real code.  */
       /* Assume a nonexplicit constant cannot equal an explicit one,
         since such code would be undefined anyway.
         Exception: on sysvr4, using #pragma weak,
@@ -4609,7 +5351,7 @@ fold (expr)
               && TREE_CODE (arg0) == ADDR_EXPR
               && code == EQ_EXPR)
        t1 = build_int_2 (0, 0);
-
+#endif
       /* Two real constants can be compared explicitly.  */
       else if (TREE_CODE (arg0) == REAL_CST && TREE_CODE (arg1) == REAL_CST)
        {
@@ -4650,7 +5392,7 @@ fold (expr)
        return pedantic_non_lvalue
          (TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1)));
       else if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0))
-       return pedantic_non_lvalue (omit_one_operand (type, arg1, arg0));
+       return pedantic_omit_one_operand (type, arg1, arg0);
 
       /* If the second operand is zero, invert the comparison and swap
         the second and third operands.  Likewise if the second operand
@@ -4671,10 +5413,11 @@ fold (expr)
 
          if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
            {
-             arg0 = TREE_OPERAND (t, 0) = tem;
-             TREE_OPERAND (t, 1) = TREE_OPERAND (t, 2);
-             TREE_OPERAND (t, 2) = arg1;
-             arg1 = TREE_OPERAND (t, 1);
+             t = build (code, type, tem,
+                        TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
+             arg0 = tem;
+             arg1 = TREE_OPERAND (t, 2);
+             STRIP_NOPS (arg1);
            }
        }
 
@@ -4693,9 +5436,13 @@ fold (expr)
          tree arg2 = TREE_OPERAND (t, 2);
          enum tree_code comp_code = TREE_CODE (arg0);
 
+         STRIP_NOPS (arg2);
+
          /* If we have A op 0 ? A : -A, this is A, -A, abs (A), or abs (-A),
             depending on the comparison operation.  */
-         if (integer_zerop (TREE_OPERAND (arg0, 1))
+         if ((FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 1)))
+              ? real_zerop (TREE_OPERAND (arg0, 1))
+              : integer_zerop (TREE_OPERAND (arg0, 1)))
              && TREE_CODE (arg2) == NEGATE_EXPR
              && operand_equal_p (TREE_OPERAND (arg2, 0), arg1, 0))
            switch (comp_code)
@@ -4708,12 +5455,16 @@ fold (expr)
              case GE_EXPR:
              case GT_EXPR:
                return pedantic_non_lvalue
-                 (fold (build1 (ABS_EXPR, type, arg1)));
+                 (convert (type, fold (build1 (ABS_EXPR,
+                                               TREE_TYPE (arg1), arg1))));
              case LE_EXPR:
              case LT_EXPR:
                return pedantic_non_lvalue
                  (fold (build1 (NEGATE_EXPR, type,
-                                fold (build1 (ABS_EXPR, type, arg1)))));
+                                convert (type,
+                                         fold (build1 (ABS_EXPR,
+                                                       TREE_TYPE (arg1),
+                                                       arg1))))));
              }
 
          /* If this is A != 0 ? A : 0, this is simply A.  For ==, it is
@@ -4732,21 +5483,29 @@ fold (expr)
 
          if (operand_equal_for_comparison_p (TREE_OPERAND (arg0, 1),
                                              arg2, TREE_OPERAND (arg0, 0)))
-           switch (comp_code)
-             {
-             case EQ_EXPR:
-               return pedantic_non_lvalue (convert (type, arg2));
-             case NE_EXPR:
-               return pedantic_non_lvalue (convert (type, arg1));
-             case LE_EXPR:
-             case LT_EXPR:
-               return pedantic_non_lvalue
-                 (fold (build (MIN_EXPR, type, arg1, arg2)));
-             case GE_EXPR:
-             case GT_EXPR:
-               return pedantic_non_lvalue
-                 (fold (build (MAX_EXPR, type, arg1, arg2)));
-             }
+           {
+             tree comp_op0 = TREE_OPERAND (arg0, 0);
+             tree comp_op1 = TREE_OPERAND (arg0, 1);
+             tree comp_type = TREE_TYPE (comp_op0);
+
+             switch (comp_code)
+               {
+               case EQ_EXPR:
+                 return pedantic_non_lvalue (convert (type, arg2));
+               case NE_EXPR:
+                 return pedantic_non_lvalue (convert (type, arg1));
+               case LE_EXPR:
+               case LT_EXPR:
+                 return pedantic_non_lvalue
+                   (convert (type, (fold (build (MIN_EXPR, comp_type,
+                                                 comp_op0, comp_op1)))));
+               case GE_EXPR:
+               case GT_EXPR:
+                 return pedantic_non_lvalue
+                   (convert (type, fold (build (MAX_EXPR, comp_type,
+                                                comp_op0, comp_op1))));
+               }
+           }
 
          /* If this is A op C1 ? A : C2 with C1 and C2 constant integers,
             we might still be able to simplify this.  For example,
@@ -4761,8 +5520,9 @@ fold (expr)
              {
              case EQ_EXPR:
                /* We can replace A with C1 in this case.  */
-               arg1 = TREE_OPERAND (t, 1)
-                 = convert (type, TREE_OPERAND (arg0, 1));
+               arg1 = convert (type, TREE_OPERAND (arg0, 1));
+               t = build (code, type, TREE_OPERAND (t, 0), arg1,
+                          TREE_OPERAND (t, 2));
                break;
 
              case LT_EXPR:
@@ -4807,6 +5567,29 @@ fold (expr)
              }
        }
 
+      /* If the second operand is simpler than the third, swap them
+        since that produces better jump optimization results.  */
+      if ((TREE_CONSTANT (arg1) || TREE_CODE_CLASS (TREE_CODE (arg1)) == 'd'
+          || TREE_CODE (arg1) == SAVE_EXPR)
+         && ! (TREE_CONSTANT (TREE_OPERAND (t, 2))
+               || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 2))) == 'd'
+               || TREE_CODE (TREE_OPERAND (t, 2)) == SAVE_EXPR))
+       {
+         /* See if this can be inverted.  If it can't, possibly because
+            it was a floating-point inequality comparison, don't do
+            anything.  */
+         tem = invert_truthvalue (arg0);
+
+         if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
+           {
+             t = build (code, type, tem,
+                        TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
+             arg0 = tem;
+             arg1 = TREE_OPERAND (t, 2);
+             STRIP_NOPS (arg1);
+           }
+       }
+
       /* Convert A ? 1 : 0 to simply A.  */
       if (integer_onep (TREE_OPERAND (t, 1))
          && integer_zerop (TREE_OPERAND (t, 2))
@@ -4817,7 +5600,6 @@ fold (expr)
          && type == TREE_TYPE (arg0))
        return pedantic_non_lvalue (arg0);
 
-
       /* Look for expressions of the form A & 2 ? 2 : 0.  The result of this
         operation is simply A & 2.  */
 
@@ -4844,7 +5626,7 @@ fold (expr)
 
     case COMPLEX_EXPR:
       if (wins)
-       return build_complex (arg0, arg1);
+       return build_complex (type, arg0, arg1);
       return t;
 
     case REALPART_EXPR:
@@ -4879,6 +5661,45 @@ fold (expr)
                                          TREE_OPERAND (arg0, 1)))));
       return t;
 
+      /* Pull arithmetic ops out of the CLEANUP_POINT_EXPR where
+         appropriate.  */
+    case CLEANUP_POINT_EXPR:
+      if (! TREE_SIDE_EFFECTS (arg0))
+       return TREE_OPERAND (t, 0);
+
+      {
+       enum tree_code code0 = TREE_CODE (arg0);
+       int kind0 = TREE_CODE_CLASS (code0);
+       tree arg00 = TREE_OPERAND (arg0, 0);
+       tree arg01;
+
+       if (kind0 == '1' || code0 == TRUTH_NOT_EXPR)
+         return fold (build1 (code0, type, 
+                              fold (build1 (CLEANUP_POINT_EXPR,
+                                            TREE_TYPE (arg00), arg00))));
+
+       if (kind0 == '<' || kind0 == '2'
+           || code0 == TRUTH_ANDIF_EXPR || code0 == TRUTH_ORIF_EXPR
+           || code0 == TRUTH_AND_EXPR   || code0 == TRUTH_OR_EXPR
+           || code0 == TRUTH_XOR_EXPR)
+         {
+           arg01 = TREE_OPERAND (arg0, 1);
+
+           if (! TREE_SIDE_EFFECTS (arg00))
+             return fold (build (code0, type, arg00,
+                                 fold (build1 (CLEANUP_POINT_EXPR,
+                                               TREE_TYPE (arg01), arg01))));
+
+           if (! TREE_SIDE_EFFECTS (arg01))
+             return fold (build (code0, type,
+                                 fold (build1 (CLEANUP_POINT_EXPR,
+                                               TREE_TYPE (arg00), arg00)),
+                                 arg01));
+         }
+
+       return t;
+      }
+
     default:
       return t;
     } /* switch (code) */