Annotation of gcc/fold-const.c, revision 1.1.1.8

1.1       root        1: /* Fold a constant sub-tree into a single node for C-compiler
1.1.1.8 ! root        2:    Copyright (C) 1987, 88, 92, 93, 94, 1995 Free Software Foundation, Inc.
1.1       root        3: 
                      4: This file is part of GNU CC.
                      5: 
                      6: GNU CC is free software; you can redistribute it and/or modify
                      7: it under the terms of the GNU General Public License as published by
                      8: the Free Software Foundation; either version 2, or (at your option)
                      9: any later version.
                     10: 
                     11: GNU CC is distributed in the hope that it will be useful,
                     12: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14: GNU General Public License for more details.
                     15: 
                     16: You should have received a copy of the GNU General Public License
                     17: along with GNU CC; see the file COPYING.  If not, write to
1.1.1.8 ! root       18: the Free Software Foundation, 59 Temple Place - Suite 330,
        !            19: Boston, MA 02111-1307, USA.  */
1.1       root       20: 
1.1.1.3   root       21: /*@@ This file should be rewritten to use an arbitrary precision
1.1       root       22:   @@ representation for "struct tree_int_cst" and "struct tree_real_cst".
                     23:   @@ Perhaps the routines could also be used for bc/dc, and made a lib.
                     24:   @@ The routines that translate from the ap rep should
                     25:   @@ warn if precision et. al. is lost.
                     26:   @@ This would also make life easier when this technology is used
                     27:   @@ for cross-compilers.  */
                     28: 
                     29: 
                     30: /* The entry points in this file are fold, size_int and size_binop.
                     31: 
                     32:    fold takes a tree as argument and returns a simplified tree.
                     33: 
                     34:    size_binop takes a tree code for an arithmetic operation
                     35:    and two operands that are trees, and produces a tree for the
                     36:    result, assuming the type comes from `sizetype'.
                     37: 
                     38:    size_int takes an integer value, and creates a tree constant
                     39:    with type from `sizetype'.  */
                     40:    
                     41: #include <stdio.h>
                     42: #include <setjmp.h>
                     43: #include "config.h"
                     44: #include "flags.h"
                     45: #include "tree.h"
                     46: 
1.1.1.3   root       47: /* Handle floating overflow for `const_binop'.  */
                     48: static jmp_buf float_error;
                     49: 
1.1.1.7   root       50: static void encode     PROTO((HOST_WIDE_INT *, HOST_WIDE_INT, HOST_WIDE_INT));
                     51: static void decode     PROTO((HOST_WIDE_INT *, HOST_WIDE_INT *, HOST_WIDE_INT *));
                     52: int div_and_round_double PROTO((enum tree_code, int, HOST_WIDE_INT,
1.1.1.6   root       53:                                       HOST_WIDE_INT, HOST_WIDE_INT,
                     54:                                       HOST_WIDE_INT, HOST_WIDE_INT *,
                     55:                                       HOST_WIDE_INT *, HOST_WIDE_INT *,
                     56:                                       HOST_WIDE_INT *));
                     57: static int split_tree  PROTO((tree, enum tree_code, tree *, tree *, int *));
                     58: static tree const_binop PROTO((enum tree_code, tree, tree, int));
                     59: static tree fold_convert PROTO((tree, tree));
                     60: static enum tree_code invert_tree_comparison PROTO((enum tree_code));
                     61: static enum tree_code swap_tree_comparison PROTO((enum tree_code));
1.1.1.7   root       62: static int truth_value_p PROTO((enum tree_code));
1.1.1.6   root       63: static int operand_equal_for_comparison_p PROTO((tree, tree, tree));
                     64: static int twoval_comparison_p PROTO((tree, tree *, tree *, int *));
                     65: static tree eval_subst PROTO((tree, tree, tree, tree, tree));
                     66: static tree omit_one_operand PROTO((tree, tree, tree));
1.1.1.8 ! root       67: static tree pedantic_omit_one_operand PROTO((tree, tree, tree));
1.1.1.6   root       68: static tree distribute_bit_expr PROTO((enum tree_code, tree, tree, tree));
                     69: static tree make_bit_field_ref PROTO((tree, tree, int, int, int));
                     70: static tree optimize_bit_field_compare PROTO((enum tree_code, tree,
                     71:                                              tree, tree));
                     72: static tree decode_field_reference PROTO((tree, int *, int *,
                     73:                                          enum machine_mode *, int *,
1.1.1.8 ! root       74:                                          int *, tree *, tree *));
1.1.1.6   root       75: static int all_ones_mask_p PROTO((tree, int));
                     76: static int simple_operand_p PROTO((tree));
                     77: static tree range_test PROTO((enum tree_code, tree, enum tree_code,
                     78:                               enum tree_code, tree, tree, tree));
1.1.1.8 ! root       79: static tree unextend   PROTO((tree, int, int, tree));
1.1.1.6   root       80: static tree fold_truthop PROTO((enum tree_code, tree, tree, tree));
1.1.1.7   root       81: static tree strip_compound_expr PROTO((tree, tree));
1.1.1.4   root       82: 
                     83: #ifndef BRANCH_COST
                     84: #define BRANCH_COST 1
                     85: #endif
                     86: 
                     87: /* Yield nonzero if a signed left shift of A by B bits overflows.  */
                     88: #define left_shift_overflows(a, b)  ((a)  !=  ((a) << (b)) >> (b))
                     89: 
                     90: /* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
                     91:    Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.
                     92:    Then this yields nonzero if overflow occurred during the addition.
                     93:    Overflow occurs if A and B have the same sign, but A and SUM differ in sign.
                     94:    Use `^' to test whether signs differ, and `< 0' to isolate the sign.  */
                     95: #define overflow_sum_sign(a, b, sum) ((~((a) ^ (b)) & ((a) ^ (sum))) < 0)
1.1       root       96: 
1.1.1.4   root       97: /* To do constant folding on INTEGER_CST nodes requires two-word arithmetic.
1.1.1.7   root       98:    We do that by representing the two-word integer in 4 words, with only
                     99:    HOST_BITS_PER_WIDE_INT/2 bits stored in each word, as a positive number.  */
                    100: 
                    101: #define LOWPART(x) \
                    102:   ((x) & (((unsigned HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT/2)) - 1))
                    103: #define HIGHPART(x) \
                    104:   ((unsigned HOST_WIDE_INT) (x) >> HOST_BITS_PER_WIDE_INT/2)
                    105: #define BASE ((unsigned HOST_WIDE_INT) 1 << HOST_BITS_PER_WIDE_INT/2)
1.1       root      106: 
1.1.1.7   root      107: /* Unpack a two-word integer into 4 words.
1.1.1.4   root      108:    LOW and HI are the integer, as two `HOST_WIDE_INT' pieces.
1.1.1.7   root      109:    WORDS points to the array of HOST_WIDE_INTs.  */
1.1       root      110: 
                    111: static void
1.1.1.7   root      112: encode (words, low, hi)
                    113:      HOST_WIDE_INT *words;
1.1.1.4   root      114:      HOST_WIDE_INT low, hi;
1.1       root      115: {
1.1.1.7   root      116:   words[0] = LOWPART (low);
                    117:   words[1] = HIGHPART (low);
                    118:   words[2] = LOWPART (hi);
                    119:   words[3] = HIGHPART (hi);
1.1       root      120: }
                    121: 
1.1.1.7   root      122: /* Pack an array of 4 words into a two-word integer.
                    123:    WORDS points to the array of words.
1.1.1.4   root      124:    The integer is stored into *LOW and *HI as two `HOST_WIDE_INT' pieces.  */
1.1       root      125: 
                    126: static void
1.1.1.7   root      127: decode (words, low, hi)
                    128:      HOST_WIDE_INT *words;
1.1.1.4   root      129:      HOST_WIDE_INT *low, *hi;
1.1       root      130: {
1.1.1.7   root      131:   *low = words[0] | words[1] * BASE;
                    132:   *hi = words[2] | words[3] * BASE;
1.1       root      133: }
                    134: 
                    135: /* Make the integer constant T valid for its type
                    136:    by setting to 0 or 1 all the bits in the constant
1.1.1.5   root      137:    that don't belong in the type.
                    138:    Yield 1 if a signed overflow occurs, 0 otherwise.
                    139:    If OVERFLOW is nonzero, a signed overflow has already occurred
1.1.1.7   root      140:    in calculating T, so propagate it.
                    141: 
                    142:    Make the real constant T valid for its type by calling CHECK_FLOAT_VALUE,
                    143:    if it exists.  */
1.1       root      144: 
1.1.1.5   root      145: int
                    146: force_fit_type (t, overflow)
1.1       root      147:      tree t;
1.1.1.5   root      148:      int overflow;
1.1       root      149: {
1.1.1.5   root      150:   HOST_WIDE_INT low, high;
                    151:   register int prec;
                    152: 
1.1.1.7   root      153:   if (TREE_CODE (t) == REAL_CST)
                    154:     {
                    155: #ifdef CHECK_FLOAT_VALUE
                    156:       CHECK_FLOAT_VALUE (TYPE_MODE (TREE_TYPE (t)), TREE_REAL_CST (t),
                    157:                         overflow);
                    158: #endif
                    159:       return overflow;
                    160:     }
                    161: 
                    162:   else if (TREE_CODE (t) != INTEGER_CST)
1.1.1.5   root      163:     return overflow;
                    164: 
                    165:   low = TREE_INT_CST_LOW (t);
                    166:   high = TREE_INT_CST_HIGH (t);
1.1       root      167: 
                    168:   if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
                    169:     prec = POINTER_SIZE;
1.1.1.5   root      170:   else
                    171:     prec = TYPE_PRECISION (TREE_TYPE (t));
1.1       root      172: 
                    173:   /* First clear all bits that are beyond the type's precision.  */
                    174: 
1.1.1.4   root      175:   if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1.1       root      176:     ;
1.1.1.4   root      177:   else if (prec > HOST_BITS_PER_WIDE_INT)
1.1       root      178:     {
                    179:       TREE_INT_CST_HIGH (t)
1.1.1.4   root      180:        &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1.1       root      181:     }
                    182:   else
                    183:     {
                    184:       TREE_INT_CST_HIGH (t) = 0;
1.1.1.4   root      185:       if (prec < HOST_BITS_PER_WIDE_INT)
                    186:        TREE_INT_CST_LOW (t) &= ~((HOST_WIDE_INT) (-1) << prec);
1.1       root      187:     }
                    188: 
1.1.1.5   root      189:   /* Unsigned types do not suffer sign extension or overflow.  */
                    190:   if (TREE_UNSIGNED (TREE_TYPE (t)))
1.1.1.8 ! root      191:     return overflow;
1.1       root      192: 
1.1.1.5   root      193:   /* If the value's sign bit is set, extend the sign.  */
                    194:   if (prec != 2 * HOST_BITS_PER_WIDE_INT
1.1.1.4   root      195:       && (prec > HOST_BITS_PER_WIDE_INT
                    196:          ? (TREE_INT_CST_HIGH (t)
                    197:             & ((HOST_WIDE_INT) 1 << (prec - HOST_BITS_PER_WIDE_INT - 1)))
                    198:          : TREE_INT_CST_LOW (t) & ((HOST_WIDE_INT) 1 << (prec - 1))))
1.1       root      199:     {
                    200:       /* Value is negative:
                    201:         set to 1 all the bits that are outside this type's precision.  */
1.1.1.4   root      202:       if (prec > HOST_BITS_PER_WIDE_INT)
1.1       root      203:        {
                    204:          TREE_INT_CST_HIGH (t)
1.1.1.4   root      205:            |= ((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1.1       root      206:        }
                    207:       else
                    208:        {
                    209:          TREE_INT_CST_HIGH (t) = -1;
1.1.1.4   root      210:          if (prec < HOST_BITS_PER_WIDE_INT)
                    211:            TREE_INT_CST_LOW (t) |= ((HOST_WIDE_INT) (-1) << prec);
1.1       root      212:        }
                    213:     }
1.1.1.5   root      214: 
                    215:   /* Yield nonzero if signed overflow occurred.  */
                    216:   return
                    217:     ((overflow | (low ^ TREE_INT_CST_LOW (t)) | (high ^ TREE_INT_CST_HIGH (t)))
                    218:      != 0);
1.1       root      219: }
                    220: 
1.1.1.4   root      221: /* Add two doubleword integers with doubleword result.
                    222:    Each argument is given as two `HOST_WIDE_INT' pieces.
1.1       root      223:    One argument is L1 and H1; the other, L2 and H2.
1.1.1.7   root      224:    The value is stored as two `HOST_WIDE_INT' pieces in *LV and *HV.  */
1.1       root      225: 
1.1.1.4   root      226: int
1.1       root      227: add_double (l1, h1, l2, h2, lv, hv)
1.1.1.4   root      228:      HOST_WIDE_INT l1, h1, l2, h2;
                    229:      HOST_WIDE_INT *lv, *hv;
1.1       root      230: {
1.1.1.7   root      231:   HOST_WIDE_INT l, h;
1.1       root      232: 
1.1.1.7   root      233:   l = l1 + l2;
                    234:   h = h1 + h2 + ((unsigned HOST_WIDE_INT) l < l1);
1.1       root      235: 
1.1.1.7   root      236:   *lv = l;
                    237:   *hv = h;
                    238:   return overflow_sum_sign (h1, h2, h);
1.1       root      239: }
                    240: 
1.1.1.4   root      241: /* Negate a doubleword integer with doubleword result.
                    242:    Return nonzero if the operation overflows, assuming it's signed.
                    243:    The argument is given as two `HOST_WIDE_INT' pieces in L1 and H1.
1.1.1.7   root      244:    The value is stored as two `HOST_WIDE_INT' pieces in *LV and *HV.  */
1.1       root      245: 
1.1.1.4   root      246: int
1.1       root      247: neg_double (l1, h1, lv, hv)
1.1.1.4   root      248:      HOST_WIDE_INT l1, h1;
                    249:      HOST_WIDE_INT *lv, *hv;
1.1       root      250: {
                    251:   if (l1 == 0)
                    252:     {
                    253:       *lv = 0;
                    254:       *hv = - h1;
1.1.1.5   root      255:       return (*hv & h1) < 0;
1.1       root      256:     }
                    257:   else
                    258:     {
                    259:       *lv = - l1;
                    260:       *hv = ~ h1;
1.1.1.4   root      261:       return 0;
1.1       root      262:     }
                    263: }
                    264: 
1.1.1.4   root      265: /* Multiply two doubleword integers with doubleword result.
                    266:    Return nonzero if the operation overflows, assuming it's signed.
                    267:    Each argument is given as two `HOST_WIDE_INT' pieces.
1.1       root      268:    One argument is L1 and H1; the other, L2 and H2.
1.1.1.7   root      269:    The value is stored as two `HOST_WIDE_INT' pieces in *LV and *HV.  */
1.1       root      270: 
1.1.1.4   root      271: int
1.1       root      272: mul_double (l1, h1, l2, h2, lv, hv)
1.1.1.4   root      273:      HOST_WIDE_INT l1, h1, l2, h2;
                    274:      HOST_WIDE_INT *lv, *hv;
1.1       root      275: {
1.1.1.7   root      276:   HOST_WIDE_INT arg1[4];
                    277:   HOST_WIDE_INT arg2[4];
                    278:   HOST_WIDE_INT prod[4 * 2];
                    279:   register unsigned HOST_WIDE_INT carry;
1.1       root      280:   register int i, j, k;
1.1.1.4   root      281:   HOST_WIDE_INT toplow, tophigh, neglow, neghigh;
1.1       root      282: 
                    283:   encode (arg1, l1, h1);
                    284:   encode (arg2, l2, h2);
                    285: 
1.1.1.7   root      286:   bzero ((char *) prod, sizeof prod);
1.1       root      287: 
1.1.1.7   root      288:   for (i = 0; i < 4; i++)
                    289:     {
                    290:       carry = 0;
                    291:       for (j = 0; j < 4; j++)
                    292:        {
                    293:          k = i + j;
                    294:          /* This product is <= 0xFFFE0001, the sum <= 0xFFFF0000.  */
                    295:          carry += arg1[i] * arg2[j];
                    296:          /* Since prod[p] < 0xFFFF, this sum <= 0xFFFFFFFF.  */
                    297:          carry += prod[k];
                    298:          prod[k] = LOWPART (carry);
                    299:          carry = HIGHPART (carry);
                    300:        }
                    301:       prod[i + 4] = carry;
                    302:     }
1.1       root      303: 
1.1.1.7   root      304:   decode (prod, lv, hv);       /* This ignores prod[4] through prod[4*2-1] */
1.1.1.4   root      305: 
                    306:   /* Check for overflow by calculating the top half of the answer in full;
                    307:      it should agree with the low half's sign bit.  */
1.1.1.7   root      308:   decode (prod+4, &toplow, &tophigh);
1.1.1.4   root      309:   if (h1 < 0)
                    310:     {
                    311:       neg_double (l2, h2, &neglow, &neghigh);
                    312:       add_double (neglow, neghigh, toplow, tophigh, &toplow, &tophigh);
                    313:     }
                    314:   if (h2 < 0)
                    315:     {
                    316:       neg_double (l1, h1, &neglow, &neghigh);
                    317:       add_double (neglow, neghigh, toplow, tophigh, &toplow, &tophigh);
                    318:     }
                    319:   return (*hv < 0 ? ~(toplow & tophigh) : toplow | tophigh) != 0;
1.1       root      320: }
                    321: 
1.1.1.4   root      322: /* Shift the doubleword integer in L1, H1 left by COUNT places
1.1       root      323:    keeping only PREC bits of result.
                    324:    Shift right if COUNT is negative.
                    325:    ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
1.1.1.4   root      326:    Store the value as two `HOST_WIDE_INT' pieces in *LV and *HV.  */
1.1       root      327: 
1.1.1.5   root      328: void
1.1       root      329: lshift_double (l1, h1, count, prec, lv, hv, arith)
1.1.1.6   root      330:      HOST_WIDE_INT l1, h1, count;
                    331:      int prec;
1.1.1.4   root      332:      HOST_WIDE_INT *lv, *hv;
1.1       root      333:      int arith;
                    334: {
                    335:   if (count < 0)
                    336:     {
                    337:       rshift_double (l1, h1, - count, prec, lv, hv, arith);
1.1.1.5   root      338:       return;
1.1       root      339:     }
1.1.1.7   root      340:   
1.1.1.8 ! root      341: #ifdef SHIFT_COUNT_TRUNCATED
        !           342:   if (SHIFT_COUNT_TRUNCATED)
        !           343:     count %= prec;
        !           344: #endif
1.1       root      345: 
1.1.1.7   root      346:   if (count >= HOST_BITS_PER_WIDE_INT)
1.1       root      347:     {
1.1.1.7   root      348:       *hv = (unsigned HOST_WIDE_INT) l1 << count - HOST_BITS_PER_WIDE_INT;
                    349:       *lv = 0;
                    350:     }
                    351:   else
                    352:     {
                    353:       *hv = (((unsigned HOST_WIDE_INT) h1 << count)
                    354:             | ((unsigned HOST_WIDE_INT) l1 >> HOST_BITS_PER_WIDE_INT - count - 1 >> 1));
                    355:       *lv = (unsigned HOST_WIDE_INT) l1 << count;
1.1       root      356:     }
                    357: }
                    358: 
1.1.1.4   root      359: /* Shift the doubleword integer in L1, H1 right by COUNT places
1.1       root      360:    keeping only PREC bits of result.  COUNT must be positive.
                    361:    ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
1.1.1.4   root      362:    Store the value as two `HOST_WIDE_INT' pieces in *LV and *HV.  */
1.1       root      363: 
                    364: void
                    365: rshift_double (l1, h1, count, prec, lv, hv, arith)
1.1.1.6   root      366:      HOST_WIDE_INT l1, h1, count;
                    367:      int prec;
1.1.1.4   root      368:      HOST_WIDE_INT *lv, *hv;
1.1       root      369:      int arith;
                    370: {
1.1.1.7   root      371:   unsigned HOST_WIDE_INT signmask;
                    372:   signmask = (arith
                    373:              ? -((unsigned HOST_WIDE_INT) h1 >> (HOST_BITS_PER_WIDE_INT - 1))
                    374:              : 0);
                    375: 
1.1.1.8 ! root      376: #ifdef SHIFT_COUNT_TRUNCATED
        !           377:   if (SHIFT_COUNT_TRUNCATED)
        !           378:     count %= prec;
        !           379: #endif
1.1.1.7   root      380: 
                    381:   if (count >= HOST_BITS_PER_WIDE_INT)
                    382:     {
                    383:       *hv = signmask;
                    384:       *lv = ((signmask << 2 * HOST_BITS_PER_WIDE_INT - count - 1 << 1)
                    385:             | ((unsigned HOST_WIDE_INT) h1 >> count - HOST_BITS_PER_WIDE_INT));
                    386:     }
                    387:   else
1.1       root      388:     {
1.1.1.7   root      389:       *lv = (((unsigned HOST_WIDE_INT) l1 >> count)
                    390:             | ((unsigned HOST_WIDE_INT) h1 << HOST_BITS_PER_WIDE_INT - count - 1 << 1));
                    391:       *hv = ((signmask << HOST_BITS_PER_WIDE_INT - count)
                    392:             | ((unsigned HOST_WIDE_INT) h1 >> count));
1.1       root      393:     }
                    394: }
                    395: 
1.1.1.7   root      396: /* Rotate the doubleword integer in L1, H1 left by COUNT places
1.1       root      397:    keeping only PREC bits of result.
                    398:    Rotate right if COUNT is negative.
1.1.1.4   root      399:    Store the value as two `HOST_WIDE_INT' pieces in *LV and *HV.  */
1.1       root      400: 
                    401: void
                    402: lrotate_double (l1, h1, count, prec, lv, hv)
1.1.1.6   root      403:      HOST_WIDE_INT l1, h1, count;
                    404:      int prec;
1.1.1.4   root      405:      HOST_WIDE_INT *lv, *hv;
1.1       root      406: {
1.1.1.8 ! root      407:   HOST_WIDE_INT s1l, s1h, s2l, s2h;
1.1       root      408: 
1.1.1.8 ! root      409:   count %= prec;
1.1       root      410:   if (count < 0)
1.1.1.8 ! root      411:     count += prec;
1.1       root      412: 
1.1.1.8 ! root      413:   lshift_double (l1, h1, count, prec, &s1l, &s1h, 0);
        !           414:   rshift_double (l1, h1, prec - count, prec, &s2l, &s2h, 0);
        !           415:   *lv = s1l | s2l;
        !           416:   *hv = s1h | s2h;
1.1       root      417: }
                    418: 
1.1.1.4   root      419: /* Rotate the doubleword integer in L1, H1 left by COUNT places
1.1       root      420:    keeping only PREC bits of result.  COUNT must be positive.
1.1.1.4   root      421:    Store the value as two `HOST_WIDE_INT' pieces in *LV and *HV.  */
1.1       root      422: 
                    423: void
                    424: rrotate_double (l1, h1, count, prec, lv, hv)
1.1.1.6   root      425:      HOST_WIDE_INT l1, h1, count;
                    426:      int prec;
1.1.1.4   root      427:      HOST_WIDE_INT *lv, *hv;
1.1       root      428: {
1.1.1.8 ! root      429:   HOST_WIDE_INT s1l, s1h, s2l, s2h;
1.1       root      430: 
1.1.1.8 ! root      431:   count %= prec;
        !           432:   if (count < 0)
        !           433:     count += prec;
1.1       root      434: 
1.1.1.8 ! root      435:   rshift_double (l1, h1, count, prec, &s1l, &s1h, 0);
        !           436:   lshift_double (l1, h1, prec - count, prec, &s2l, &s2h, 0);
        !           437:   *lv = s1l | s2l;
        !           438:   *hv = s1h | s2h;
1.1       root      439: }
                    440: 
1.1.1.4   root      441: /* Divide doubleword integer LNUM, HNUM by doubleword integer LDEN, HDEN
1.1       root      442:    for a quotient (stored in *LQUO, *HQUO) and remainder (in *LREM, *HREM).
                    443:    CODE is a tree code for a kind of division, one of
                    444:    TRUNC_DIV_EXPR, FLOOR_DIV_EXPR, CEIL_DIV_EXPR, ROUND_DIV_EXPR
                    445:    or EXACT_DIV_EXPR
                    446:    It controls how the quotient is rounded to a integer.
1.1.1.4   root      447:    Return nonzero if the operation overflows.
1.1       root      448:    UNS nonzero says do unsigned division.  */
                    449: 
1.1.1.7   root      450: int
1.1       root      451: div_and_round_double (code, uns,
                    452:                      lnum_orig, hnum_orig, lden_orig, hden_orig,
                    453:                      lquo, hquo, lrem, hrem)
                    454:      enum tree_code code;
                    455:      int uns;
1.1.1.4   root      456:      HOST_WIDE_INT lnum_orig, hnum_orig; /* num == numerator == dividend */
                    457:      HOST_WIDE_INT lden_orig, hden_orig; /* den == denominator == divisor */
                    458:      HOST_WIDE_INT *lquo, *hquo, *lrem, *hrem;
1.1       root      459: {
                    460:   int quo_neg = 0;
1.1.1.7   root      461:   HOST_WIDE_INT num[4 + 1];    /* extra element for scaling.  */
                    462:   HOST_WIDE_INT den[4], quo[4];
                    463:   register int i, j;
                    464:   unsigned HOST_WIDE_INT work;
1.1.1.8 ! root      465:   register unsigned HOST_WIDE_INT carry = 0;
1.1.1.5   root      466:   HOST_WIDE_INT lnum = lnum_orig;
1.1.1.4   root      467:   HOST_WIDE_INT hnum = hnum_orig;
1.1.1.5   root      468:   HOST_WIDE_INT lden = lden_orig;
1.1.1.4   root      469:   HOST_WIDE_INT hden = hden_orig;
                    470:   int overflow = 0;
1.1       root      471: 
                    472:   if ((hden == 0) && (lden == 0))
                    473:     abort ();
                    474: 
                    475:   /* calculate quotient sign and convert operands to unsigned.  */
                    476:   if (!uns) 
                    477:     {
1.1.1.4   root      478:       if (hnum < 0)
1.1       root      479:        {
                    480:          quo_neg = ~ quo_neg;
1.1.1.4   root      481:          /* (minimum integer) / (-1) is the only overflow case.  */
                    482:          if (neg_double (lnum, hnum, &lnum, &hnum) && (lden & hden) == -1)
                    483:            overflow = 1;
1.1       root      484:        }
1.1.1.4   root      485:       if (hden < 0) 
1.1       root      486:        {
                    487:          quo_neg = ~ quo_neg;
1.1.1.4   root      488:          neg_double (lden, hden, &lden, &hden);
1.1       root      489:        }
                    490:     }
                    491: 
                    492:   if (hnum == 0 && hden == 0)
                    493:     {                          /* single precision */
                    494:       *hquo = *hrem = 0;
1.1.1.5   root      495:       /* This unsigned division rounds toward zero.  */
                    496:       *lquo = lnum / (unsigned HOST_WIDE_INT) lden;
1.1       root      497:       goto finish_up;
                    498:     }
                    499: 
                    500:   if (hnum == 0)
                    501:     {                          /* trivial case: dividend < divisor */
                    502:       /* hden != 0 already checked.  */
                    503:       *hquo = *lquo = 0;
                    504:       *hrem = hnum;
                    505:       *lrem = lnum;
                    506:       goto finish_up;
                    507:     }
                    508: 
1.1.1.7   root      509:   bzero ((char *) quo, sizeof quo);
1.1       root      510: 
1.1.1.7   root      511:   bzero ((char *) num, sizeof num);    /* to zero 9th element */
                    512:   bzero ((char *) den, sizeof den);
1.1       root      513: 
                    514:   encode (num, lnum, hnum); 
                    515:   encode (den, lden, hden);
                    516: 
1.1.1.7   root      517:   /* Special code for when the divisor < BASE.  */
                    518:   if (hden == 0 && lden < BASE)
                    519:     {
1.1       root      520:       /* hnum != 0 already checked.  */
1.1.1.7   root      521:       for (i = 4 - 1; i >= 0; i--)
1.1       root      522:        {
1.1.1.7   root      523:          work = num[i] + carry * BASE;
1.1.1.5   root      524:          quo[i] = work / (unsigned HOST_WIDE_INT) lden;
                    525:          carry = work % (unsigned HOST_WIDE_INT) lden;
1.1       root      526:        }
                    527:     }
1.1.1.7   root      528:   else
                    529:     {
                    530:       /* Full double precision division,
                    531:         with thanks to Don Knuth's "Seminumerical Algorithms".  */
1.1.1.8 ! root      532:     int num_hi_sig, den_hi_sig;
        !           533:     unsigned HOST_WIDE_INT quo_est, scale;
1.1       root      534: 
                    535:     /* Find the highest non-zero divisor digit.  */
1.1.1.7   root      536:     for (i = 4 - 1; ; i--)
1.1       root      537:       if (den[i] != 0) {
                    538:        den_hi_sig = i;
                    539:        break;
                    540:       }
                    541: 
                    542:     /* Insure that the first digit of the divisor is at least BASE/2.
                    543:        This is required by the quotient digit estimation algorithm.  */
                    544: 
                    545:     scale = BASE / (den[den_hi_sig] + 1);
                    546:     if (scale > 1) {           /* scale divisor and dividend */
                    547:       carry = 0;
1.1.1.7   root      548:       for (i = 0; i <= 4 - 1; i++) {
1.1       root      549:        work = (num[i] * scale) + carry;
1.1.1.7   root      550:        num[i] = LOWPART (work);
                    551:        carry = HIGHPART (work);
                    552:       } num[4] = carry;
1.1       root      553:       carry = 0;
1.1.1.7   root      554:       for (i = 0; i <= 4 - 1; i++) {
1.1       root      555:        work = (den[i] * scale) + carry;
1.1.1.7   root      556:        den[i] = LOWPART (work);
                    557:        carry = HIGHPART (work);
1.1       root      558:        if (den[i] != 0) den_hi_sig = i;
                    559:       }
                    560:     }
                    561: 
1.1.1.7   root      562:     num_hi_sig = 4;
                    563: 
1.1       root      564:     /* Main loop */
1.1.1.7   root      565:     for (i = num_hi_sig - den_hi_sig - 1; i >= 0; i--) {
1.1.1.3   root      566:       /* guess the next quotient digit, quo_est, by dividing the first
1.1       root      567:         two remaining dividend digits by the high order quotient digit.
                    568:         quo_est is never low and is at most 2 high.  */
1.1.1.7   root      569:       unsigned HOST_WIDE_INT tmp;
1.1       root      570: 
1.1.1.7   root      571:       num_hi_sig = i + den_hi_sig + 1;
                    572:       work = num[num_hi_sig] * BASE + num[num_hi_sig - 1];
                    573:       if (num[num_hi_sig] != den[den_hi_sig])
1.1       root      574:        quo_est = work / den[den_hi_sig];
1.1.1.7   root      575:       else
1.1       root      576:        quo_est = BASE - 1;
                    577: 
                    578:       /* refine quo_est so it's usually correct, and at most one high.   */
1.1.1.7   root      579:       tmp = work - quo_est * den[den_hi_sig];
                    580:       if (tmp < BASE
                    581:          && den[den_hi_sig - 1] * quo_est > (tmp * BASE + num[num_hi_sig - 2]))
1.1       root      582:        quo_est--;
                    583: 
                    584:       /* Try QUO_EST as the quotient digit, by multiplying the
                    585:          divisor by QUO_EST and subtracting from the remaining dividend.
                    586:         Keep in mind that QUO_EST is the I - 1st digit.  */
                    587: 
                    588:       carry = 0;
                    589:       for (j = 0; j <= den_hi_sig; j++)
                    590:        {
1.1.1.7   root      591:          work = quo_est * den[j] + carry;
                    592:          carry = HIGHPART (work);
                    593:          work = num[i + j] - LOWPART (work);
                    594:          num[i + j] = LOWPART (work);
                    595:          carry += HIGHPART (work) != 0;
1.1       root      596:        }
                    597: 
                    598:       /* if quo_est was high by one, then num[i] went negative and
                    599:         we need to correct things.  */
                    600: 
1.1.1.7   root      601:       if (num[num_hi_sig] < carry)
1.1       root      602:        {
                    603:          quo_est--;
                    604:          carry = 0;            /* add divisor back in */
                    605:          for (j = 0; j <= den_hi_sig; j++)
                    606:            {
1.1.1.7   root      607:              work = num[i + j] + den[j] + carry;
                    608:              carry = HIGHPART (work);
                    609:              num[i + j] = LOWPART (work);
1.1       root      610:            }
1.1.1.7   root      611:          num [num_hi_sig] += carry;
1.1       root      612:        }
                    613: 
                    614:       /* store the quotient digit.  */
1.1.1.7   root      615:       quo[i] = quo_est;
1.1       root      616:     }
                    617:   }
                    618: 
                    619:   decode (quo, lquo, hquo);
                    620: 
                    621:  finish_up:
                    622:   /* if result is negative, make it so.  */
                    623:   if (quo_neg)
                    624:     neg_double (*lquo, *hquo, lquo, hquo);
                    625: 
                    626:   /* compute trial remainder:  rem = num - (quo * den)  */
                    627:   mul_double (*lquo, *hquo, lden_orig, hden_orig, lrem, hrem);
                    628:   neg_double (*lrem, *hrem, lrem, hrem);
                    629:   add_double (lnum_orig, hnum_orig, *lrem, *hrem, lrem, hrem);
                    630: 
                    631:   switch (code)
                    632:     {
                    633:     case TRUNC_DIV_EXPR:
                    634:     case TRUNC_MOD_EXPR:       /* round toward zero */
                    635:     case EXACT_DIV_EXPR:       /* for this one, it shouldn't matter */
1.1.1.4   root      636:       return overflow;
1.1       root      637: 
                    638:     case FLOOR_DIV_EXPR:
                    639:     case FLOOR_MOD_EXPR:       /* round toward negative infinity */
                    640:       if (quo_neg && (*lrem != 0 || *hrem != 0))   /* ratio < 0 && rem != 0 */
                    641:        {
                    642:          /* quo = quo - 1;  */
1.1.1.4   root      643:          add_double (*lquo, *hquo, (HOST_WIDE_INT) -1, (HOST_WIDE_INT)  -1,
                    644:                      lquo, hquo);
1.1       root      645:        }
1.1.1.4   root      646:       else return overflow;
1.1       root      647:       break;
                    648: 
                    649:     case CEIL_DIV_EXPR:
                    650:     case CEIL_MOD_EXPR:                /* round toward positive infinity */
                    651:       if (!quo_neg && (*lrem != 0 || *hrem != 0))  /* ratio > 0 && rem != 0 */
                    652:        {
1.1.1.4   root      653:          add_double (*lquo, *hquo, (HOST_WIDE_INT) 1, (HOST_WIDE_INT) 0,
                    654:                      lquo, hquo);
1.1       root      655:        }
1.1.1.4   root      656:       else return overflow;
1.1       root      657:       break;
                    658:     
                    659:     case ROUND_DIV_EXPR:
                    660:     case ROUND_MOD_EXPR:       /* round to closest integer */
                    661:       {
1.1.1.4   root      662:        HOST_WIDE_INT labs_rem = *lrem, habs_rem = *hrem;
                    663:        HOST_WIDE_INT labs_den = lden, habs_den = hden, ltwice, htwice;
1.1       root      664: 
                    665:        /* get absolute values */
                    666:        if (*hrem < 0) neg_double (*lrem, *hrem, &labs_rem, &habs_rem);
                    667:        if (hden < 0) neg_double (lden, hden, &labs_den, &habs_den);
                    668: 
                    669:        /* if (2 * abs (lrem) >= abs (lden)) */
1.1.1.4   root      670:        mul_double ((HOST_WIDE_INT) 2, (HOST_WIDE_INT) 0,
                    671:                    labs_rem, habs_rem, &ltwice, &htwice);
                    672:        if (((unsigned HOST_WIDE_INT) habs_den
                    673:             < (unsigned HOST_WIDE_INT) htwice)
                    674:            || (((unsigned HOST_WIDE_INT) habs_den
                    675:                 == (unsigned HOST_WIDE_INT) htwice)
                    676:                && ((HOST_WIDE_INT unsigned) labs_den
                    677:                    < (unsigned HOST_WIDE_INT) ltwice)))
1.1       root      678:          {
                    679:            if (*hquo < 0)
                    680:              /* quo = quo - 1;  */
1.1.1.4   root      681:              add_double (*lquo, *hquo,
                    682:                          (HOST_WIDE_INT) -1, (HOST_WIDE_INT) -1, lquo, hquo);
1.1       root      683:            else
                    684:              /* quo = quo + 1; */
1.1.1.4   root      685:              add_double (*lquo, *hquo, (HOST_WIDE_INT) 1, (HOST_WIDE_INT) 0,
                    686:                          lquo, hquo);
1.1       root      687:          }
1.1.1.4   root      688:        else return overflow;
1.1       root      689:       }
                    690:       break;
                    691: 
                    692:     default:
                    693:       abort ();
                    694:     }
                    695: 
                    696:   /* compute true remainder:  rem = num - (quo * den)  */
                    697:   mul_double (*lquo, *hquo, lden_orig, hden_orig, lrem, hrem);
                    698:   neg_double (*lrem, *hrem, lrem, hrem);
                    699:   add_double (lnum_orig, hnum_orig, *lrem, *hrem, lrem, hrem);
1.1.1.4   root      700:   return overflow;
1.1       root      701: }
                    702: 
1.1.1.5   root      703: #ifndef REAL_ARITHMETIC
1.1.1.7   root      704: /* Effectively truncate a real value to represent the nearest possible value
                    705:    in a narrower mode.  The result is actually represented in the same data
                    706:    type as the argument, but its value is usually different.
                    707: 
                    708:    A trap may occur during the FP operations and it is the responsibility
                    709:    of the calling function to have a handler established.  */
1.1.1.4   root      710: 
                    711: REAL_VALUE_TYPE
                    712: real_value_truncate (mode, arg)
                    713:      enum machine_mode mode;
                    714:      REAL_VALUE_TYPE arg;
                    715: {
1.1.1.7   root      716:   return REAL_VALUE_TRUNCATE (mode, arg);
1.1.1.4   root      717: }
                    718: 
1.1       root      719: #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
                    720: 
                    721: /* Check for infinity in an IEEE double precision number.  */
                    722: 
                    723: int
                    724: target_isinf (x)
                    725:      REAL_VALUE_TYPE x;
                    726: {
                    727:   /* The IEEE 64-bit double format.  */
                    728:   union {
                    729:     REAL_VALUE_TYPE d;
                    730:     struct {
                    731:       unsigned sign      :  1;
                    732:       unsigned exponent  : 11;
                    733:       unsigned mantissa1 : 20;
                    734:       unsigned mantissa2;
                    735:     } little_endian;
                    736:     struct {
                    737:       unsigned mantissa2;
                    738:       unsigned mantissa1 : 20;
                    739:       unsigned exponent  : 11;
                    740:       unsigned sign      :  1;
                    741:     } big_endian;    
                    742:   } u;
                    743: 
                    744:   u.d = dconstm1;
                    745:   if (u.big_endian.sign == 1)
                    746:     {
                    747:       u.d = x;
                    748:       return (u.big_endian.exponent == 2047
                    749:              && u.big_endian.mantissa1 == 0
                    750:              && u.big_endian.mantissa2 == 0);
                    751:     }
                    752:   else
                    753:     {
                    754:       u.d = x;
                    755:       return (u.little_endian.exponent == 2047
                    756:              && u.little_endian.mantissa1 == 0
                    757:              && u.little_endian.mantissa2 == 0);
                    758:     }
                    759: }
                    760: 
1.1.1.2   root      761: /* Check whether an IEEE double precision number is a NaN.  */
                    762: 
                    763: int
                    764: target_isnan (x)
                    765:      REAL_VALUE_TYPE x;
                    766: {
                    767:   /* The IEEE 64-bit double format.  */
                    768:   union {
                    769:     REAL_VALUE_TYPE d;
                    770:     struct {
                    771:       unsigned sign      :  1;
                    772:       unsigned exponent  : 11;
                    773:       unsigned mantissa1 : 20;
                    774:       unsigned mantissa2;
                    775:     } little_endian;
                    776:     struct {
                    777:       unsigned mantissa2;
                    778:       unsigned mantissa1 : 20;
                    779:       unsigned exponent  : 11;
                    780:       unsigned sign      :  1;
                    781:     } big_endian;    
                    782:   } u;
                    783: 
                    784:   u.d = dconstm1;
                    785:   if (u.big_endian.sign == 1)
                    786:     {
                    787:       u.d = x;
                    788:       return (u.big_endian.exponent == 2047
                    789:              && (u.big_endian.mantissa1 != 0
                    790:                  || u.big_endian.mantissa2 != 0));
                    791:     }
                    792:   else
                    793:     {
                    794:       u.d = x;
                    795:       return (u.little_endian.exponent == 2047
                    796:              && (u.little_endian.mantissa1 != 0
                    797:                  || u.little_endian.mantissa2 != 0));
                    798:     }
                    799: }
                    800: 
1.1.1.3   root      801: /* Check for a negative IEEE double precision number.  */
1.1       root      802: 
                    803: int
1.1.1.3   root      804: target_negative (x)
1.1       root      805:      REAL_VALUE_TYPE x;
                    806: {
1.1.1.3   root      807:   /* The IEEE 64-bit double format.  */
                    808:   union {
                    809:     REAL_VALUE_TYPE d;
                    810:     struct {
                    811:       unsigned sign      :  1;
                    812:       unsigned exponent  : 11;
                    813:       unsigned mantissa1 : 20;
                    814:       unsigned mantissa2;
                    815:     } little_endian;
                    816:     struct {
                    817:       unsigned mantissa2;
                    818:       unsigned mantissa1 : 20;
                    819:       unsigned exponent  : 11;
                    820:       unsigned sign      :  1;
                    821:     } big_endian;    
                    822:   } u;
1.1       root      823: 
1.1.1.3   root      824:   u.d = dconstm1;
                    825:   if (u.big_endian.sign == 1)
                    826:     {
                    827:       u.d = x;
                    828:       return u.big_endian.sign;
                    829:     }
                    830:   else
                    831:     {
                    832:       u.d = x;
                    833:       return u.little_endian.sign;
                    834:     }
1.1       root      835: }
                    836: #else /* Target not IEEE */
                    837: 
                    838: /* Let's assume other float formats don't have infinity.
                    839:    (This can be overridden by redefining REAL_VALUE_ISINF.)  */
                    840: 
                    841: target_isinf (x)
                    842:      REAL_VALUE_TYPE x;
                    843: {
                    844:   return 0;
                    845: }
                    846: 
1.1.1.2   root      847: /* Let's assume other float formats don't have NaNs.
                    848:    (This can be overridden by redefining REAL_VALUE_ISNAN.)  */
                    849: 
                    850: target_isnan (x)
                    851:      REAL_VALUE_TYPE x;
                    852: {
                    853:   return 0;
                    854: }
                    855: 
1.1       root      856: /* Let's assume other float formats don't have minus zero.
1.1.1.3   root      857:    (This can be overridden by redefining REAL_VALUE_NEGATIVE.)  */
1.1       root      858: 
1.1.1.3   root      859: target_negative (x)
1.1       root      860:      REAL_VALUE_TYPE x;
                    861: {
1.1.1.3   root      862:   return x < 0;
1.1       root      863: }
                    864: #endif /* Target not IEEE */
1.1.1.5   root      865: #endif /* no REAL_ARITHMETIC */
1.1       root      866: 
                    867: /* Split a tree IN into a constant and a variable part
                    868:    that could be combined with CODE to make IN.
                    869:    CODE must be a commutative arithmetic operation.
                    870:    Store the constant part into *CONP and the variable in &VARP.
                    871:    Return 1 if this was done; zero means the tree IN did not decompose
                    872:    this way.
                    873: 
                    874:    If CODE is PLUS_EXPR we also split trees that use MINUS_EXPR.
                    875:    Therefore, we must tell the caller whether the variable part
                    876:    was subtracted.  We do this by storing 1 or -1 into *VARSIGNP.
                    877:    The value stored is the coefficient for the variable term.
                    878:    The constant term we return should always be added;
                    879:    we negate it if necessary.  */
                    880: 
                    881: static int
                    882: split_tree (in, code, varp, conp, varsignp)
                    883:      tree in;
                    884:      enum tree_code code;
                    885:      tree *varp, *conp;
                    886:      int *varsignp;
                    887: {
                    888:   register tree outtype = TREE_TYPE (in);
                    889:   *varp = 0;
                    890:   *conp = 0;
                    891: 
                    892:   /* Strip any conversions that don't change the machine mode.  */
                    893:   while ((TREE_CODE (in) == NOP_EXPR
                    894:          || TREE_CODE (in) == CONVERT_EXPR)
                    895:         && (TYPE_MODE (TREE_TYPE (in))
                    896:             == TYPE_MODE (TREE_TYPE (TREE_OPERAND (in, 0)))))
                    897:     in = TREE_OPERAND (in, 0);
                    898: 
                    899:   if (TREE_CODE (in) == code
1.1.1.5   root      900:       || (! FLOAT_TYPE_P (TREE_TYPE (in))
1.1       root      901:          /* We can associate addition and subtraction together
                    902:             (even though the C standard doesn't say so)
                    903:             for integers because the value is not affected.
                    904:             For reals, the value might be affected, so we can't.  */
1.1.1.5   root      905:          && ((code == PLUS_EXPR && TREE_CODE (in) == MINUS_EXPR)
                    906:              || (code == MINUS_EXPR && TREE_CODE (in) == PLUS_EXPR))))
1.1       root      907:     {
                    908:       enum tree_code code = TREE_CODE (TREE_OPERAND (in, 0));
                    909:       if (code == INTEGER_CST)
                    910:        {
                    911:          *conp = TREE_OPERAND (in, 0);
                    912:          *varp = TREE_OPERAND (in, 1);
                    913:          if (TYPE_MODE (TREE_TYPE (*varp)) != TYPE_MODE (outtype)
                    914:              && TREE_TYPE (*varp) != outtype)
                    915:            *varp = convert (outtype, *varp);
                    916:          *varsignp = (TREE_CODE (in) == MINUS_EXPR) ? -1 : 1;
                    917:          return 1;
                    918:        }
                    919:       if (TREE_CONSTANT (TREE_OPERAND (in, 1)))
                    920:        {
                    921:          *conp = TREE_OPERAND (in, 1);
                    922:          *varp = TREE_OPERAND (in, 0);
                    923:          *varsignp = 1;
                    924:          if (TYPE_MODE (TREE_TYPE (*varp)) != TYPE_MODE (outtype)
                    925:              && TREE_TYPE (*varp) != outtype)
                    926:            *varp = convert (outtype, *varp);
                    927:          if (TREE_CODE (in) == MINUS_EXPR)
                    928:            {
                    929:              /* If operation is subtraction and constant is second,
                    930:                 must negate it to get an additive constant.
                    931:                 And this cannot be done unless it is a manifest constant.
                    932:                 It could also be the address of a static variable.
                    933:                 We cannot negate that, so give up.  */
                    934:              if (TREE_CODE (*conp) == INTEGER_CST)
                    935:                /* Subtracting from integer_zero_node loses for long long.  */
                    936:                *conp = fold (build1 (NEGATE_EXPR, TREE_TYPE (*conp), *conp));
                    937:              else
                    938:                return 0;
                    939:            }
                    940:          return 1;
                    941:        }
                    942:       if (TREE_CONSTANT (TREE_OPERAND (in, 0)))
                    943:        {
                    944:          *conp = TREE_OPERAND (in, 0);
                    945:          *varp = TREE_OPERAND (in, 1);
                    946:          if (TYPE_MODE (TREE_TYPE (*varp)) != TYPE_MODE (outtype)
                    947:              && TREE_TYPE (*varp) != outtype)
                    948:            *varp = convert (outtype, *varp);
                    949:          *varsignp = (TREE_CODE (in) == MINUS_EXPR) ? -1 : 1;
                    950:          return 1;
                    951:        }
                    952:     }
                    953:   return 0;
                    954: }
                    955: 
                    956: /* Combine two constants NUM and ARG2 under operation CODE
                    957:    to produce a new constant.
                    958:    We assume ARG1 and ARG2 have the same data type,
1.1.1.5   root      959:    or at least are the same kind of constant and the same machine mode.
                    960: 
                    961:    If NOTRUNC is nonzero, do not truncate the result to fit the data type.  */
1.1       root      962: 
                    963: static tree
1.1.1.5   root      964: const_binop (code, arg1, arg2, notrunc)
1.1       root      965:      enum tree_code code;
                    966:      register tree arg1, arg2;
1.1.1.5   root      967:      int notrunc;
1.1       root      968: {
                    969:   if (TREE_CODE (arg1) == INTEGER_CST)
                    970:     {
1.1.1.4   root      971:       register HOST_WIDE_INT int1l = TREE_INT_CST_LOW (arg1);
                    972:       register HOST_WIDE_INT int1h = TREE_INT_CST_HIGH (arg1);
                    973:       HOST_WIDE_INT int2l = TREE_INT_CST_LOW (arg2);
                    974:       HOST_WIDE_INT int2h = TREE_INT_CST_HIGH (arg2);
                    975:       HOST_WIDE_INT low, hi;
                    976:       HOST_WIDE_INT garbagel, garbageh;
1.1       root      977:       register tree t;
                    978:       int uns = TREE_UNSIGNED (TREE_TYPE (arg1));
1.1.1.5   root      979:       int overflow = 0;
1.1       root      980: 
                    981:       switch (code)
                    982:        {
                    983:        case BIT_IOR_EXPR:
                    984:          t = build_int_2 (int1l | int2l, int1h | int2h);
                    985:          break;
                    986: 
                    987:        case BIT_XOR_EXPR:
                    988:          t = build_int_2 (int1l ^ int2l, int1h ^ int2h);
                    989:          break;
                    990: 
                    991:        case BIT_AND_EXPR:
                    992:          t = build_int_2 (int1l & int2l, int1h & int2h);
                    993:          break;
                    994: 
                    995:        case BIT_ANDTC_EXPR:
                    996:          t = build_int_2 (int1l & ~int2l, int1h & ~int2h);
                    997:          break;
                    998: 
                    999:        case RSHIFT_EXPR:
                   1000:          int2l = - int2l;
                   1001:        case LSHIFT_EXPR:
1.1.1.5   root     1002:          /* It's unclear from the C standard whether shifts can overflow.
                   1003:             The following code ignores overflow; perhaps a C standard
                   1004:             interpretation ruling is needed.  */
                   1005:          lshift_double (int1l, int1h, int2l,
                   1006:                         TYPE_PRECISION (TREE_TYPE (arg1)),
                   1007:                         &low, &hi,
                   1008:                         !uns);
1.1       root     1009:          t = build_int_2 (low, hi);
1.1.1.5   root     1010:          TREE_TYPE (t) = TREE_TYPE (arg1);
                   1011:          if (!notrunc)
                   1012:            force_fit_type (t, 0);
1.1.1.6   root     1013:          TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2);
1.1.1.5   root     1014:          TREE_CONSTANT_OVERFLOW (t)
                   1015:            = TREE_CONSTANT_OVERFLOW (arg1) | TREE_CONSTANT_OVERFLOW (arg2);
                   1016:          return t;
1.1       root     1017: 
                   1018:        case RROTATE_EXPR:
                   1019:          int2l = - int2l;
                   1020:        case LROTATE_EXPR:
                   1021:          lrotate_double (int1l, int1h, int2l,
                   1022:                          TYPE_PRECISION (TREE_TYPE (arg1)),
                   1023:                          &low, &hi);
                   1024:          t = build_int_2 (low, hi);
                   1025:          break;
                   1026: 
                   1027:        case PLUS_EXPR:
                   1028:          if (int1h == 0)
                   1029:            {
                   1030:              int2l += int1l;
1.1.1.4   root     1031:              if ((unsigned HOST_WIDE_INT) int2l < int1l)
                   1032:                {
                   1033:                  hi = int2h++;
1.1.1.5   root     1034:                  overflow = int2h < hi;
1.1.1.4   root     1035:                }
1.1       root     1036:              t = build_int_2 (int2l, int2h);
                   1037:              break;
                   1038:            }
                   1039:          if (int2h == 0)
                   1040:            {
                   1041:              int1l += int2l;
1.1.1.4   root     1042:              if ((unsigned HOST_WIDE_INT) int1l < int2l)
                   1043:                {
                   1044:                  hi = int1h++;
1.1.1.5   root     1045:                  overflow = int1h < hi;
1.1.1.4   root     1046:                }
1.1       root     1047:              t = build_int_2 (int1l, int1h);
                   1048:              break;
                   1049:            }
1.1.1.4   root     1050:          overflow = add_double (int1l, int1h, int2l, int2h, &low, &hi);
1.1       root     1051:          t = build_int_2 (low, hi);
                   1052:          break;
                   1053: 
                   1054:        case MINUS_EXPR:
                   1055:          if (int2h == 0 && int2l == 0)
                   1056:            {
                   1057:              t = build_int_2 (int1l, int1h);
                   1058:              break;
                   1059:            }
1.1.1.4   root     1060:          neg_double (int2l, int2h, &low, &hi);
                   1061:          add_double (int1l, int1h, low, hi, &low, &hi);
                   1062:          overflow = overflow_sum_sign (hi, int2h, int1h);
1.1       root     1063:          t = build_int_2 (low, hi);
                   1064:          break;
                   1065: 
                   1066:        case MULT_EXPR:
1.1.1.4   root     1067:          overflow = mul_double (int1l, int1h, int2l, int2h, &low, &hi);
1.1       root     1068:          t = build_int_2 (low, hi);
                   1069:          break;
                   1070: 
                   1071:        case TRUNC_DIV_EXPR:
                   1072:        case FLOOR_DIV_EXPR: case CEIL_DIV_EXPR:
                   1073:        case EXACT_DIV_EXPR:
                   1074:          /* This is a shortcut for a common special case.
                   1075:             It reduces the number of tree nodes generated
                   1076:             and saves time.  */
                   1077:          if (int2h == 0 && int2l > 0
                   1078:              && TREE_TYPE (arg1) == sizetype
                   1079:              && int1h == 0 && int1l >= 0)
                   1080:            {
                   1081:              if (code == CEIL_DIV_EXPR)
                   1082:                int1l += int2l-1;
                   1083:              return size_int (int1l / int2l);
                   1084:            }
                   1085:        case ROUND_DIV_EXPR: 
                   1086:          if (int2h == 0 && int2l == 1)
                   1087:            {
                   1088:              t = build_int_2 (int1l, int1h);
                   1089:              break;
                   1090:            }
                   1091:          if (int1l == int2l && int1h == int2h)
                   1092:            {
                   1093:              if ((int1l | int1h) == 0)
                   1094:                abort ();
                   1095:              t = build_int_2 (1, 0);
                   1096:              break;
                   1097:            }
1.1.1.4   root     1098:          overflow = div_and_round_double (code, uns,
                   1099:                                           int1l, int1h, int2l, int2h,
                   1100:                                           &low, &hi, &garbagel, &garbageh);
1.1       root     1101:          t = build_int_2 (low, hi);
                   1102:          break;
                   1103: 
                   1104:        case TRUNC_MOD_EXPR: case ROUND_MOD_EXPR: 
                   1105:        case FLOOR_MOD_EXPR: case CEIL_MOD_EXPR:
1.1.1.4   root     1106:          overflow = div_and_round_double (code, uns,
                   1107:                                           int1l, int1h, int2l, int2h,
                   1108:                                           &garbagel, &garbageh, &low, &hi);
1.1       root     1109:          t = build_int_2 (low, hi);
                   1110:          break;
                   1111: 
                   1112:        case MIN_EXPR:
                   1113:        case MAX_EXPR:
                   1114:          if (uns)
                   1115:            {
1.1.1.4   root     1116:              low = (((unsigned HOST_WIDE_INT) int1h
                   1117:                      < (unsigned HOST_WIDE_INT) int2h)
                   1118:                     || (((unsigned HOST_WIDE_INT) int1h
                   1119:                          == (unsigned HOST_WIDE_INT) int2h)
                   1120:                         && ((unsigned HOST_WIDE_INT) int1l
                   1121:                             < (unsigned HOST_WIDE_INT) int2l)));
1.1       root     1122:            }
                   1123:          else
                   1124:            {
                   1125:              low = ((int1h < int2h)
                   1126:                     || ((int1h == int2h)
1.1.1.4   root     1127:                         && ((unsigned HOST_WIDE_INT) int1l
                   1128:                             < (unsigned HOST_WIDE_INT) int2l)));
1.1       root     1129:            }
                   1130:          if (low == (code == MIN_EXPR))
                   1131:            t = build_int_2 (int1l, int1h);
                   1132:          else
                   1133:            t = build_int_2 (int2l, int2h);
                   1134:          break;
                   1135: 
                   1136:        default:
                   1137:          abort ();
                   1138:        }
                   1139:     got_it:
                   1140:       TREE_TYPE (t) = TREE_TYPE (arg1);
1.1.1.6   root     1141:       TREE_OVERFLOW (t)
1.1.1.8 ! root     1142:        = ((notrunc ? !uns && overflow : force_fit_type (t, overflow && !uns))
1.1.1.6   root     1143:           | TREE_OVERFLOW (arg1)
                   1144:           | TREE_OVERFLOW (arg2));
                   1145:       TREE_CONSTANT_OVERFLOW (t) = (TREE_OVERFLOW (t)
                   1146:                                    | TREE_CONSTANT_OVERFLOW (arg1)
                   1147:                                    | TREE_CONSTANT_OVERFLOW (arg2));
1.1       root     1148:       return t;
                   1149:     }
                   1150: #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
                   1151:   if (TREE_CODE (arg1) == REAL_CST)
                   1152:     {
1.1.1.5   root     1153:       REAL_VALUE_TYPE d1;
                   1154:       REAL_VALUE_TYPE d2;
1.1.1.7   root     1155:       int overflow = 0;
1.1.1.5   root     1156:       REAL_VALUE_TYPE value;
1.1.1.3   root     1157:       tree t;
1.1       root     1158: 
                   1159:       d1 = TREE_REAL_CST (arg1);
                   1160:       d2 = TREE_REAL_CST (arg2);
1.1.1.7   root     1161: 
                   1162:       /* If either operand is a NaN, just return it.  Otherwise, set up
                   1163:         for floating-point trap; we return an overflow.  */
                   1164:       if (REAL_VALUE_ISNAN (d1))
                   1165:        return arg1;
                   1166:       else if (REAL_VALUE_ISNAN (d2))
                   1167:        return arg2;
                   1168:       else if (setjmp (float_error))
                   1169:        {
                   1170:          t = copy_node (arg1);
                   1171:          overflow = 1;
                   1172:          goto got_float;
1.1       root     1173:        }
1.1.1.7   root     1174: 
1.1.1.3   root     1175:       set_float_handler (float_error);
1.1       root     1176: 
                   1177: #ifdef REAL_ARITHMETIC
                   1178:       REAL_ARITHMETIC (value, code, d1, d2);
                   1179: #else
                   1180:       switch (code)
                   1181:        {
                   1182:        case PLUS_EXPR:
                   1183:          value = d1 + d2;
                   1184:          break;
                   1185: 
                   1186:        case MINUS_EXPR:
                   1187:          value = d1 - d2;
                   1188:          break;
                   1189: 
                   1190:        case MULT_EXPR:
                   1191:          value = d1 * d2;
                   1192:          break;
                   1193: 
                   1194:        case RDIV_EXPR:
                   1195: #ifndef REAL_INFINITY
                   1196:          if (d2 == 0)
                   1197:            abort ();
                   1198: #endif
                   1199: 
                   1200:          value = d1 / d2;
                   1201:          break;
                   1202: 
                   1203:        case MIN_EXPR:
                   1204:          value = MIN (d1, d2);
                   1205:          break;
                   1206: 
                   1207:        case MAX_EXPR:
                   1208:          value = MAX (d1, d2);
                   1209:          break;
                   1210: 
                   1211:        default:
                   1212:          abort ();
                   1213:        }
                   1214: #endif /* no REAL_ARITHMETIC */
1.1.1.3   root     1215:       t = build_real (TREE_TYPE (arg1),
1.1.1.4   root     1216:                      real_value_truncate (TYPE_MODE (TREE_TYPE (arg1)), value));
1.1.1.7   root     1217:     got_float:
1.1.1.4   root     1218:       set_float_handler (NULL_PTR);
1.1.1.7   root     1219: 
                   1220:       TREE_OVERFLOW (t)
                   1221:        = (force_fit_type (t, overflow)
                   1222:           | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
                   1223:       TREE_CONSTANT_OVERFLOW (t)
                   1224:        = TREE_OVERFLOW (t)
                   1225:          | TREE_CONSTANT_OVERFLOW (arg1)
                   1226:          | TREE_CONSTANT_OVERFLOW (arg2);
1.1.1.3   root     1227:       return t;
1.1       root     1228:     }
                   1229: #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
                   1230:   if (TREE_CODE (arg1) == COMPLEX_CST)
                   1231:     {
                   1232:       register tree r1 = TREE_REALPART (arg1);
                   1233:       register tree i1 = TREE_IMAGPART (arg1);
                   1234:       register tree r2 = TREE_REALPART (arg2);
                   1235:       register tree i2 = TREE_IMAGPART (arg2);
                   1236:       register tree t;
                   1237: 
                   1238:       switch (code)
                   1239:        {
                   1240:        case PLUS_EXPR:
1.1.1.5   root     1241:          t = build_complex (const_binop (PLUS_EXPR, r1, r2, notrunc),
                   1242:                             const_binop (PLUS_EXPR, i1, i2, notrunc));
1.1       root     1243:          break;
                   1244: 
                   1245:        case MINUS_EXPR:
1.1.1.5   root     1246:          t = build_complex (const_binop (MINUS_EXPR, r1, r2, notrunc),
                   1247:                             const_binop (MINUS_EXPR, i1, i2, notrunc));
1.1       root     1248:          break;
                   1249: 
                   1250:        case MULT_EXPR:
                   1251:          t = build_complex (const_binop (MINUS_EXPR,
1.1.1.5   root     1252:                                          const_binop (MULT_EXPR,
                   1253:                                                       r1, r2, notrunc),
                   1254:                                          const_binop (MULT_EXPR,
                   1255:                                                       i1, i2, notrunc),
                   1256:                                          notrunc),
1.1       root     1257:                             const_binop (PLUS_EXPR,
1.1.1.5   root     1258:                                          const_binop (MULT_EXPR,
                   1259:                                                       r1, i2, notrunc),
                   1260:                                          const_binop (MULT_EXPR,
                   1261:                                                       i1, r2, notrunc),
                   1262:                                          notrunc));
1.1       root     1263:          break;
                   1264: 
                   1265:        case RDIV_EXPR:
                   1266:          {
                   1267:            register tree magsquared
                   1268:              = const_binop (PLUS_EXPR,
1.1.1.5   root     1269:                             const_binop (MULT_EXPR, r2, r2, notrunc),
                   1270:                             const_binop (MULT_EXPR, i2, i2, notrunc),
                   1271:                             notrunc);
1.1.1.7   root     1272: 
                   1273:            t = build_complex
                   1274:              (const_binop (INTEGRAL_TYPE_P (TREE_TYPE (r1))
                   1275:                            ? TRUNC_DIV_EXPR : RDIV_EXPR,
                   1276:                            const_binop (PLUS_EXPR,
                   1277:                                         const_binop (MULT_EXPR, r1, r2,
                   1278:                                                      notrunc),
                   1279:                                         const_binop (MULT_EXPR, i1, i2,
                   1280:                                                      notrunc),
                   1281:                                         notrunc),
                   1282:                            magsquared, notrunc),
                   1283:               const_binop (INTEGRAL_TYPE_P (TREE_TYPE (r1))
                   1284:                            ? TRUNC_DIV_EXPR : RDIV_EXPR,
                   1285:                            const_binop (MINUS_EXPR,
                   1286:                                         const_binop (MULT_EXPR, i1, r2,
                   1287:                                                      notrunc),
                   1288:                                         const_binop (MULT_EXPR, r1, i2,
                   1289:                                                      notrunc),
                   1290:                                         notrunc),
                   1291:                            magsquared, notrunc));
1.1       root     1292:          }
                   1293:          break;
                   1294: 
                   1295:        default:
                   1296:          abort ();
                   1297:        }
                   1298:       TREE_TYPE (t) = TREE_TYPE (arg1);
                   1299:       return t;
                   1300:     }
                   1301:   return 0;
                   1302: }
                   1303: 
                   1304: /* Return an INTEGER_CST with value V and type from `sizetype'.  */
                   1305: 
                   1306: tree
                   1307: size_int (number)
1.1.1.8 ! root     1308:      unsigned HOST_WIDE_INT number;
1.1       root     1309: {
                   1310:   register tree t;
                   1311:   /* Type-size nodes already made for small sizes.  */
1.1.1.4   root     1312:   static tree size_table[2*HOST_BITS_PER_WIDE_INT + 1];
1.1       root     1313: 
1.1.1.5   root     1314:   if (number < 2*HOST_BITS_PER_WIDE_INT + 1
1.1.1.4   root     1315:       && size_table[number] != 0)
1.1       root     1316:     return size_table[number];
1.1.1.5   root     1317:   if (number < 2*HOST_BITS_PER_WIDE_INT + 1)
1.1       root     1318:     {
                   1319:       push_obstacks_nochange ();
                   1320:       /* Make this a permanent node.  */
1.1.1.3   root     1321:       end_temporary_allocation ();
1.1       root     1322:       t = build_int_2 (number, 0);
                   1323:       TREE_TYPE (t) = sizetype;
                   1324:       size_table[number] = t;
                   1325:       pop_obstacks ();
                   1326:     }
                   1327:   else
                   1328:     {
                   1329:       t = build_int_2 (number, 0);
                   1330:       TREE_TYPE (t) = sizetype;
                   1331:     }
                   1332:   return t;
                   1333: }
                   1334: 
                   1335: /* Combine operands OP1 and OP2 with arithmetic operation CODE.
                   1336:    CODE is a tree code.  Data type is taken from `sizetype',
                   1337:    If the operands are constant, so is the result.  */
                   1338: 
                   1339: tree
                   1340: size_binop (code, arg0, arg1)
                   1341:      enum tree_code code;
                   1342:      tree arg0, arg1;
                   1343: {
                   1344:   /* Handle the special case of two integer constants faster.  */
                   1345:   if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
                   1346:     {
                   1347:       /* And some specific cases even faster than that.  */
                   1348:       if (code == PLUS_EXPR
                   1349:          && TREE_INT_CST_LOW (arg0) == 0
                   1350:          && TREE_INT_CST_HIGH (arg0) == 0)
                   1351:        return arg1;
                   1352:       if (code == MINUS_EXPR
                   1353:          && TREE_INT_CST_LOW (arg1) == 0
                   1354:          && TREE_INT_CST_HIGH (arg1) == 0)
                   1355:        return arg0;
                   1356:       if (code == MULT_EXPR
                   1357:          && TREE_INT_CST_LOW (arg0) == 1
                   1358:          && TREE_INT_CST_HIGH (arg0) == 0)
                   1359:        return arg1;
                   1360:       /* Handle general case of two integer constants.  */
1.1.1.8 ! root     1361:       return const_binop (code, arg0, arg1, 0);
1.1       root     1362:     }
                   1363: 
                   1364:   if (arg0 == error_mark_node || arg1 == error_mark_node)
                   1365:     return error_mark_node;
                   1366: 
                   1367:   return fold (build (code, sizetype, arg0, arg1));
                   1368: }
                   1369: 
                   1370: /* Given T, a tree representing type conversion of ARG1, a constant,
                   1371:    return a constant tree representing the result of conversion.  */
                   1372: 
                   1373: static tree
                   1374: fold_convert (t, arg1)
                   1375:      register tree t;
                   1376:      register tree arg1;
                   1377: {
                   1378:   register tree type = TREE_TYPE (t);
1.1.1.7   root     1379:   int overflow = 0;
1.1       root     1380: 
1.1.1.5   root     1381:   if (TREE_CODE (type) == POINTER_TYPE || INTEGRAL_TYPE_P (type))
1.1       root     1382:     {
                   1383:       if (TREE_CODE (arg1) == INTEGER_CST)
                   1384:        {
1.1.1.7   root     1385:          /* If we would build a constant wider than GCC supports,
                   1386:             leave the conversion unfolded.  */
                   1387:          if (TYPE_PRECISION (type) > 2 * HOST_BITS_PER_WIDE_INT)
                   1388:            return t;
                   1389: 
1.1       root     1390:          /* Given an integer constant, make new constant with new type,
                   1391:             appropriately sign-extended or truncated.  */
                   1392:          t = build_int_2 (TREE_INT_CST_LOW (arg1),
                   1393:                           TREE_INT_CST_HIGH (arg1));
                   1394:          TREE_TYPE (t) = type;
1.1.1.5   root     1395:          /* Indicate an overflow if (1) ARG1 already overflowed,
1.1.1.6   root     1396:             or (2) force_fit_type indicates an overflow.
                   1397:             Tell force_fit_type that an overflow has already occurred
                   1398:             if ARG1 is a too-large unsigned value and T is signed.  */
                   1399:          TREE_OVERFLOW (t)
                   1400:            = (TREE_OVERFLOW (arg1)
                   1401:               | force_fit_type (t,
                   1402:                                 (TREE_INT_CST_HIGH (arg1) < 0
                   1403:                                  & (TREE_UNSIGNED (type)
                   1404:                                     < TREE_UNSIGNED (TREE_TYPE (arg1))))));
                   1405:          TREE_CONSTANT_OVERFLOW (t)
                   1406:            = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
1.1       root     1407:        }
                   1408: #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
                   1409:       else if (TREE_CODE (arg1) == REAL_CST)
                   1410:        {
1.1.1.7   root     1411:          /* Don't initialize these, use assignments.
                   1412:             Initialized local aggregates don't work on old compilers.  */
                   1413:          REAL_VALUE_TYPE x;
                   1414:          REAL_VALUE_TYPE l;
                   1415:          REAL_VALUE_TYPE u;
1.1.1.5   root     1416: 
                   1417:          x = TREE_REAL_CST (arg1);
1.1.1.7   root     1418:          l = real_value_from_int_cst (TYPE_MIN_VALUE (type));
1.1.1.5   root     1419:          u = real_value_from_int_cst (TYPE_MAX_VALUE (type));
1.1.1.4   root     1420:          /* See if X will be in range after truncation towards 0.
                   1421:             To compensate for truncation, move the bounds away from 0,
                   1422:             but reject if X exactly equals the adjusted bounds.  */
                   1423: #ifdef REAL_ARITHMETIC
                   1424:          REAL_ARITHMETIC (l, MINUS_EXPR, l, dconst1);
                   1425:          REAL_ARITHMETIC (u, PLUS_EXPR, u, dconst1);
                   1426: #else
                   1427:          l--;
                   1428:          u++;
                   1429: #endif
1.1.1.7   root     1430:          /* If X is a NaN, use zero instead and show we have an overflow.
                   1431:             Otherwise, range check.  */
                   1432:          if (REAL_VALUE_ISNAN (x))
                   1433:            overflow = 1, x = dconst0;
                   1434:          else if (! (REAL_VALUES_LESS (l, x) && REAL_VALUES_LESS (x, u)))
                   1435:            overflow = 1;
                   1436: 
1.1       root     1437: #ifndef REAL_ARITHMETIC
                   1438:          {
1.1.1.4   root     1439:            HOST_WIDE_INT low, high;
                   1440:            HOST_WIDE_INT half_word
                   1441:              = (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2);
1.1       root     1442: 
1.1.1.7   root     1443:            if (x < 0)
                   1444:              x = -x;
                   1445: 
                   1446:            high = (HOST_WIDE_INT) (x / half_word / half_word);
                   1447:            x -= (REAL_VALUE_TYPE) high * half_word * half_word;
                   1448:            if (x >= (REAL_VALUE_TYPE) half_word * half_word / 2)
1.1.1.4   root     1449:              {
1.1.1.7   root     1450:                low = x - (REAL_VALUE_TYPE) half_word * half_word / 2;
1.1.1.5   root     1451:                low |= (HOST_WIDE_INT) -1 << (HOST_BITS_PER_WIDE_INT - 1);
1.1.1.4   root     1452:              }
                   1453:            else
1.1.1.7   root     1454:              low = (HOST_WIDE_INT) x;
1.1       root     1455:            if (TREE_REAL_CST (arg1) < 0)
                   1456:              neg_double (low, high, &low, &high);
                   1457:            t = build_int_2 (low, high);
                   1458:          }
                   1459: #else
                   1460:          {
1.1.1.4   root     1461:            HOST_WIDE_INT low, high;
1.1.1.7   root     1462:            REAL_VALUE_TO_INT (&low, &high, x);
1.1       root     1463:            t = build_int_2 (low, high);
                   1464:          }
                   1465: #endif
                   1466:          TREE_TYPE (t) = type;
1.1.1.7   root     1467:          TREE_OVERFLOW (t)
                   1468:            = TREE_OVERFLOW (arg1) | force_fit_type (t, overflow);
                   1469:          TREE_CONSTANT_OVERFLOW (t)
                   1470:            = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
1.1       root     1471:        }
                   1472: #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
                   1473:       TREE_TYPE (t) = type;
                   1474:     }
                   1475:   else if (TREE_CODE (type) == REAL_TYPE)
                   1476:     {
                   1477: #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
                   1478:       if (TREE_CODE (arg1) == INTEGER_CST)
                   1479:        return build_real_from_int_cst (type, arg1);
                   1480: #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
                   1481:       if (TREE_CODE (arg1) == REAL_CST)
1.1.1.3   root     1482:        {
1.1.1.7   root     1483:          if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)))
                   1484:            return arg1;
                   1485:          else if (setjmp (float_error))
                   1486:            {
                   1487:              overflow = 1;
                   1488:              t = copy_node (arg1);
                   1489:              goto got_it;
1.1.1.3   root     1490:            }
                   1491:          set_float_handler (float_error);
                   1492: 
1.1.1.4   root     1493:          t = build_real (type, real_value_truncate (TYPE_MODE (type),
1.1.1.3   root     1494:                                                     TREE_REAL_CST (arg1)));
1.1.1.4   root     1495:          set_float_handler (NULL_PTR);
1.1.1.7   root     1496: 
                   1497:        got_it:
                   1498:          TREE_OVERFLOW (t)
                   1499:            = TREE_OVERFLOW (arg1) | force_fit_type (t, overflow);
                   1500:          TREE_CONSTANT_OVERFLOW (t)
                   1501:            = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
1.1.1.3   root     1502:          return t;
                   1503:        }
1.1       root     1504:     }
                   1505:   TREE_CONSTANT (t) = 1;
                   1506:   return t;
                   1507: }
                   1508: 
1.1.1.5   root     1509: /* Return an expr equal to X but certainly not valid as an lvalue.
                   1510:    Also make sure it is not valid as an null pointer constant.  */
1.1       root     1511: 
                   1512: tree
                   1513: non_lvalue (x)
                   1514:      tree x;
                   1515: {
                   1516:   tree result;
                   1517: 
                   1518:   /* These things are certainly not lvalues.  */
                   1519:   if (TREE_CODE (x) == NON_LVALUE_EXPR
                   1520:       || TREE_CODE (x) == INTEGER_CST
                   1521:       || TREE_CODE (x) == REAL_CST
                   1522:       || TREE_CODE (x) == STRING_CST
                   1523:       || TREE_CODE (x) == ADDR_EXPR)
1.1.1.5   root     1524:     {
                   1525:       if (TREE_CODE (x) == INTEGER_CST && integer_zerop (x))
                   1526:        {
                   1527:          /* Use NOP_EXPR instead of NON_LVALUE_EXPR
                   1528:             so convert_for_assignment won't strip it.
                   1529:             This is so this 0 won't be treated as a null pointer constant.  */
                   1530:          result = build1 (NOP_EXPR, TREE_TYPE (x), x);
                   1531:          TREE_CONSTANT (result) = TREE_CONSTANT (x);
                   1532:          return result;
                   1533:        }
                   1534:       return x;
                   1535:     }
1.1       root     1536: 
                   1537:   result = build1 (NON_LVALUE_EXPR, TREE_TYPE (x), x);
                   1538:   TREE_CONSTANT (result) = TREE_CONSTANT (x);
                   1539:   return result;
                   1540: }
1.1.1.6   root     1541: 
1.1.1.8 ! root     1542: /* Nonzero means lvalues are limited to those valid in pedantic ANSI C.
        !          1543:    Zero means allow extended lvalues.  */
        !          1544: 
        !          1545: int pedantic_lvalues;
        !          1546: 
1.1.1.6   root     1547: /* When pedantic, return an expr equal to X but certainly not valid as a
                   1548:    pedantic lvalue.  Otherwise, return X.  */
                   1549: 
                   1550: tree
                   1551: pedantic_non_lvalue (x)
                   1552:      tree x;
                   1553: {
1.1.1.8 ! root     1554:   if (pedantic_lvalues)
1.1.1.6   root     1555:     return non_lvalue (x);
                   1556:   else
                   1557:     return x;
                   1558: }
1.1.1.3   root     1559: 
                   1560: /* Given a tree comparison code, return the code that is the logical inverse
                   1561:    of the given code.  It is not safe to do this for floating-point
                   1562:    comparisons, except for NE_EXPR and EQ_EXPR.  */
                   1563: 
                   1564: static enum tree_code
                   1565: invert_tree_comparison (code)
                   1566:      enum tree_code code;
                   1567: {
                   1568:   switch (code)
                   1569:     {
                   1570:     case EQ_EXPR:
                   1571:       return NE_EXPR;
                   1572:     case NE_EXPR:
                   1573:       return EQ_EXPR;
                   1574:     case GT_EXPR:
                   1575:       return LE_EXPR;
                   1576:     case GE_EXPR:
                   1577:       return LT_EXPR;
                   1578:     case LT_EXPR:
                   1579:       return GE_EXPR;
                   1580:     case LE_EXPR:
                   1581:       return GT_EXPR;
                   1582:     default:
                   1583:       abort ();
                   1584:     }
                   1585: }
                   1586: 
                   1587: /* Similar, but return the comparison that results if the operands are
                   1588:    swapped.  This is safe for floating-point.  */
1.1       root     1589: 
1.1.1.3   root     1590: static enum tree_code
                   1591: swap_tree_comparison (code)
                   1592:      enum tree_code code;
                   1593: {
                   1594:   switch (code)
                   1595:     {
                   1596:     case EQ_EXPR:
                   1597:     case NE_EXPR:
                   1598:       return code;
                   1599:     case GT_EXPR:
                   1600:       return LT_EXPR;
                   1601:     case GE_EXPR:
                   1602:       return LE_EXPR;
                   1603:     case LT_EXPR:
                   1604:       return GT_EXPR;
                   1605:     case LE_EXPR:
                   1606:       return GE_EXPR;
                   1607:     default:
                   1608:       abort ();
                   1609:     }
                   1610: }
1.1.1.7   root     1611: 
                   1612: /* Return nonzero if CODE is a tree code that represents a truth value.  */
                   1613: 
                   1614: static int
                   1615: truth_value_p (code)
                   1616:      enum tree_code code;
                   1617: {
                   1618:   return (TREE_CODE_CLASS (code) == '<'
                   1619:          || code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
                   1620:          || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
                   1621:          || code == TRUTH_XOR_EXPR || code == TRUTH_NOT_EXPR);
                   1622: }
1.1.1.3   root     1623: 
1.1.1.4   root     1624: /* Return nonzero if two operands are necessarily equal.
                   1625:    If ONLY_CONST is non-zero, only return non-zero for constants.
                   1626:    This function tests whether the operands are indistinguishable;
                   1627:    it does not test whether they are equal using C's == operation.
                   1628:    The distinction is important for IEEE floating point, because
                   1629:    (1) -0.0 and 0.0 are distinguishable, but -0.0==0.0, and
                   1630:    (2) two NaNs may be indistinguishable, but NaN!=NaN.  */
1.1       root     1631: 
                   1632: int
                   1633: operand_equal_p (arg0, arg1, only_const)
                   1634:      tree arg0, arg1;
                   1635:      int only_const;
                   1636: {
                   1637:   /* If both types don't have the same signedness, then we can't consider
                   1638:      them equal.  We must check this before the STRIP_NOPS calls
                   1639:      because they may change the signedness of the arguments.  */
                   1640:   if (TREE_UNSIGNED (TREE_TYPE (arg0)) != TREE_UNSIGNED (TREE_TYPE (arg1)))
                   1641:     return 0;
                   1642: 
                   1643:   STRIP_NOPS (arg0);
                   1644:   STRIP_NOPS (arg1);
                   1645: 
                   1646:   /* If ARG0 and ARG1 are the same SAVE_EXPR, they are necessarily equal.
                   1647:      We don't care about side effects in that case because the SAVE_EXPR
                   1648:      takes care of that for us.  */
                   1649:   if (TREE_CODE (arg0) == SAVE_EXPR && arg0 == arg1)
                   1650:     return ! only_const;
                   1651: 
                   1652:   if (TREE_SIDE_EFFECTS (arg0) || TREE_SIDE_EFFECTS (arg1))
                   1653:     return 0;
                   1654: 
                   1655:   if (TREE_CODE (arg0) == TREE_CODE (arg1)
                   1656:       && TREE_CODE (arg0) == ADDR_EXPR
                   1657:       && TREE_OPERAND (arg0, 0) == TREE_OPERAND (arg1, 0))
                   1658:     return 1;
                   1659: 
                   1660:   if (TREE_CODE (arg0) == TREE_CODE (arg1)
                   1661:       && TREE_CODE (arg0) == INTEGER_CST
                   1662:       && TREE_INT_CST_LOW (arg0) == TREE_INT_CST_LOW (arg1)
                   1663:       && TREE_INT_CST_HIGH (arg0) == TREE_INT_CST_HIGH (arg1))
                   1664:     return 1;
                   1665: 
1.1.1.4   root     1666:   /* Detect when real constants are equal.  */
1.1       root     1667:   if (TREE_CODE (arg0) == TREE_CODE (arg1)
1.1.1.4   root     1668:       && TREE_CODE (arg0) == REAL_CST)
1.1.1.7   root     1669:     return !bcmp ((char *) &TREE_REAL_CST (arg0),
                   1670:                  (char *) &TREE_REAL_CST (arg1),
1.1.1.4   root     1671:                  sizeof (REAL_VALUE_TYPE));
1.1       root     1672: 
                   1673:   if (only_const)
                   1674:     return 0;
                   1675: 
                   1676:   if (arg0 == arg1)
                   1677:     return 1;
                   1678: 
                   1679:   if (TREE_CODE (arg0) != TREE_CODE (arg1))
                   1680:     return 0;
                   1681:   /* This is needed for conversions and for COMPONENT_REF.
                   1682:      Might as well play it safe and always test this.  */
                   1683:   if (TYPE_MODE (TREE_TYPE (arg0)) != TYPE_MODE (TREE_TYPE (arg1)))
                   1684:     return 0;
                   1685: 
                   1686:   switch (TREE_CODE_CLASS (TREE_CODE (arg0)))
                   1687:     {
                   1688:     case '1':
                   1689:       /* Two conversions are equal only if signedness and modes match.  */
                   1690:       if ((TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == CONVERT_EXPR)
                   1691:          && (TREE_UNSIGNED (TREE_TYPE (arg0))
                   1692:              != TREE_UNSIGNED (TREE_TYPE (arg1))))
                   1693:        return 0;
                   1694: 
                   1695:       return operand_equal_p (TREE_OPERAND (arg0, 0),
                   1696:                              TREE_OPERAND (arg1, 0), 0);
                   1697: 
                   1698:     case '<':
                   1699:     case '2':
                   1700:       return (operand_equal_p (TREE_OPERAND (arg0, 0),
                   1701:                               TREE_OPERAND (arg1, 0), 0)
                   1702:              && operand_equal_p (TREE_OPERAND (arg0, 1),
                   1703:                                  TREE_OPERAND (arg1, 1), 0));
                   1704: 
                   1705:     case 'r':
                   1706:       switch (TREE_CODE (arg0))
                   1707:        {
                   1708:        case INDIRECT_REF:
                   1709:          return operand_equal_p (TREE_OPERAND (arg0, 0),
                   1710:                                  TREE_OPERAND (arg1, 0), 0);
                   1711: 
                   1712:        case COMPONENT_REF:
                   1713:        case ARRAY_REF:
                   1714:          return (operand_equal_p (TREE_OPERAND (arg0, 0),
                   1715:                                   TREE_OPERAND (arg1, 0), 0)
                   1716:                  && operand_equal_p (TREE_OPERAND (arg0, 1),
                   1717:                                      TREE_OPERAND (arg1, 1), 0));
                   1718: 
                   1719:        case BIT_FIELD_REF:
                   1720:          return (operand_equal_p (TREE_OPERAND (arg0, 0),
                   1721:                                   TREE_OPERAND (arg1, 0), 0)
                   1722:                  && operand_equal_p (TREE_OPERAND (arg0, 1),
                   1723:                                      TREE_OPERAND (arg1, 1), 0)
                   1724:                  && operand_equal_p (TREE_OPERAND (arg0, 2),
                   1725:                                      TREE_OPERAND (arg1, 2), 0));
                   1726:        }
                   1727:       break;
                   1728:     }
                   1729: 
                   1730:   return 0;
                   1731: }
1.1.1.3   root     1732: 
                   1733: /* Similar to operand_equal_p, but see if ARG0 might have been made by
                   1734:    shorten_compare from ARG1 when ARG1 was being compared with OTHER. 
1.1       root     1735: 
                   1736:    When in doubt, return 0.  */
                   1737: 
                   1738: static int 
1.1.1.3   root     1739: operand_equal_for_comparison_p (arg0, arg1, other)
                   1740:      tree arg0, arg1;
                   1741:      tree other;
1.1       root     1742: {
1.1.1.3   root     1743:   int unsignedp1, unsignedpo;
                   1744:   tree primarg1, primother;
1.1.1.7   root     1745:   unsigned correct_width;
1.1       root     1746: 
1.1.1.3   root     1747:   if (operand_equal_p (arg0, arg1, 0))
1.1       root     1748:     return 1;
                   1749: 
1.1.1.8 ! root     1750:   if (! INTEGRAL_TYPE_P (TREE_TYPE (arg0))
        !          1751:       || ! INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
1.1       root     1752:     return 0;
                   1753: 
1.1.1.3   root     1754:   /* Duplicate what shorten_compare does to ARG1 and see if that gives the
                   1755:      actual comparison operand, ARG0.
1.1       root     1756: 
1.1.1.3   root     1757:      First throw away any conversions to wider types
1.1       root     1758:      already present in the operands.  */
                   1759: 
1.1.1.3   root     1760:   primarg1 = get_narrower (arg1, &unsignedp1);
                   1761:   primother = get_narrower (other, &unsignedpo);
                   1762: 
                   1763:   correct_width = TYPE_PRECISION (TREE_TYPE (arg1));
                   1764:   if (unsignedp1 == unsignedpo
                   1765:       && TYPE_PRECISION (TREE_TYPE (primarg1)) < correct_width
                   1766:       && TYPE_PRECISION (TREE_TYPE (primother)) < correct_width)
1.1       root     1767:     {
1.1.1.3   root     1768:       tree type = TREE_TYPE (arg0);
1.1       root     1769: 
                   1770:       /* Make sure shorter operand is extended the right way
                   1771:         to match the longer operand.  */
1.1.1.3   root     1772:       primarg1 = convert (signed_or_unsigned_type (unsignedp1,
                   1773:                                                  TREE_TYPE (primarg1)),
                   1774:                         primarg1);
1.1       root     1775: 
1.1.1.3   root     1776:       if (operand_equal_p (arg0, convert (type, primarg1), 0))
1.1       root     1777:        return 1;
                   1778:     }
                   1779: 
                   1780:   return 0;
                   1781: }
                   1782: 
1.1.1.4   root     1783: /* See if ARG is an expression that is either a comparison or is performing
1.1.1.3   root     1784:    arithmetic on comparisons.  The comparisons must only be comparing
                   1785:    two different values, which will be stored in *CVAL1 and *CVAL2; if
                   1786:    they are non-zero it means that some operands have already been found.
                   1787:    No variables may be used anywhere else in the expression except in the
1.1.1.6   root     1788:    comparisons.  If SAVE_P is true it means we removed a SAVE_EXPR around
                   1789:    the expression and save_expr needs to be called with CVAL1 and CVAL2.
1.1.1.3   root     1790: 
                   1791:    If this is true, return 1.  Otherwise, return zero.  */
                   1792: 
                   1793: static int
1.1.1.6   root     1794: twoval_comparison_p (arg, cval1, cval2, save_p)
1.1.1.3   root     1795:      tree arg;
                   1796:      tree *cval1, *cval2;
1.1.1.6   root     1797:      int *save_p;
1.1.1.3   root     1798: {
                   1799:   enum tree_code code = TREE_CODE (arg);
                   1800:   char class = TREE_CODE_CLASS (code);
                   1801: 
                   1802:   /* We can handle some of the 'e' cases here.  */
1.1.1.6   root     1803:   if (class == 'e' && code == TRUTH_NOT_EXPR)
1.1.1.3   root     1804:     class = '1';
                   1805:   else if (class == 'e'
                   1806:           && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR
                   1807:               || code == COMPOUND_EXPR))
                   1808:     class = '2';
                   1809: 
1.1.1.6   root     1810:   /* ??? Disable this since the SAVE_EXPR might already be in use outside
                   1811:      the expression.  There may be no way to make this work, but it needs
                   1812:      to be looked at again for 2.6.  */
                   1813: #if 0
                   1814:   else if (class == 'e' && code == SAVE_EXPR && SAVE_EXPR_RTL (arg) == 0)
                   1815:     {
                   1816:       /* If we've already found a CVAL1 or CVAL2, this expression is
                   1817:         two complex to handle.  */
                   1818:       if (*cval1 || *cval2)
                   1819:        return 0;
                   1820: 
                   1821:       class = '1';
                   1822:       *save_p = 1;
                   1823:     }
                   1824: #endif
                   1825: 
1.1.1.3   root     1826:   switch (class)
                   1827:     {
                   1828:     case '1':
1.1.1.6   root     1829:       return twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2, save_p);
1.1.1.3   root     1830: 
                   1831:     case '2':
1.1.1.6   root     1832:       return (twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2, save_p)
                   1833:              && twoval_comparison_p (TREE_OPERAND (arg, 1),
                   1834:                                      cval1, cval2, save_p));
1.1.1.3   root     1835: 
                   1836:     case 'c':
                   1837:       return 1;
                   1838: 
                   1839:     case 'e':
                   1840:       if (code == COND_EXPR)
1.1.1.6   root     1841:        return (twoval_comparison_p (TREE_OPERAND (arg, 0),
                   1842:                                     cval1, cval2, save_p)
                   1843:                && twoval_comparison_p (TREE_OPERAND (arg, 1),
                   1844:                                        cval1, cval2, save_p)
1.1.1.3   root     1845:                && twoval_comparison_p (TREE_OPERAND (arg, 2),
1.1.1.6   root     1846:                                        cval1, cval2, save_p));
1.1.1.3   root     1847:       return 0;
                   1848:          
                   1849:     case '<':
                   1850:       /* First see if we can handle the first operand, then the second.  For
                   1851:         the second operand, we know *CVAL1 can't be zero.  It must be that
                   1852:         one side of the comparison is each of the values; test for the
                   1853:         case where this isn't true by failing if the two operands
                   1854:         are the same.  */
                   1855: 
                   1856:       if (operand_equal_p (TREE_OPERAND (arg, 0),
                   1857:                           TREE_OPERAND (arg, 1), 0))
                   1858:        return 0;
                   1859: 
                   1860:       if (*cval1 == 0)
                   1861:        *cval1 = TREE_OPERAND (arg, 0);
                   1862:       else if (operand_equal_p (*cval1, TREE_OPERAND (arg, 0), 0))
                   1863:        ;
                   1864:       else if (*cval2 == 0)
                   1865:        *cval2 = TREE_OPERAND (arg, 0);
                   1866:       else if (operand_equal_p (*cval2, TREE_OPERAND (arg, 0), 0))
                   1867:        ;
                   1868:       else
                   1869:        return 0;
                   1870: 
                   1871:       if (operand_equal_p (*cval1, TREE_OPERAND (arg, 1), 0))
                   1872:        ;
                   1873:       else if (*cval2 == 0)
                   1874:        *cval2 = TREE_OPERAND (arg, 1);
                   1875:       else if (operand_equal_p (*cval2, TREE_OPERAND (arg, 1), 0))
                   1876:        ;
                   1877:       else
                   1878:        return 0;
                   1879: 
                   1880:       return 1;
                   1881:     }
                   1882: 
                   1883:   return 0;
                   1884: }
                   1885: 
                   1886: /* ARG is a tree that is known to contain just arithmetic operations and
                   1887:    comparisons.  Evaluate the operations in the tree substituting NEW0 for
1.1.1.4   root     1888:    any occurrence of OLD0 as an operand of a comparison and likewise for
1.1.1.3   root     1889:    NEW1 and OLD1.  */
                   1890: 
                   1891: static tree
                   1892: eval_subst (arg, old0, new0, old1, new1)
                   1893:      tree arg;
                   1894:      tree old0, new0, old1, new1;
                   1895: {
                   1896:   tree type = TREE_TYPE (arg);
                   1897:   enum tree_code code = TREE_CODE (arg);
                   1898:   char class = TREE_CODE_CLASS (code);
                   1899: 
                   1900:   /* We can handle some of the 'e' cases here.  */
                   1901:   if (class == 'e' && code == TRUTH_NOT_EXPR)
                   1902:     class = '1';
                   1903:   else if (class == 'e'
                   1904:           && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR))
                   1905:     class = '2';
                   1906: 
                   1907:   switch (class)
                   1908:     {
                   1909:     case '1':
                   1910:       return fold (build1 (code, type,
                   1911:                           eval_subst (TREE_OPERAND (arg, 0),
                   1912:                                       old0, new0, old1, new1)));
                   1913: 
                   1914:     case '2':
                   1915:       return fold (build (code, type,
                   1916:                          eval_subst (TREE_OPERAND (arg, 0),
                   1917:                                      old0, new0, old1, new1),
                   1918:                          eval_subst (TREE_OPERAND (arg, 1),
                   1919:                                      old0, new0, old1, new1)));
                   1920: 
                   1921:     case 'e':
                   1922:       switch (code)
                   1923:        {
                   1924:        case SAVE_EXPR:
                   1925:          return eval_subst (TREE_OPERAND (arg, 0), old0, new0, old1, new1);
                   1926: 
                   1927:        case COMPOUND_EXPR:
                   1928:          return eval_subst (TREE_OPERAND (arg, 1), old0, new0, old1, new1);
                   1929: 
                   1930:        case COND_EXPR:
                   1931:          return fold (build (code, type,
                   1932:                              eval_subst (TREE_OPERAND (arg, 0),
                   1933:                                          old0, new0, old1, new1),
                   1934:                              eval_subst (TREE_OPERAND (arg, 1),
                   1935:                                          old0, new0, old1, new1),
                   1936:                              eval_subst (TREE_OPERAND (arg, 2),
                   1937:                                          old0, new0, old1, new1)));
                   1938:        }
                   1939: 
                   1940:     case '<':
                   1941:       {
                   1942:        tree arg0 = TREE_OPERAND (arg, 0);
                   1943:        tree arg1 = TREE_OPERAND (arg, 1);
                   1944: 
                   1945:        /* We need to check both for exact equality and tree equality.  The
                   1946:           former will be true if the operand has a side-effect.  In that
                   1947:           case, we know the operand occurred exactly once.  */
                   1948: 
                   1949:        if (arg0 == old0 || operand_equal_p (arg0, old0, 0))
                   1950:          arg0 = new0;
                   1951:        else if (arg0 == old1 || operand_equal_p (arg0, old1, 0))
                   1952:          arg0 = new1;
                   1953: 
                   1954:        if (arg1 == old0 || operand_equal_p (arg1, old0, 0))
                   1955:          arg1 = new0;
                   1956:        else if (arg1 == old1 || operand_equal_p (arg1, old1, 0))
                   1957:          arg1 = new1;
                   1958: 
                   1959:        return fold (build (code, type, arg0, arg1));
                   1960:       }
                   1961:     }
                   1962: 
                   1963:   return arg;
                   1964: }
                   1965: 
1.1       root     1966: /* Return a tree for the case when the result of an expression is RESULT
                   1967:    converted to TYPE and OMITTED was previously an operand of the expression
                   1968:    but is now not needed (e.g., we folded OMITTED * 0).
                   1969: 
                   1970:    If OMITTED has side effects, we must evaluate it.  Otherwise, just do
                   1971:    the conversion of RESULT to TYPE.  */
                   1972: 
                   1973: static tree
                   1974: omit_one_operand (type, result, omitted)
                   1975:      tree type, result, omitted;
                   1976: {
                   1977:   tree t = convert (type, result);
                   1978: 
                   1979:   if (TREE_SIDE_EFFECTS (omitted))
                   1980:     return build (COMPOUND_EXPR, type, omitted, t);
                   1981: 
1.1.1.5   root     1982:   return non_lvalue (t);
1.1       root     1983: }
1.1.1.8 ! root     1984: 
        !          1985: /* Similar, but call pedantic_non_lvalue instead of non_lvalue.  */
        !          1986: 
        !          1987: static tree
        !          1988: pedantic_omit_one_operand (type, result, omitted)
        !          1989:      tree type, result, omitted;
        !          1990: {
        !          1991:   tree t = convert (type, result);
        !          1992: 
        !          1993:   if (TREE_SIDE_EFFECTS (omitted))
        !          1994:     return build (COMPOUND_EXPR, type, omitted, t);
        !          1995: 
        !          1996:   return pedantic_non_lvalue (t);
        !          1997: }
        !          1998: 
        !          1999: 
1.1       root     2000: 
1.1.1.4   root     2001: /* Return a simplified tree node for the truth-negation of ARG.  This
                   2002:    never alters ARG itself.  We assume that ARG is an operation that
1.1       root     2003:    returns a truth value (0 or 1).  */
                   2004: 
                   2005: tree
                   2006: invert_truthvalue (arg)
                   2007:      tree arg;
                   2008: {
                   2009:   tree type = TREE_TYPE (arg);
1.1.1.3   root     2010:   enum tree_code code = TREE_CODE (arg);
1.1       root     2011: 
1.1.1.6   root     2012:   if (code == ERROR_MARK)
                   2013:     return arg;
                   2014: 
1.1.1.3   root     2015:   /* If this is a comparison, we can simply invert it, except for
                   2016:      floating-point non-equality comparisons, in which case we just
                   2017:      enclose a TRUTH_NOT_EXPR around what we have.  */
1.1       root     2018: 
1.1.1.3   root     2019:   if (TREE_CODE_CLASS (code) == '<')
1.1       root     2020:     {
1.1.1.5   root     2021:       if (FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
1.1.1.3   root     2022:          && code != NE_EXPR && code != EQ_EXPR)
                   2023:        return build1 (TRUTH_NOT_EXPR, type, arg);
                   2024:       else
1.1.1.4   root     2025:        return build (invert_tree_comparison (code), type,
                   2026:                      TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1));
1.1.1.3   root     2027:     }
1.1       root     2028: 
1.1.1.3   root     2029:   switch (code)
                   2030:     {
1.1       root     2031:     case INTEGER_CST:
                   2032:       return convert (type, build_int_2 (TREE_INT_CST_LOW (arg) == 0
                   2033:                                         && TREE_INT_CST_HIGH (arg) == 0, 0));
                   2034: 
                   2035:     case TRUTH_AND_EXPR:
                   2036:       return build (TRUTH_OR_EXPR, type,
                   2037:                    invert_truthvalue (TREE_OPERAND (arg, 0)),
                   2038:                    invert_truthvalue (TREE_OPERAND (arg, 1)));
                   2039: 
                   2040:     case TRUTH_OR_EXPR:
                   2041:       return build (TRUTH_AND_EXPR, type,
                   2042:                    invert_truthvalue (TREE_OPERAND (arg, 0)),
                   2043:                    invert_truthvalue (TREE_OPERAND (arg, 1)));
                   2044: 
1.1.1.5   root     2045:     case TRUTH_XOR_EXPR:
                   2046:       /* Here we can invert either operand.  We invert the first operand
                   2047:         unless the second operand is a TRUTH_NOT_EXPR in which case our
                   2048:         result is the XOR of the first operand with the inside of the
                   2049:         negation of the second operand.  */
                   2050: 
                   2051:       if (TREE_CODE (TREE_OPERAND (arg, 1)) == TRUTH_NOT_EXPR)
                   2052:        return build (TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0),
                   2053:                      TREE_OPERAND (TREE_OPERAND (arg, 1), 0));
                   2054:       else
                   2055:        return build (TRUTH_XOR_EXPR, type,
                   2056:                      invert_truthvalue (TREE_OPERAND (arg, 0)),
                   2057:                      TREE_OPERAND (arg, 1));
                   2058: 
1.1       root     2059:     case TRUTH_ANDIF_EXPR:
                   2060:       return build (TRUTH_ORIF_EXPR, type,
                   2061:                    invert_truthvalue (TREE_OPERAND (arg, 0)),
                   2062:                    invert_truthvalue (TREE_OPERAND (arg, 1)));
                   2063: 
                   2064:     case TRUTH_ORIF_EXPR:
                   2065:       return build (TRUTH_ANDIF_EXPR, type,
                   2066:                    invert_truthvalue (TREE_OPERAND (arg, 0)),
                   2067:                    invert_truthvalue (TREE_OPERAND (arg, 1)));
                   2068: 
                   2069:     case TRUTH_NOT_EXPR:
                   2070:       return TREE_OPERAND (arg, 0);
                   2071: 
                   2072:     case COND_EXPR:
                   2073:       return build (COND_EXPR, type, TREE_OPERAND (arg, 0),
                   2074:                    invert_truthvalue (TREE_OPERAND (arg, 1)),
                   2075:                    invert_truthvalue (TREE_OPERAND (arg, 2)));
                   2076: 
1.1.1.2   root     2077:     case COMPOUND_EXPR:
                   2078:       return build (COMPOUND_EXPR, type, TREE_OPERAND (arg, 0),
                   2079:                    invert_truthvalue (TREE_OPERAND (arg, 1)));
                   2080: 
1.1       root     2081:     case NON_LVALUE_EXPR:
                   2082:       return invert_truthvalue (TREE_OPERAND (arg, 0));
                   2083: 
                   2084:     case NOP_EXPR:
                   2085:     case CONVERT_EXPR:
                   2086:     case FLOAT_EXPR:
                   2087:       return build1 (TREE_CODE (arg), type,
                   2088:                     invert_truthvalue (TREE_OPERAND (arg, 0)));
                   2089: 
                   2090:     case BIT_AND_EXPR:
1.1.1.6   root     2091:       if (!integer_onep (TREE_OPERAND (arg, 1)))
                   2092:        break;
1.1       root     2093:       return build (EQ_EXPR, type, arg, convert (type, integer_zero_node));
                   2094: 
1.1.1.6   root     2095:     case SAVE_EXPR:
                   2096:       return build1 (TRUTH_NOT_EXPR, type, arg);
1.1.1.8 ! root     2097: 
        !          2098:     case CLEANUP_POINT_EXPR:
        !          2099:       return build1 (CLEANUP_POINT_EXPR, type,
        !          2100:                     invert_truthvalue (TREE_OPERAND (arg, 0)));
1.1.1.6   root     2101:     }
                   2102:   if (TREE_CODE (TREE_TYPE (arg)) != BOOLEAN_TYPE)
                   2103:     abort ();
                   2104:   return build1 (TRUTH_NOT_EXPR, type, arg);
1.1       root     2105: }
                   2106: 
                   2107: /* Given a bit-wise operation CODE applied to ARG0 and ARG1, see if both
                   2108:    operands are another bit-wise operation with a common input.  If so,
                   2109:    distribute the bit operations to save an operation and possibly two if
                   2110:    constants are involved.  For example, convert
                   2111:        (A | B) & (A | C) into A | (B & C)
                   2112:    Further simplification will occur if B and C are constants.
                   2113: 
                   2114:    If this optimization cannot be done, 0 will be returned.  */
                   2115: 
                   2116: static tree
                   2117: distribute_bit_expr (code, type, arg0, arg1)
                   2118:      enum tree_code code;
                   2119:      tree type;
                   2120:      tree arg0, arg1;
                   2121: {
                   2122:   tree common;
                   2123:   tree left, right;
                   2124: 
                   2125:   if (TREE_CODE (arg0) != TREE_CODE (arg1)
                   2126:       || TREE_CODE (arg0) == code
                   2127:       || (TREE_CODE (arg0) != BIT_AND_EXPR
                   2128:          && TREE_CODE (arg0) != BIT_IOR_EXPR))
                   2129:     return 0;
                   2130: 
                   2131:   if (operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0), 0))
                   2132:     {
                   2133:       common = TREE_OPERAND (arg0, 0);
                   2134:       left = TREE_OPERAND (arg0, 1);
                   2135:       right = TREE_OPERAND (arg1, 1);
                   2136:     }
                   2137:   else if (operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 1), 0))
                   2138:     {
                   2139:       common = TREE_OPERAND (arg0, 0);
                   2140:       left = TREE_OPERAND (arg0, 1);
                   2141:       right = TREE_OPERAND (arg1, 0);
                   2142:     }
                   2143:   else if (operand_equal_p (TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 0), 0))
                   2144:     {
                   2145:       common = TREE_OPERAND (arg0, 1);
                   2146:       left = TREE_OPERAND (arg0, 0);
                   2147:       right = TREE_OPERAND (arg1, 1);
                   2148:     }
                   2149:   else if (operand_equal_p (TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 1), 0))
                   2150:     {
                   2151:       common = TREE_OPERAND (arg0, 1);
                   2152:       left = TREE_OPERAND (arg0, 0);
                   2153:       right = TREE_OPERAND (arg1, 0);
                   2154:     }
                   2155:   else
                   2156:     return 0;
                   2157: 
                   2158:   return fold (build (TREE_CODE (arg0), type, common,
                   2159:                      fold (build (code, type, left, right))));
                   2160: }
                   2161: 
                   2162: /* Return a BIT_FIELD_REF of type TYPE to refer to BITSIZE bits of INNER
                   2163:    starting at BITPOS.  The field is unsigned if UNSIGNEDP is non-zero.  */
                   2164: 
                   2165: static tree
                   2166: make_bit_field_ref (inner, type, bitsize, bitpos, unsignedp)
                   2167:      tree inner;
                   2168:      tree type;
                   2169:      int bitsize, bitpos;
                   2170:      int unsignedp;
                   2171: {
                   2172:   tree result = build (BIT_FIELD_REF, type, inner,
                   2173:                       size_int (bitsize), size_int (bitpos));
                   2174: 
                   2175:   TREE_UNSIGNED (result) = unsignedp;
                   2176: 
                   2177:   return result;
                   2178: }
                   2179: 
                   2180: /* Optimize a bit-field compare.
                   2181: 
                   2182:    There are two cases:  First is a compare against a constant and the
                   2183:    second is a comparison of two items where the fields are at the same
                   2184:    bit position relative to the start of a chunk (byte, halfword, word)
                   2185:    large enough to contain it.  In these cases we can avoid the shift
                   2186:    implicit in bitfield extractions.
                   2187: 
                   2188:    For constants, we emit a compare of the shifted constant with the
                   2189:    BIT_AND_EXPR of a mask and a byte, halfword, or word of the operand being
                   2190:    compared.  For two fields at the same position, we do the ANDs with the
                   2191:    similar mask and compare the result of the ANDs.
                   2192: 
                   2193:    CODE is the comparison code, known to be either NE_EXPR or EQ_EXPR.
                   2194:    COMPARE_TYPE is the type of the comparison, and LHS and RHS
                   2195:    are the left and right operands of the comparison, respectively.
                   2196: 
1.1.1.3   root     2197:    If the optimization described above can be done, we return the resulting
1.1       root     2198:    tree.  Otherwise we return zero.  */
                   2199: 
                   2200: static tree
                   2201: optimize_bit_field_compare (code, compare_type, lhs, rhs)
                   2202:      enum tree_code code;
                   2203:      tree compare_type;
                   2204:      tree lhs, rhs;
                   2205: {
                   2206:   int lbitpos, lbitsize, rbitpos, rbitsize;
                   2207:   int lnbitpos, lnbitsize, rnbitpos, rnbitsize;
                   2208:   tree type = TREE_TYPE (lhs);
                   2209:   tree signed_type, unsigned_type;
                   2210:   int const_p = TREE_CODE (rhs) == INTEGER_CST;
                   2211:   enum machine_mode lmode, rmode, lnmode, rnmode;
                   2212:   int lunsignedp, runsignedp;
                   2213:   int lvolatilep = 0, rvolatilep = 0;
                   2214:   tree linner, rinner;
                   2215:   tree mask;
1.1.1.3   root     2216:   tree offset;
1.1       root     2217: 
                   2218:   /* Get all the information about the extractions being done.  If the bit size
                   2219:      if the same as the size of the underlying object, we aren't doing an
                   2220:      extraction at all and so can do nothing.  */
1.1.1.3   root     2221:   linner = get_inner_reference (lhs, &lbitsize, &lbitpos, &offset, &lmode,
1.1       root     2222:                                &lunsignedp, &lvolatilep);
1.1.1.6   root     2223:   if (linner == lhs || lbitsize == GET_MODE_BITSIZE (lmode) || lbitsize < 0
1.1.1.3   root     2224:       || offset != 0)
1.1       root     2225:     return 0;
                   2226: 
                   2227:  if (!const_p)
                   2228:    {
                   2229:      /* If this is not a constant, we can only do something if bit positions,
                   2230:        sizes, and signedness are the same.   */
1.1.1.3   root     2231:      rinner = get_inner_reference (rhs, &rbitsize, &rbitpos, &offset,
1.1       root     2232:                                   &rmode, &runsignedp, &rvolatilep);
                   2233: 
1.1.1.6   root     2234:      if (rinner == rhs || lbitpos != rbitpos || lbitsize != rbitsize
1.1.1.3   root     2235:         || lunsignedp != runsignedp || offset != 0)
1.1       root     2236:        return 0;
                   2237:    }
                   2238: 
                   2239:   /* See if we can find a mode to refer to this field.  We should be able to,
                   2240:      but fail if we can't.  */
                   2241:   lnmode = get_best_mode (lbitsize, lbitpos,
                   2242:                          TYPE_ALIGN (TREE_TYPE (linner)), word_mode,
                   2243:                          lvolatilep);
                   2244:   if (lnmode == VOIDmode)
                   2245:     return 0;
                   2246: 
                   2247:   /* Set signed and unsigned types of the precision of this mode for the
                   2248:      shifts below.  */
                   2249:   signed_type = type_for_mode (lnmode, 0);
                   2250:   unsigned_type = type_for_mode (lnmode, 1);
                   2251: 
                   2252:   if (! const_p)
                   2253:     {
                   2254:       rnmode = get_best_mode (rbitsize, rbitpos, 
                   2255:                              TYPE_ALIGN (TREE_TYPE (rinner)), word_mode,
                   2256:                              rvolatilep);
                   2257:       if (rnmode == VOIDmode)
                   2258:        return 0;
                   2259:     }
                   2260:     
                   2261:   /* Compute the bit position and size for the new reference and our offset
                   2262:      within it. If the new reference is the same size as the original, we
                   2263:      won't optimize anything, so return zero.  */
                   2264:   lnbitsize = GET_MODE_BITSIZE (lnmode);
                   2265:   lnbitpos = lbitpos & ~ (lnbitsize - 1);
                   2266:   lbitpos -= lnbitpos;
                   2267:   if (lnbitsize == lbitsize)
                   2268:     return 0;
                   2269: 
                   2270:   if (! const_p)
                   2271:     {
                   2272:       rnbitsize = GET_MODE_BITSIZE (rnmode);
                   2273:       rnbitpos = rbitpos & ~ (rnbitsize - 1);
                   2274:       rbitpos -= rnbitpos;
                   2275:       if (rnbitsize == rbitsize)
                   2276:        return 0;
                   2277:     }
                   2278: 
1.1.1.8 ! root     2279:   if (BYTES_BIG_ENDIAN)
        !          2280:     lbitpos = lnbitsize - lbitsize - lbitpos;
1.1       root     2281: 
                   2282:   /* Make the mask to be used against the extracted field.  */
1.1.1.5   root     2283:   mask = build_int_2 (~0, ~0);
                   2284:   TREE_TYPE (mask) = unsigned_type;
                   2285:   force_fit_type (mask, 0);
                   2286:   mask = convert (unsigned_type, mask);
                   2287:   mask = const_binop (LSHIFT_EXPR, mask, size_int (lnbitsize - lbitsize), 0);
1.1       root     2288:   mask = const_binop (RSHIFT_EXPR, mask,
1.1.1.5   root     2289:                      size_int (lnbitsize - lbitsize - lbitpos), 0);
1.1       root     2290: 
                   2291:   if (! const_p)
                   2292:     /* If not comparing with constant, just rework the comparison
                   2293:        and return.  */
                   2294:     return build (code, compare_type,
1.1.1.4   root     2295:                  build (BIT_AND_EXPR, unsigned_type,
                   2296:                         make_bit_field_ref (linner, unsigned_type,
                   2297:                                             lnbitsize, lnbitpos, 1),
1.1       root     2298:                         mask),
1.1.1.4   root     2299:                  build (BIT_AND_EXPR, unsigned_type,
                   2300:                         make_bit_field_ref (rinner, unsigned_type,
                   2301:                                             rnbitsize, rnbitpos, 1),
1.1       root     2302:                         mask));
                   2303: 
                   2304:   /* Otherwise, we are handling the constant case. See if the constant is too
                   2305:      big for the field.  Warn and return a tree of for 0 (false) if so.  We do
                   2306:      this not only for its own sake, but to avoid having to test for this
                   2307:      error case below.  If we didn't, we might generate wrong code.
                   2308: 
                   2309:      For unsigned fields, the constant shifted right by the field length should
                   2310:      be all zero.  For signed fields, the high-order bits should agree with 
                   2311:      the sign bit.  */
                   2312: 
                   2313:   if (lunsignedp)
                   2314:     {
                   2315:       if (! integer_zerop (const_binop (RSHIFT_EXPR,
                   2316:                                        convert (unsigned_type, rhs),
1.1.1.5   root     2317:                                        size_int (lbitsize), 0)))
1.1       root     2318:        {
                   2319:          warning ("comparison is always %s due to width of bitfield",
                   2320:                   code == NE_EXPR ? "one" : "zero");
                   2321:          return convert (compare_type,
                   2322:                          (code == NE_EXPR
                   2323:                           ? integer_one_node : integer_zero_node));
                   2324:        }
                   2325:     }
                   2326:   else
                   2327:     {
                   2328:       tree tem = const_binop (RSHIFT_EXPR, convert (signed_type, rhs),
1.1.1.5   root     2329:                              size_int (lbitsize - 1), 0);
1.1       root     2330:       if (! integer_zerop (tem) && ! integer_all_onesp (tem))
                   2331:        {
                   2332:          warning ("comparison is always %s due to width of bitfield",
                   2333:                   code == NE_EXPR ? "one" : "zero");
                   2334:          return convert (compare_type,
                   2335:                          (code == NE_EXPR
                   2336:                           ? integer_one_node : integer_zero_node));
                   2337:        }
                   2338:     }
                   2339: 
                   2340:   /* Single-bit compares should always be against zero.  */
                   2341:   if (lbitsize == 1 && ! integer_zerop (rhs))
                   2342:     {
                   2343:       code = code == EQ_EXPR ? NE_EXPR : EQ_EXPR;
                   2344:       rhs = convert (type, integer_zero_node);
                   2345:     }
                   2346: 
                   2347:   /* Make a new bitfield reference, shift the constant over the
                   2348:      appropriate number of bits and mask it with the computed mask
                   2349:      (in case this was a signed field).  If we changed it, make a new one.  */
1.1.1.4   root     2350:   lhs = make_bit_field_ref (linner, unsigned_type, lnbitsize, lnbitpos, 1);
1.1.1.6   root     2351:   if (lvolatilep)
                   2352:     {
                   2353:       TREE_SIDE_EFFECTS (lhs) = 1;
                   2354:       TREE_THIS_VOLATILE (lhs) = 1;
                   2355:     }
1.1       root     2356: 
1.1.1.4   root     2357:   rhs = fold (const_binop (BIT_AND_EXPR,
                   2358:                           const_binop (LSHIFT_EXPR,
                   2359:                                        convert (unsigned_type, rhs),
1.1.1.5   root     2360:                                        size_int (lbitpos), 0),
                   2361:                           mask, 0));
1.1       root     2362: 
                   2363:   return build (code, compare_type,
1.1.1.4   root     2364:                build (BIT_AND_EXPR, unsigned_type, lhs, mask),
1.1       root     2365:                rhs);
                   2366: }
                   2367: 
1.1.1.4   root     2368: /* Subroutine for fold_truthop: decode a field reference.
1.1       root     2369: 
                   2370:    If EXP is a comparison reference, we return the innermost reference.
                   2371: 
                   2372:    *PBITSIZE is set to the number of bits in the reference, *PBITPOS is
                   2373:    set to the starting bit number.
                   2374: 
                   2375:    If the innermost field can be completely contained in a mode-sized
                   2376:    unit, *PMODE is set to that mode.  Otherwise, it is set to VOIDmode.
                   2377: 
                   2378:    *PVOLATILEP is set to 1 if the any expression encountered is volatile;
                   2379:    otherwise it is not changed.
                   2380: 
                   2381:    *PUNSIGNEDP is set to the signedness of the field.
                   2382: 
                   2383:    *PMASK is set to the mask used.  This is either contained in a
                   2384:    BIT_AND_EXPR or derived from the width of the field.
                   2385: 
1.1.1.8 ! root     2386:    *PAND_MASK is set the the mask found in a BIT_AND_EXPR, if any.
        !          2387: 
1.1       root     2388:    Return 0 if this is not a component reference or is one that we can't
                   2389:    do anything with.  */
                   2390: 
                   2391: static tree
                   2392: decode_field_reference (exp, pbitsize, pbitpos, pmode, punsignedp,
1.1.1.8 ! root     2393:                        pvolatilep, pmask, pand_mask)
1.1       root     2394:      tree exp;
                   2395:      int *pbitsize, *pbitpos;
                   2396:      enum machine_mode *pmode;
                   2397:      int *punsignedp, *pvolatilep;
                   2398:      tree *pmask;
1.1.1.8 ! root     2399:      tree *pand_mask;
1.1       root     2400: {
1.1.1.7   root     2401:   tree and_mask = 0;
                   2402:   tree mask, inner, offset;
                   2403:   tree unsigned_type;
                   2404:   int precision;
1.1       root     2405: 
1.1.1.5   root     2406:   /* All the optimizations using this function assume integer fields.  
                   2407:      There are problems with FP fields since the type_for_size call
                   2408:      below can fail for, e.g., XFmode.  */
                   2409:   if (! INTEGRAL_TYPE_P (TREE_TYPE (exp)))
                   2410:     return 0;
                   2411: 
1.1       root     2412:   STRIP_NOPS (exp);
                   2413: 
                   2414:   if (TREE_CODE (exp) == BIT_AND_EXPR)
                   2415:     {
1.1.1.7   root     2416:       and_mask = TREE_OPERAND (exp, 1);
1.1       root     2417:       exp = TREE_OPERAND (exp, 0);
1.1.1.7   root     2418:       STRIP_NOPS (exp); STRIP_NOPS (and_mask);
                   2419:       if (TREE_CODE (and_mask) != INTEGER_CST)
1.1       root     2420:        return 0;
                   2421:     }
                   2422: 
                   2423: 
1.1.1.3   root     2424:   inner = get_inner_reference (exp, pbitsize, pbitpos, &offset, pmode,
1.1       root     2425:                               punsignedp, pvolatilep);
1.1.1.8 ! root     2426:   if ((inner == exp && and_mask == 0)
        !          2427:       || *pbitsize < 0 || offset != 0)
1.1.1.3   root     2428:     return 0;
1.1       root     2429:   
1.1.1.7   root     2430:   /* Compute the mask to access the bitfield.  */
                   2431:   unsigned_type = type_for_size (*pbitsize, 1);
                   2432:   precision = TYPE_PRECISION (unsigned_type);
1.1       root     2433: 
1.1.1.7   root     2434:   mask = build_int_2 (~0, ~0);
                   2435:   TREE_TYPE (mask) = unsigned_type;
                   2436:   force_fit_type (mask, 0);
                   2437:   mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
                   2438:   mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
                   2439: 
                   2440:   /* Merge it with the mask we found in the BIT_AND_EXPR, if any.  */
                   2441:   if (and_mask != 0)
                   2442:     mask = fold (build (BIT_AND_EXPR, unsigned_type,
                   2443:                        convert (unsigned_type, and_mask), mask));
1.1       root     2444: 
                   2445:   *pmask = mask;
1.1.1.8 ! root     2446:   *pand_mask = and_mask;
1.1       root     2447:   return inner;
                   2448: }
                   2449: 
1.1.1.3   root     2450: /* Return non-zero if MASK represents a mask of SIZE ones in the low-order
1.1       root     2451:    bit positions.  */
                   2452: 
                   2453: static int
                   2454: all_ones_mask_p (mask, size)
                   2455:      tree mask;
                   2456:      int size;
                   2457: {
                   2458:   tree type = TREE_TYPE (mask);
                   2459:   int precision = TYPE_PRECISION (type);
1.1.1.5   root     2460:   tree tmask;
1.1       root     2461: 
1.1.1.5   root     2462:   tmask = build_int_2 (~0, ~0);
                   2463:   TREE_TYPE (tmask) = signed_type (type);
                   2464:   force_fit_type (tmask, 0);
1.1       root     2465:   return
1.1.1.8 ! root     2466:     tree_int_cst_equal (mask, 
        !          2467:                        const_binop (RSHIFT_EXPR,
        !          2468:                                     const_binop (LSHIFT_EXPR, tmask,
        !          2469:                                                  size_int (precision - size),
        !          2470:                                                  0),
        !          2471:                                     size_int (precision - size), 0));
1.1       root     2472: }
1.1.1.4   root     2473: 
                   2474: /* Subroutine for fold_truthop: determine if an operand is simple enough
                   2475:    to be evaluated unconditionally.  */
                   2476: 
                   2477: static int 
                   2478: simple_operand_p (exp)
                   2479:      tree exp;
                   2480: {
                   2481:   /* Strip any conversions that don't change the machine mode.  */
                   2482:   while ((TREE_CODE (exp) == NOP_EXPR
                   2483:          || TREE_CODE (exp) == CONVERT_EXPR)
                   2484:         && (TYPE_MODE (TREE_TYPE (exp))
                   2485:             == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
                   2486:     exp = TREE_OPERAND (exp, 0);
                   2487: 
                   2488:   return (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c'
                   2489:          || (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
                   2490:              && ! TREE_ADDRESSABLE (exp)
                   2491:              && ! TREE_THIS_VOLATILE (exp)
                   2492:              && ! DECL_NONLOCAL (exp)
                   2493:              /* Don't regard global variables as simple.  They may be
                   2494:                 allocated in ways unknown to the compiler (shared memory,
                   2495:                 #pragma weak, etc).  */
                   2496:              && ! TREE_PUBLIC (exp)
                   2497:              && ! DECL_EXTERNAL (exp)
                   2498:              /* Loading a static variable is unduly expensive, but global
                   2499:                 registers aren't expensive.  */
                   2500:              && (! TREE_STATIC (exp) || DECL_REGISTER (exp))));
                   2501: }
1.1       root     2502: 
1.1.1.4   root     2503: /* Subroutine for fold_truthop: try to optimize a range test.
                   2504: 
                   2505:    For example, "i >= 2 && i =< 9" can be done as "(unsigned) (i - 2) <= 7".
                   2506: 
                   2507:    JCODE is the logical combination of the two terms.  It is TRUTH_AND_EXPR
                   2508:    (representing TRUTH_ANDIF_EXPR and TRUTH_AND_EXPR) or TRUTH_OR_EXPR
                   2509:    (representing TRUTH_ORIF_EXPR and TRUTH_OR_EXPR).  TYPE is the type of
                   2510:    the result.
                   2511: 
                   2512:    VAR is the value being tested.  LO_CODE and HI_CODE are the comparison
                   2513:    operators comparing VAR to LO_CST and HI_CST.  LO_CST is known to be no
                   2514:    larger than HI_CST (they may be equal).
                   2515: 
                   2516:    We return the simplified tree or 0 if no optimization is possible.  */
                   2517: 
1.1.1.6   root     2518: static tree
1.1.1.4   root     2519: range_test (jcode, type, lo_code, hi_code, var, lo_cst, hi_cst)
                   2520:      enum tree_code jcode, lo_code, hi_code;
                   2521:      tree type, var, lo_cst, hi_cst;
                   2522: {
                   2523:   tree utype;
                   2524:   enum tree_code rcode;
                   2525: 
                   2526:   /* See if this is a range test and normalize the constant terms.  */
                   2527: 
                   2528:   if (jcode == TRUTH_AND_EXPR)
                   2529:     {
                   2530:       switch (lo_code)
                   2531:        {
                   2532:        case NE_EXPR:
                   2533:          /* See if we have VAR != CST && VAR != CST+1.  */
                   2534:          if (! (hi_code == NE_EXPR
                   2535:                 && TREE_INT_CST_LOW (hi_cst) - TREE_INT_CST_LOW (lo_cst) == 1
                   2536:                 && tree_int_cst_equal (integer_one_node,
                   2537:                                        const_binop (MINUS_EXPR,
1.1.1.5   root     2538:                                                     hi_cst, lo_cst, 0))))
1.1.1.4   root     2539:            return 0;
                   2540: 
                   2541:          rcode = GT_EXPR;
                   2542:          break;
                   2543: 
                   2544:        case GT_EXPR:
                   2545:        case GE_EXPR:
                   2546:          if (hi_code == LT_EXPR)
1.1.1.5   root     2547:            hi_cst = const_binop (MINUS_EXPR, hi_cst, integer_one_node, 0);
1.1.1.4   root     2548:          else if (hi_code != LE_EXPR)
                   2549:            return 0;
                   2550: 
                   2551:          if (lo_code == GT_EXPR)
1.1.1.5   root     2552:            lo_cst = const_binop (PLUS_EXPR, lo_cst, integer_one_node, 0);
1.1.1.4   root     2553: 
                   2554:          /* We now have VAR >= LO_CST && VAR <= HI_CST.  */
                   2555:          rcode = LE_EXPR;
                   2556:          break;
                   2557: 
                   2558:        default:
                   2559:          return 0;
                   2560:        }
                   2561:     }
                   2562:   else
                   2563:     {
                   2564:       switch (lo_code)
                   2565:        {
                   2566:        case EQ_EXPR:
                   2567:          /* See if we have VAR == CST || VAR == CST+1.  */
                   2568:          if (! (hi_code == EQ_EXPR
                   2569:                 && TREE_INT_CST_LOW (hi_cst) - TREE_INT_CST_LOW (lo_cst) == 1
                   2570:                 && tree_int_cst_equal (integer_one_node,
                   2571:                                        const_binop (MINUS_EXPR,
1.1.1.5   root     2572:                                                     hi_cst, lo_cst, 0))))
1.1.1.4   root     2573:            return 0;
                   2574: 
                   2575:          rcode = LE_EXPR;
                   2576:          break;
                   2577: 
                   2578:        case LE_EXPR:
                   2579:        case LT_EXPR:
                   2580:          if (hi_code == GE_EXPR)
1.1.1.5   root     2581:            hi_cst = const_binop (MINUS_EXPR, hi_cst, integer_one_node, 0);
1.1.1.4   root     2582:          else if (hi_code != GT_EXPR)
                   2583:            return 0;
                   2584: 
                   2585:          if (lo_code == LE_EXPR)
1.1.1.5   root     2586:            lo_cst = const_binop (PLUS_EXPR, lo_cst, integer_one_node, 0);
1.1.1.4   root     2587: 
                   2588:          /* We now have VAR < LO_CST || VAR > HI_CST.  */
                   2589:          rcode = GT_EXPR;
                   2590:          break;
                   2591: 
                   2592:        default:
                   2593:          return 0;
                   2594:        }
                   2595:     }
                   2596: 
                   2597:   /* When normalizing, it is possible to both increment the smaller constant
                   2598:      and decrement the larger constant.  See if they are still ordered.  */
                   2599:   if (tree_int_cst_lt (hi_cst, lo_cst))
                   2600:     return 0;
                   2601: 
                   2602:   /* Fail if VAR isn't an integer.  */
                   2603:   utype = TREE_TYPE (var);
1.1.1.5   root     2604:   if (! INTEGRAL_TYPE_P (utype))
1.1.1.4   root     2605:     return 0;
                   2606: 
                   2607:   /* The range test is invalid if subtracting the two constants results
                   2608:      in overflow.  This can happen in traditional mode.  */
                   2609:   if (! int_fits_type_p (hi_cst, TREE_TYPE (var))
                   2610:       || ! int_fits_type_p (lo_cst, TREE_TYPE (var)))
                   2611:     return 0;
                   2612: 
                   2613:   if (! TREE_UNSIGNED (utype))
                   2614:     {
                   2615:       utype = unsigned_type (utype);
                   2616:       var = convert (utype, var);
                   2617:       lo_cst = convert (utype, lo_cst);
                   2618:       hi_cst = convert (utype, hi_cst);
                   2619:     }
                   2620: 
                   2621:   return fold (convert (type,
                   2622:                        build (rcode, utype,
                   2623:                               build (MINUS_EXPR, utype, var, lo_cst),
1.1.1.5   root     2624:                               const_binop (MINUS_EXPR, hi_cst, lo_cst, 0))));
1.1.1.4   root     2625: }
                   2626: 
1.1.1.8 ! root     2627: /* Subroutine for fold_truthop: C is an INTEGER_CST interpreted as a P
        !          2628:    bit value.  Arrange things so the extra bits will be set to zero if and
        !          2629:    only if C is signed-extended to its full width.  If MASK is nonzero,
        !          2630:    it is an INTEGER_CST that should be AND'ed with the extra bits.  */
        !          2631: 
        !          2632: static tree
        !          2633: unextend (c, p, unsignedp, mask)
        !          2634:      tree c;
        !          2635:      int p;
        !          2636:      int unsignedp;
        !          2637:      tree mask;
        !          2638: {
        !          2639:   tree type = TREE_TYPE (c);
        !          2640:   int modesize = GET_MODE_BITSIZE (TYPE_MODE (type));
        !          2641:   tree temp;
        !          2642: 
        !          2643:   if (p == modesize || unsignedp)
        !          2644:     return c;
        !          2645: 
        !          2646:   if (TREE_UNSIGNED (type))
        !          2647:     c = convert (signed_type (type), c);
        !          2648: 
        !          2649:   /* We work by getting just the sign bit into the low-order bit, then
        !          2650:      into the high-order bit, then sign-extend.  We then XOR that value
        !          2651:      with C.  */
        !          2652:   temp = const_binop (RSHIFT_EXPR, c, size_int (p - 1), 0);
        !          2653:   temp = const_binop (BIT_AND_EXPR, temp, size_int (1), 0);
        !          2654:   temp = const_binop (LSHIFT_EXPR, temp, size_int (modesize - 1), 0);
        !          2655:   temp = const_binop (RSHIFT_EXPR, temp, size_int (modesize - p - 1), 0);
        !          2656:   if (mask != 0)
        !          2657:     temp = const_binop (BIT_AND_EXPR, temp, convert (TREE_TYPE (c), mask), 0);
        !          2658: 
        !          2659:   return convert (type, const_binop (BIT_XOR_EXPR, c, temp, 0));
        !          2660: }
        !          2661: 
1.1.1.4   root     2662: /* Find ways of folding logical expressions of LHS and RHS:
                   2663:    Try to merge two comparisons to the same innermost item.
                   2664:    Look for range tests like "ch >= '0' && ch <= '9'".
                   2665:    Look for combinations of simple terms on machines with expensive branches
                   2666:    and evaluate the RHS unconditionally.
1.1       root     2667: 
                   2668:    For example, if we have p->a == 2 && p->b == 4 and we can make an
                   2669:    object large enough to span both A and B, we can do this with a comparison
                   2670:    against the object ANDed with the a mask.
                   2671: 
                   2672:    If we have p->a == q->a && p->b == q->b, we may be able to use bit masking
                   2673:    operations to do this with one comparison.
                   2674: 
                   2675:    We check for both normal comparisons and the BIT_AND_EXPRs made this by
                   2676:    function and the one above.
                   2677: 
                   2678:    CODE is the logical operation being done.  It can be TRUTH_ANDIF_EXPR,
                   2679:    TRUTH_AND_EXPR, TRUTH_ORIF_EXPR, or TRUTH_OR_EXPR.
                   2680: 
                   2681:    TRUTH_TYPE is the type of the logical operand and LHS and RHS are its
                   2682:    two operands.
                   2683: 
                   2684:    We return the simplified tree or 0 if no optimization is possible.  */
                   2685: 
                   2686: static tree
1.1.1.4   root     2687: fold_truthop (code, truth_type, lhs, rhs)
1.1       root     2688:      enum tree_code code;
                   2689:      tree truth_type, lhs, rhs;
                   2690: {
                   2691:   /* If this is the "or" of two comparisons, we can do something if we
                   2692:      the comparisons are NE_EXPR.  If this is the "and", we can do something
                   2693:      if the comparisons are EQ_EXPR.  I.e., 
                   2694:        (a->b == 2 && a->c == 4) can become (a->new == NEW).
                   2695: 
                   2696:      WANTED_CODE is this operation code.  For single bit fields, we can
                   2697:      convert EQ_EXPR to NE_EXPR so we need not reject the "wrong"
                   2698:      comparison for one-bit fields.  */
                   2699: 
1.1.1.4   root     2700:   enum tree_code wanted_code;
1.1       root     2701:   enum tree_code lcode, rcode;
1.1.1.4   root     2702:   tree ll_arg, lr_arg, rl_arg, rr_arg;
1.1       root     2703:   tree ll_inner, lr_inner, rl_inner, rr_inner;
                   2704:   int ll_bitsize, ll_bitpos, lr_bitsize, lr_bitpos;
                   2705:   int rl_bitsize, rl_bitpos, rr_bitsize, rr_bitpos;
                   2706:   int xll_bitpos, xlr_bitpos, xrl_bitpos, xrr_bitpos;
                   2707:   int lnbitsize, lnbitpos, rnbitsize, rnbitpos;
                   2708:   int ll_unsignedp, lr_unsignedp, rl_unsignedp, rr_unsignedp;
                   2709:   enum machine_mode ll_mode, lr_mode, rl_mode, rr_mode;
                   2710:   enum machine_mode lnmode, rnmode;
                   2711:   tree ll_mask, lr_mask, rl_mask, rr_mask;
1.1.1.8 ! root     2712:   tree ll_and_mask, lr_and_mask, rl_and_mask, rr_and_mask;
1.1.1.4   root     2713:   tree l_const, r_const;
1.1       root     2714:   tree type, result;
                   2715:   int first_bit, end_bit;
1.1.1.4   root     2716:   int volatilep;
1.1       root     2717: 
1.1.1.4   root     2718:   /* Start by getting the comparison codes and seeing if this looks like
1.1.1.6   root     2719:      a range test.  Fail if anything is volatile.  If one operand is a
                   2720:      BIT_AND_EXPR with the constant one, treat it as if it were surrounded
                   2721:      with a NE_EXPR.  */
1.1.1.4   root     2722: 
                   2723:   if (TREE_SIDE_EFFECTS (lhs)
                   2724:       || TREE_SIDE_EFFECTS (rhs))
                   2725:     return 0;
1.1       root     2726: 
                   2727:   lcode = TREE_CODE (lhs);
                   2728:   rcode = TREE_CODE (rhs);
1.1.1.4   root     2729: 
1.1.1.6   root     2730:   if (lcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (lhs, 1)))
                   2731:     lcode = NE_EXPR, lhs = build (NE_EXPR, truth_type, lhs, integer_zero_node);
                   2732: 
                   2733:   if (rcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (rhs, 1)))
                   2734:     rcode = NE_EXPR, rhs = build (NE_EXPR, truth_type, rhs, integer_zero_node);
                   2735: 
1.1.1.4   root     2736:   if (TREE_CODE_CLASS (lcode) != '<'
                   2737:       || TREE_CODE_CLASS (rcode) != '<')
                   2738:     return 0;
                   2739: 
                   2740:   code = ((code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR)
                   2741:          ? TRUTH_AND_EXPR : TRUTH_OR_EXPR);
                   2742: 
                   2743:   ll_arg = TREE_OPERAND (lhs, 0);
                   2744:   lr_arg = TREE_OPERAND (lhs, 1);
                   2745:   rl_arg = TREE_OPERAND (rhs, 0);
                   2746:   rr_arg = TREE_OPERAND (rhs, 1);
                   2747:   
                   2748:   if (TREE_CODE (lr_arg) == INTEGER_CST
                   2749:       && TREE_CODE (rr_arg) == INTEGER_CST
                   2750:       && operand_equal_p (ll_arg, rl_arg, 0))
                   2751:     {
                   2752:       if (tree_int_cst_lt (lr_arg, rr_arg))
                   2753:        result = range_test (code, truth_type, lcode, rcode,
                   2754:                             ll_arg, lr_arg, rr_arg);
                   2755:       else
                   2756:        result = range_test (code, truth_type, rcode, lcode,
                   2757:                             ll_arg, rr_arg, lr_arg);
                   2758: 
                   2759:       /* If this isn't a range test, it also isn't a comparison that
                   2760:         can be merged.  However, it wins to evaluate the RHS unconditionally
                   2761:         on machines with expensive branches.   */
                   2762: 
                   2763:       if (result == 0 && BRANCH_COST >= 2)
                   2764:        {
                   2765:          if (TREE_CODE (ll_arg) != VAR_DECL
                   2766:              && TREE_CODE (ll_arg) != PARM_DECL)
                   2767:            {
                   2768:              /* Avoid evaluating the variable part twice.  */
                   2769:              ll_arg = save_expr (ll_arg);
                   2770:              lhs = build (lcode, TREE_TYPE (lhs), ll_arg, lr_arg);
                   2771:              rhs = build (rcode, TREE_TYPE (rhs), ll_arg, rr_arg);
                   2772:            }
                   2773:          return build (code, truth_type, lhs, rhs);
                   2774:        }
                   2775:       return result;
                   2776:     }
                   2777: 
                   2778:   /* If the RHS can be evaluated unconditionally and its operands are
                   2779:      simple, it wins to evaluate the RHS unconditionally on machines
                   2780:      with expensive branches.  In this case, this isn't a comparison
                   2781:      that can be merged.  */
                   2782: 
                   2783:   /* @@ I'm not sure it wins on the m88110 to do this if the comparisons
                   2784:      are with zero (tmw).  */
                   2785: 
                   2786:   if (BRANCH_COST >= 2
1.1.1.5   root     2787:       && INTEGRAL_TYPE_P (TREE_TYPE (rhs))
1.1.1.4   root     2788:       && simple_operand_p (rl_arg)
                   2789:       && simple_operand_p (rr_arg))
                   2790:     return build (code, truth_type, lhs, rhs);
                   2791: 
                   2792:   /* See if the comparisons can be merged.  Then get all the parameters for
                   2793:      each side.  */
                   2794: 
1.1       root     2795:   if ((lcode != EQ_EXPR && lcode != NE_EXPR)
1.1.1.4   root     2796:       || (rcode != EQ_EXPR && rcode != NE_EXPR))
1.1       root     2797:     return 0;
                   2798: 
1.1.1.4   root     2799:   volatilep = 0;
                   2800:   ll_inner = decode_field_reference (ll_arg,
1.1       root     2801:                                     &ll_bitsize, &ll_bitpos, &ll_mode,
1.1.1.8 ! root     2802:                                     &ll_unsignedp, &volatilep, &ll_mask,
        !          2803:                                     &ll_and_mask);
1.1.1.4   root     2804:   lr_inner = decode_field_reference (lr_arg,
1.1       root     2805:                                     &lr_bitsize, &lr_bitpos, &lr_mode,
1.1.1.8 ! root     2806:                                     &lr_unsignedp, &volatilep, &lr_mask,
        !          2807:                                     &lr_and_mask);
1.1.1.4   root     2808:   rl_inner = decode_field_reference (rl_arg,
1.1       root     2809:                                     &rl_bitsize, &rl_bitpos, &rl_mode,
1.1.1.8 ! root     2810:                                     &rl_unsignedp, &volatilep, &rl_mask,
        !          2811:                                     &rl_and_mask);
1.1.1.4   root     2812:   rr_inner = decode_field_reference (rr_arg,
1.1       root     2813:                                     &rr_bitsize, &rr_bitpos, &rr_mode,
1.1.1.8 ! root     2814:                                     &rr_unsignedp, &volatilep, &rr_mask,
        !          2815:                                     &rr_and_mask);
1.1       root     2816: 
                   2817:   /* It must be true that the inner operation on the lhs of each
                   2818:      comparison must be the same if we are to be able to do anything.
                   2819:      Then see if we have constants.  If not, the same must be true for
                   2820:      the rhs's.  */
                   2821:   if (volatilep || ll_inner == 0 || rl_inner == 0
                   2822:       || ! operand_equal_p (ll_inner, rl_inner, 0))
                   2823:     return 0;
                   2824: 
1.1.1.4   root     2825:   if (TREE_CODE (lr_arg) == INTEGER_CST
                   2826:       && TREE_CODE (rr_arg) == INTEGER_CST)
                   2827:     l_const = lr_arg, r_const = rr_arg;
1.1       root     2828:   else if (lr_inner == 0 || rr_inner == 0
                   2829:           || ! operand_equal_p (lr_inner, rr_inner, 0))
                   2830:     return 0;
1.1.1.4   root     2831:   else
                   2832:     l_const = r_const = 0;
1.1       root     2833: 
                   2834:   /* If either comparison code is not correct for our logical operation,
                   2835:      fail.  However, we can convert a one-bit comparison against zero into
                   2836:      the opposite comparison against that bit being set in the field.  */
1.1.1.4   root     2837: 
                   2838:   wanted_code = (code == TRUTH_AND_EXPR ? EQ_EXPR : NE_EXPR);
1.1       root     2839:   if (lcode != wanted_code)
                   2840:     {
                   2841:       if (l_const && integer_zerop (l_const) && integer_pow2p (ll_mask))
                   2842:        l_const = ll_mask;
                   2843:       else
                   2844:        return 0;
                   2845:     }
                   2846: 
                   2847:   if (rcode != wanted_code)
                   2848:     {
                   2849:       if (r_const && integer_zerop (r_const) && integer_pow2p (rl_mask))
                   2850:        r_const = rl_mask;
                   2851:       else
                   2852:        return 0;
                   2853:     }
                   2854: 
                   2855:   /* See if we can find a mode that contains both fields being compared on
                   2856:      the left.  If we can't, fail.  Otherwise, update all constants and masks
                   2857:      to be relative to a field of that size.  */
                   2858:   first_bit = MIN (ll_bitpos, rl_bitpos);
                   2859:   end_bit = MAX (ll_bitpos + ll_bitsize, rl_bitpos + rl_bitsize);
                   2860:   lnmode = get_best_mode (end_bit - first_bit, first_bit,
                   2861:                          TYPE_ALIGN (TREE_TYPE (ll_inner)), word_mode,
                   2862:                          volatilep);
                   2863:   if (lnmode == VOIDmode)
                   2864:     return 0;
                   2865: 
                   2866:   lnbitsize = GET_MODE_BITSIZE (lnmode);
                   2867:   lnbitpos = first_bit & ~ (lnbitsize - 1);
                   2868:   type = type_for_size (lnbitsize, 1);
                   2869:   xll_bitpos = ll_bitpos - lnbitpos, xrl_bitpos = rl_bitpos - lnbitpos;
                   2870: 
1.1.1.8 ! root     2871:   if (BYTES_BIG_ENDIAN)
        !          2872:     {
        !          2873:       xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize;
        !          2874:       xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize;
        !          2875:     }
1.1       root     2876: 
                   2877:   ll_mask = const_binop (LSHIFT_EXPR, convert (type, ll_mask),
1.1.1.5   root     2878:                         size_int (xll_bitpos), 0);
1.1       root     2879:   rl_mask = const_binop (LSHIFT_EXPR, convert (type, rl_mask),
1.1.1.5   root     2880:                         size_int (xrl_bitpos), 0);
1.1       root     2881: 
                   2882:   if (l_const)
                   2883:     {
1.1.1.8 ! root     2884:       l_const = convert (type, l_const);
        !          2885:       l_const = unextend (l_const,  ll_bitsize, ll_unsignedp, ll_and_mask);
        !          2886:       l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos), 0);
        !          2887:       if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
        !          2888:                                        fold (build1 (BIT_NOT_EXPR,
        !          2889:                                                      type, ll_mask)),
        !          2890:                                        0)))
        !          2891:        {
        !          2892:          warning ("comparison is always %s",
        !          2893:                   wanted_code == NE_EXPR ? "one" : "zero");
        !          2894:          
        !          2895:          return convert (truth_type,
        !          2896:                          wanted_code == NE_EXPR
        !          2897:                          ? integer_one_node : integer_zero_node);
        !          2898:        }
1.1       root     2899:     }
                   2900:   if (r_const)
                   2901:     {
1.1.1.8 ! root     2902:       r_const = convert (type, r_const);
        !          2903:       r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
        !          2904:       r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos), 0);
        !          2905:       if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
        !          2906:                                        fold (build1 (BIT_NOT_EXPR,
        !          2907:                                                      type, rl_mask)),
        !          2908:                                        0)))
        !          2909:        {
        !          2910:          warning ("comparison is always %s",
        !          2911:                   wanted_code == NE_EXPR ? "one" : "zero");
        !          2912:          
        !          2913:          return convert (truth_type,
        !          2914:                          wanted_code == NE_EXPR
        !          2915:                          ? integer_one_node : integer_zero_node);
        !          2916:        }
1.1       root     2917:     }
                   2918: 
                   2919:   /* If the right sides are not constant, do the same for it.  Also,
                   2920:      disallow this optimization if a size or signedness mismatch occurs
                   2921:      between the left and right sides.  */
                   2922:   if (l_const == 0)
                   2923:     {
                   2924:       if (ll_bitsize != lr_bitsize || rl_bitsize != rr_bitsize
1.1.1.4   root     2925:          || ll_unsignedp != lr_unsignedp || rl_unsignedp != rr_unsignedp
                   2926:          /* Make sure the two fields on the right
                   2927:             correspond to the left without being swapped.  */
                   2928:          || ll_bitpos - rl_bitpos != lr_bitpos - rr_bitpos)
1.1       root     2929:        return 0;
                   2930: 
                   2931:       first_bit = MIN (lr_bitpos, rr_bitpos);
                   2932:       end_bit = MAX (lr_bitpos + lr_bitsize, rr_bitpos + rr_bitsize);
                   2933:       rnmode = get_best_mode (end_bit - first_bit, first_bit,
                   2934:                              TYPE_ALIGN (TREE_TYPE (lr_inner)), word_mode,
                   2935:                              volatilep);
                   2936:       if (rnmode == VOIDmode)
                   2937:        return 0;
                   2938: 
                   2939:       rnbitsize = GET_MODE_BITSIZE (rnmode);
                   2940:       rnbitpos = first_bit & ~ (rnbitsize - 1);
                   2941:       xlr_bitpos = lr_bitpos - rnbitpos, xrr_bitpos = rr_bitpos - rnbitpos;
                   2942: 
1.1.1.8 ! root     2943:       if (BYTES_BIG_ENDIAN)
        !          2944:        {
        !          2945:          xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize;
        !          2946:          xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize;
        !          2947:        }
1.1       root     2948: 
                   2949:       lr_mask = const_binop (LSHIFT_EXPR, convert (type, lr_mask),
1.1.1.5   root     2950:                             size_int (xlr_bitpos), 0);
1.1       root     2951:       rr_mask = const_binop (LSHIFT_EXPR, convert (type, rr_mask),
1.1.1.5   root     2952:                             size_int (xrr_bitpos), 0);
1.1       root     2953: 
                   2954:       /* Make a mask that corresponds to both fields being compared.
                   2955:         Do this for both items being compared.  If the masks agree,
                   2956:         we can do this by masking both and comparing the masked
                   2957:         results.  */
1.1.1.5   root     2958:       ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
                   2959:       lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask, 0);
1.1       root     2960:       if (operand_equal_p (ll_mask, lr_mask, 0) && lnbitsize == rnbitsize)
                   2961:        {
                   2962:          lhs = make_bit_field_ref (ll_inner, type, lnbitsize, lnbitpos,
                   2963:                                    ll_unsignedp || rl_unsignedp);
                   2964:          rhs = make_bit_field_ref (lr_inner, type, rnbitsize, rnbitpos,
                   2965:                                    lr_unsignedp || rr_unsignedp);
                   2966:          if (! all_ones_mask_p (ll_mask, lnbitsize))
                   2967:            {
                   2968:              lhs = build (BIT_AND_EXPR, type, lhs, ll_mask);
                   2969:              rhs = build (BIT_AND_EXPR, type, rhs, ll_mask);
                   2970:            }
                   2971:          return build (wanted_code, truth_type, lhs, rhs);
                   2972:        }
                   2973: 
                   2974:       /* There is still another way we can do something:  If both pairs of
                   2975:         fields being compared are adjacent, we may be able to make a wider
                   2976:         field containing them both.  */
                   2977:       if ((ll_bitsize + ll_bitpos == rl_bitpos
                   2978:           && lr_bitsize + lr_bitpos == rr_bitpos)
                   2979:          || (ll_bitpos == rl_bitpos + rl_bitsize
                   2980:              && lr_bitpos == rr_bitpos + rr_bitsize))
                   2981:        return build (wanted_code, truth_type,
                   2982:                      make_bit_field_ref (ll_inner, type,
                   2983:                                          ll_bitsize + rl_bitsize,
                   2984:                                          MIN (ll_bitpos, rl_bitpos),
                   2985:                                          ll_unsignedp),
                   2986:                      make_bit_field_ref (lr_inner, type,
                   2987:                                          lr_bitsize + rr_bitsize,
                   2988:                                          MIN (lr_bitpos, rr_bitpos),
                   2989:                                          lr_unsignedp));
                   2990: 
                   2991:       return 0;
                   2992:     }
                   2993: 
                   2994:   /* Handle the case of comparisons with constants.  If there is something in
                   2995:      common between the masks, those bits of the constants must be the same.
                   2996:      If not, the condition is always false.  Test for this to avoid generating
                   2997:      incorrect code below.  */
1.1.1.5   root     2998:   result = const_binop (BIT_AND_EXPR, ll_mask, rl_mask, 0);
1.1       root     2999:   if (! integer_zerop (result)
1.1.1.5   root     3000:       && simple_cst_equal (const_binop (BIT_AND_EXPR, result, l_const, 0),
                   3001:                           const_binop (BIT_AND_EXPR, result, r_const, 0)) != 1)
1.1       root     3002:     {
                   3003:       if (wanted_code == NE_EXPR)
                   3004:        {
                   3005:          warning ("`or' of unmatched not-equal tests is always 1");
                   3006:          return convert (truth_type, integer_one_node);
                   3007:        }
                   3008:       else
                   3009:        {
                   3010:          warning ("`and' of mutually exclusive equal-tests is always zero");
                   3011:          return convert (truth_type, integer_zero_node);
                   3012:        }
                   3013:     }
                   3014: 
                   3015:   /* Construct the expression we will return.  First get the component
                   3016:      reference we will make.  Unless the mask is all ones the width of
                   3017:      that field, perform the mask operation.  Then compare with the
                   3018:      merged constant.  */
                   3019:   result = make_bit_field_ref (ll_inner, type, lnbitsize, lnbitpos,
                   3020:                               ll_unsignedp || rl_unsignedp);
                   3021: 
1.1.1.5   root     3022:   ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
1.1       root     3023:   if (! all_ones_mask_p (ll_mask, lnbitsize))
                   3024:     result = build (BIT_AND_EXPR, type, result, ll_mask);
                   3025: 
                   3026:   return build (wanted_code, truth_type, result,
1.1.1.5   root     3027:                const_binop (BIT_IOR_EXPR, l_const, r_const, 0));
1.1       root     3028: }
                   3029: 
1.1.1.7   root     3030: /* If T contains a COMPOUND_EXPR which was inserted merely to evaluate
                   3031:    S, a SAVE_EXPR, return the expression actually being evaluated.   Note
                   3032:    that we may sometimes modify the tree.  */
                   3033: 
                   3034: static tree
                   3035: strip_compound_expr (t, s)
                   3036:      tree t;
                   3037:      tree s;
                   3038: {
                   3039:   tree type = TREE_TYPE (t);
                   3040:   enum tree_code code = TREE_CODE (t);
                   3041: 
                   3042:   /* See if this is the COMPOUND_EXPR we want to eliminate.  */
                   3043:   if (code == COMPOUND_EXPR && TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR
                   3044:       && TREE_OPERAND (TREE_OPERAND (t, 0), 0) == s)
                   3045:     return TREE_OPERAND (t, 1);
                   3046: 
                   3047:   /* See if this is a COND_EXPR or a simple arithmetic operator.   We
                   3048:      don't bother handling any other types.  */
                   3049:   else if (code == COND_EXPR)
                   3050:     {
                   3051:       TREE_OPERAND (t, 0) = strip_compound_expr (TREE_OPERAND (t, 0), s);
                   3052:       TREE_OPERAND (t, 1) = strip_compound_expr (TREE_OPERAND (t, 1), s);
                   3053:       TREE_OPERAND (t, 2) = strip_compound_expr (TREE_OPERAND (t, 2), s);
                   3054:     }
                   3055:   else if (TREE_CODE_CLASS (code) == '1')
                   3056:     TREE_OPERAND (t, 0) = strip_compound_expr (TREE_OPERAND (t, 0), s);
                   3057:   else if (TREE_CODE_CLASS (code) == '<'
                   3058:           || TREE_CODE_CLASS (code) == '2')
                   3059:     {
                   3060:       TREE_OPERAND (t, 0) = strip_compound_expr (TREE_OPERAND (t, 0), s);
                   3061:       TREE_OPERAND (t, 1) = strip_compound_expr (TREE_OPERAND (t, 1), s);
                   3062:     }
                   3063: 
                   3064:   return t;
                   3065: }
                   3066: 
1.1       root     3067: /* Perform constant folding and related simplification of EXPR.
                   3068:    The related simplifications include x*1 => x, x*0 => 0, etc.,
                   3069:    and application of the associative law.
                   3070:    NOP_EXPR conversions may be removed freely (as long as we
                   3071:    are careful not to change the C type of the overall expression)
                   3072:    We cannot simplify through a CONVERT_EXPR, FIX_EXPR or FLOAT_EXPR,
                   3073:    but we can constant-fold them if they have constant operands.  */
                   3074: 
                   3075: tree
                   3076: fold (expr) 
                   3077:      tree expr;
                   3078: {
                   3079:   register tree t = expr;
                   3080:   tree t1 = NULL_TREE;
1.1.1.3   root     3081:   tree tem;
1.1       root     3082:   tree type = TREE_TYPE (expr);
                   3083:   register tree arg0, arg1;
                   3084:   register enum tree_code code = TREE_CODE (t);
                   3085:   register int kind;
1.1.1.3   root     3086:   int invert;
1.1       root     3087: 
                   3088:   /* WINS will be nonzero when the switch is done
                   3089:      if all operands are constant.  */
                   3090: 
                   3091:   int wins = 1;
                   3092: 
1.1.1.6   root     3093:   /* Don't try to process an RTL_EXPR since its operands aren't trees.  */
                   3094:   if (code == RTL_EXPR)
                   3095:     return t;
                   3096: 
1.1       root     3097:   /* Return right away if already constant.  */
                   3098:   if (TREE_CONSTANT (t))
                   3099:     {
                   3100:       if (code == CONST_DECL)
                   3101:        return DECL_INITIAL (t);
                   3102:       return t;
                   3103:     }
                   3104:   
                   3105:   kind = TREE_CODE_CLASS (code);
1.1.1.4   root     3106:   if (code == NOP_EXPR || code == FLOAT_EXPR || code == CONVERT_EXPR)
                   3107:     {
1.1.1.5   root     3108:       tree subop;
                   3109: 
1.1.1.4   root     3110:       /* Special case for conversion ops that can have fixed point args.  */
                   3111:       arg0 = TREE_OPERAND (t, 0);
                   3112: 
                   3113:       /* Don't use STRIP_NOPS, because signedness of argument type matters.  */
                   3114:       if (arg0 != 0)
                   3115:        STRIP_TYPE_NOPS (arg0);
                   3116: 
1.1.1.5   root     3117:       if (arg0 != 0 && TREE_CODE (arg0) == COMPLEX_CST)
                   3118:        subop = TREE_REALPART (arg0);
                   3119:       else
                   3120:        subop = arg0;
                   3121: 
                   3122:       if (subop != 0 && TREE_CODE (subop) != INTEGER_CST
1.1.1.4   root     3123: #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1.1.1.5   root     3124:          && TREE_CODE (subop) != REAL_CST
1.1.1.4   root     3125: #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
                   3126:          )
                   3127:        /* Note that TREE_CONSTANT isn't enough:
                   3128:           static var addresses are constant but we can't
                   3129:           do arithmetic on them.  */
                   3130:        wins = 0;
                   3131:     }
                   3132:   else if (kind == 'e' || kind == '<'
                   3133:           || kind == '1' || kind == '2' || kind == 'r')
1.1       root     3134:     {
                   3135:       register int len = tree_code_length[(int) code];
                   3136:       register int i;
                   3137:       for (i = 0; i < len; i++)
                   3138:        {
                   3139:          tree op = TREE_OPERAND (t, i);
1.1.1.5   root     3140:          tree subop;
1.1       root     3141: 
                   3142:          if (op == 0)
                   3143:            continue;           /* Valid for CALL_EXPR, at least.  */
                   3144: 
1.1.1.5   root     3145:          if (kind == '<' || code == RSHIFT_EXPR)
                   3146:            {
                   3147:              /* Signedness matters here.  Perhaps we can refine this
                   3148:                 later.  */
                   3149:              STRIP_TYPE_NOPS (op);
                   3150:            }
                   3151:          else
                   3152:            {
                   3153:              /* Strip any conversions that don't change the mode.  */
                   3154:              STRIP_NOPS (op);
                   3155:            }
1.1       root     3156:          
1.1.1.5   root     3157:          if (TREE_CODE (op) == COMPLEX_CST)
                   3158:            subop = TREE_REALPART (op);
                   3159:          else
                   3160:            subop = op;
                   3161: 
                   3162:          if (TREE_CODE (subop) != INTEGER_CST
1.1       root     3163: #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
1.1.1.5   root     3164:              && TREE_CODE (subop) != REAL_CST
1.1       root     3165: #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
                   3166:              )
                   3167:            /* Note that TREE_CONSTANT isn't enough:
                   3168:               static var addresses are constant but we can't
                   3169:               do arithmetic on them.  */
                   3170:            wins = 0;
                   3171: 
                   3172:          if (i == 0)
                   3173:            arg0 = op;
                   3174:          else if (i == 1)
                   3175:            arg1 = op;
                   3176:        }
                   3177:     }
                   3178: 
                   3179:   /* If this is a commutative operation, and ARG0 is a constant, move it
                   3180:      to ARG1 to reduce the number of tests below.  */
                   3181:   if ((code == PLUS_EXPR || code == MULT_EXPR || code == MIN_EXPR
                   3182:        || code == MAX_EXPR || code == BIT_IOR_EXPR || code == BIT_XOR_EXPR
                   3183:        || code == BIT_AND_EXPR)
                   3184:       && (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST))
                   3185:     {
1.1.1.3   root     3186:       tem = arg0; arg0 = arg1; arg1 = tem;
1.1       root     3187: 
1.1.1.3   root     3188:       tem = TREE_OPERAND (t, 0); TREE_OPERAND (t, 0) = TREE_OPERAND (t, 1);
                   3189:       TREE_OPERAND (t, 1) = tem;
1.1       root     3190:     }
                   3191: 
                   3192:   /* Now WINS is set as described above,
                   3193:      ARG0 is the first operand of EXPR,
                   3194:      and ARG1 is the second operand (if it has more than one operand).
                   3195: 
                   3196:      First check for cases where an arithmetic operation is applied to a
                   3197:      compound, conditional, or comparison operation.  Push the arithmetic
                   3198:      operation inside the compound or conditional to see if any folding
                   3199:      can then be done.  Convert comparison to conditional for this purpose.
                   3200:      The also optimizes non-constant cases that used to be done in
1.1.1.6   root     3201:      expand_expr.
                   3202: 
                   3203:      Before we do that, see if this is a BIT_AND_EXPR or a BIT_OR_EXPR,
1.1.1.7   root     3204:      one of the operands is a comparison and the other is a comparison, a
                   3205:      BIT_AND_EXPR with the constant 1, or a truth value.  In that case, the
                   3206:      code below would make the expression more complex.  Change it to a
1.1.1.6   root     3207:      TRUTH_{AND,OR}_EXPR.  Likewise, convert a similar NE_EXPR to 
                   3208:      TRUTH_XOR_EXPR and an EQ_EXPR to the inversion of a TRUTH_XOR_EXPR.  */
                   3209: 
                   3210:   if ((code == BIT_AND_EXPR || code == BIT_IOR_EXPR
                   3211:        || code == EQ_EXPR || code == NE_EXPR)
1.1.1.7   root     3212:       && ((truth_value_p (TREE_CODE (arg0))
                   3213:           && (truth_value_p (TREE_CODE (arg1))
1.1.1.6   root     3214:               || (TREE_CODE (arg1) == BIT_AND_EXPR
                   3215:                   && integer_onep (TREE_OPERAND (arg1, 1)))))
1.1.1.7   root     3216:          || (truth_value_p (TREE_CODE (arg1))
                   3217:              && (truth_value_p (TREE_CODE (arg0))
1.1.1.6   root     3218:                  || (TREE_CODE (arg0) == BIT_AND_EXPR
                   3219:                      && integer_onep (TREE_OPERAND (arg0, 1)))))))
                   3220:     {
                   3221:       t = fold (build (code == BIT_AND_EXPR ? TRUTH_AND_EXPR
                   3222:                       : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR
                   3223:                       : TRUTH_XOR_EXPR,
                   3224:                       type, arg0, arg1));
                   3225: 
                   3226:       if (code == EQ_EXPR)
                   3227:        t = invert_truthvalue (t);
                   3228: 
                   3229:       return t;
                   3230:     }
                   3231: 
1.1       root     3232:   if (TREE_CODE_CLASS (code) == '1')
                   3233:     {
                   3234:       if (TREE_CODE (arg0) == COMPOUND_EXPR)
                   3235:        return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
                   3236:                      fold (build1 (code, type, TREE_OPERAND (arg0, 1))));
                   3237:       else if (TREE_CODE (arg0) == COND_EXPR)
1.1.1.4   root     3238:        {
                   3239:          t = fold (build (COND_EXPR, type, TREE_OPERAND (arg0, 0),
                   3240:                           fold (build1 (code, type, TREE_OPERAND (arg0, 1))),
                   3241:                           fold (build1 (code, type, TREE_OPERAND (arg0, 2)))));
                   3242: 
                   3243:          /* If this was a conversion, and all we did was to move into
1.1.1.8 ! root     3244:             inside the COND_EXPR, bring it back out.  But leave it if
        !          3245:             it is a conversion from integer to integer and the
        !          3246:             result precision is no wider than a word since such a
        !          3247:             conversion is cheap and may be optimized away by combine,
        !          3248:             while it couldn't if it were outside the COND_EXPR.  Then return
        !          3249:             so we don't get into an infinite recursion loop taking the
        !          3250:             conversion out and then back in.  */
1.1.1.4   root     3251: 
                   3252:          if ((code == NOP_EXPR || code == CONVERT_EXPR
                   3253:               || code == NON_LVALUE_EXPR)
                   3254:              && TREE_CODE (t) == COND_EXPR
                   3255:              && TREE_CODE (TREE_OPERAND (t, 1)) == code
                   3256:              && TREE_CODE (TREE_OPERAND (t, 2)) == code
                   3257:              && (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0))
1.1.1.8 ! root     3258:                  == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 2), 0)))
        !          3259:              && ! (INTEGRAL_TYPE_P (TREE_TYPE (t))
        !          3260:                    && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0)))
        !          3261:                    && TYPE_PRECISION (TREE_TYPE (t)) <= BITS_PER_WORD))
1.1.1.4   root     3262:            t = build1 (code, type,
                   3263:                        build (COND_EXPR,
                   3264:                               TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0)),
                   3265:                               TREE_OPERAND (t, 0),
                   3266:                               TREE_OPERAND (TREE_OPERAND (t, 1), 0),
                   3267:                               TREE_OPERAND (TREE_OPERAND (t, 2), 0)));
                   3268:          return t;
                   3269:        }
1.1       root     3270:       else if (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<') 
                   3271:        return fold (build (COND_EXPR, type, arg0,
                   3272:                            fold (build1 (code, type, integer_one_node)),
                   3273:                            fold (build1 (code, type, integer_zero_node))));
                   3274:    }
1.1.1.6   root     3275:   else if (TREE_CODE_CLASS (code) == '2'
                   3276:           || TREE_CODE_CLASS (code) == '<')
1.1       root     3277:     {
                   3278:       if (TREE_CODE (arg1) == COMPOUND_EXPR)
                   3279:        return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
1.1.1.6   root     3280:                      fold (build (code, type,
                   3281:                                   arg0, TREE_OPERAND (arg1, 1))));
1.1       root     3282:       else if (TREE_CODE (arg1) == COND_EXPR
                   3283:               || TREE_CODE_CLASS (TREE_CODE (arg1)) == '<')
                   3284:        {
                   3285:          tree test, true_value, false_value;
                   3286: 
                   3287:          if (TREE_CODE (arg1) == COND_EXPR)
                   3288:            {
                   3289:              test = TREE_OPERAND (arg1, 0);
                   3290:              true_value = TREE_OPERAND (arg1, 1);
                   3291:              false_value = TREE_OPERAND (arg1, 2);
                   3292:            }
                   3293:          else
                   3294:            {
1.1.1.8 ! root     3295:              tree testtype = TREE_TYPE (arg1);
1.1       root     3296:              test = arg1;
1.1.1.8 ! root     3297:              true_value = convert (testtype, integer_one_node);
        !          3298:              false_value = convert (testtype, integer_zero_node);
1.1       root     3299:            }
                   3300: 
1.1.1.6   root     3301:          /* If ARG0 is complex we want to make sure we only evaluate
                   3302:             it once.  Though this is only required if it is volatile, it
                   3303:             might be more efficient even if it is not.  However, if we
                   3304:             succeed in folding one part to a constant, we do not need
                   3305:             to make this SAVE_EXPR.  Since we do this optimization
                   3306:             primarily to see if we do end up with constant and this
1.1.1.8 ! root     3307:             SAVE_EXPR interferes with later optimizations, suppressing
1.1.1.6   root     3308:             it when we can is important.  */
                   3309: 
1.1.1.7   root     3310:          if (TREE_CODE (arg0) != SAVE_EXPR
                   3311:              && ((TREE_CODE (arg0) != VAR_DECL
                   3312:                   && TREE_CODE (arg0) != PARM_DECL)
                   3313:                  || TREE_SIDE_EFFECTS (arg0)))
1.1.1.6   root     3314:            {
                   3315:              tree lhs = fold (build (code, type, arg0, true_value));
                   3316:              tree rhs = fold (build (code, type, arg0, false_value));
                   3317: 
                   3318:              if (TREE_CONSTANT (lhs) || TREE_CONSTANT (rhs))
                   3319:                return fold (build (COND_EXPR, type, test, lhs, rhs));
                   3320: 
                   3321:              arg0 = save_expr (arg0);
                   3322:            }
                   3323: 
1.1       root     3324:          test = fold (build (COND_EXPR, type, test,
                   3325:                              fold (build (code, type, arg0, true_value)),
                   3326:                              fold (build (code, type, arg0, false_value))));
                   3327:          if (TREE_CODE (arg0) == SAVE_EXPR)
                   3328:            return build (COMPOUND_EXPR, type,
1.1.1.7   root     3329:                          convert (void_type_node, arg0),
                   3330:                          strip_compound_expr (test, arg0));
1.1       root     3331:          else
                   3332:            return convert (type, test);
                   3333:        }
                   3334: 
                   3335:       else if (TREE_CODE (arg0) == COMPOUND_EXPR)
                   3336:        return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
                   3337:                      fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
                   3338:       else if (TREE_CODE (arg0) == COND_EXPR
                   3339:               || TREE_CODE_CLASS (TREE_CODE (arg0)) == '<')
                   3340:        {
                   3341:          tree test, true_value, false_value;
                   3342: 
                   3343:          if (TREE_CODE (arg0) == COND_EXPR)
                   3344:            {
                   3345:              test = TREE_OPERAND (arg0, 0);
                   3346:              true_value = TREE_OPERAND (arg0, 1);
                   3347:              false_value = TREE_OPERAND (arg0, 2);
                   3348:            }
                   3349:          else
                   3350:            {
1.1.1.8 ! root     3351:              tree testtype = TREE_TYPE (arg0);
1.1       root     3352:              test = arg0;
1.1.1.8 ! root     3353:              true_value = convert (testtype, integer_one_node);
        !          3354:              false_value = convert (testtype, integer_zero_node);
1.1       root     3355:            }
                   3356: 
1.1.1.7   root     3357:          if (TREE_CODE (arg1) != SAVE_EXPR
                   3358:              && ((TREE_CODE (arg1) != VAR_DECL
                   3359:                   && TREE_CODE (arg1) != PARM_DECL)
                   3360:                  || TREE_SIDE_EFFECTS (arg1)))
1.1.1.6   root     3361:            {
                   3362:              tree lhs = fold (build (code, type, true_value, arg1));
                   3363:              tree rhs = fold (build (code, type, false_value, arg1));
                   3364: 
1.1.1.7   root     3365:              if (TREE_CONSTANT (lhs) || TREE_CONSTANT (rhs)
                   3366:                  || TREE_CONSTANT (arg1))
1.1.1.6   root     3367:                return fold (build (COND_EXPR, type, test, lhs, rhs));
                   3368: 
                   3369:              arg1 = save_expr (arg1);
                   3370:            }
                   3371: 
1.1       root     3372:          test = fold (build (COND_EXPR, type, test,
                   3373:                              fold (build (code, type, true_value, arg1)),
                   3374:                              fold (build (code, type, false_value, arg1))));
                   3375:          if (TREE_CODE (arg1) == SAVE_EXPR)
                   3376:            return build (COMPOUND_EXPR, type,
1.1.1.7   root     3377:                          convert (void_type_node, arg1),
                   3378:                          strip_compound_expr (test, arg1));
1.1       root     3379:          else
                   3380:            return convert (type, test);
                   3381:        }
                   3382:     }
1.1.1.3   root     3383:   else if (TREE_CODE_CLASS (code) == '<'
                   3384:           && TREE_CODE (arg0) == COMPOUND_EXPR)
                   3385:     return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
                   3386:                  fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
                   3387:   else if (TREE_CODE_CLASS (code) == '<'
                   3388:           && TREE_CODE (arg1) == COMPOUND_EXPR)
                   3389:     return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
                   3390:                  fold (build (code, type, arg0, TREE_OPERAND (arg1, 1))));
1.1       root     3391:          
                   3392:   switch (code)
                   3393:     {
                   3394:     case INTEGER_CST:
                   3395:     case REAL_CST:
                   3396:     case STRING_CST:
                   3397:     case COMPLEX_CST:
                   3398:     case CONSTRUCTOR:
                   3399:       return t;
                   3400: 
                   3401:     case CONST_DECL:
                   3402:       return fold (DECL_INITIAL (t));
                   3403: 
                   3404:     case NOP_EXPR:
                   3405:     case FLOAT_EXPR:
                   3406:     case CONVERT_EXPR:
                   3407:     case FIX_TRUNC_EXPR:
                   3408:       /* Other kinds of FIX are not handled properly by fold_convert.  */
1.1.1.6   root     3409: 
1.1.1.8 ! root     3410:       if (TREE_TYPE (TREE_OPERAND (t, 0)) == TREE_TYPE (t))
        !          3411:        return TREE_OPERAND (t, 0);
        !          3412: 
        !          3413:       /* Handle cases of two conversions in a row.  */
        !          3414:       if (TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
        !          3415:          || TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)
        !          3416:        {
        !          3417:          tree inside_type = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
        !          3418:          tree inter_type = TREE_TYPE (TREE_OPERAND (t, 0));
        !          3419:          tree final_type = TREE_TYPE (t);
        !          3420:          int inside_int = INTEGRAL_TYPE_P (inside_type);
        !          3421:          int inside_ptr = POINTER_TYPE_P (inside_type);
        !          3422:          int inside_float = FLOAT_TYPE_P (inside_type);
        !          3423:          int inside_prec = TYPE_PRECISION (inside_type);
        !          3424:          int inside_unsignedp = TREE_UNSIGNED (inside_type);
        !          3425:          int inter_int = INTEGRAL_TYPE_P (inter_type);
        !          3426:          int inter_ptr = POINTER_TYPE_P (inter_type);
        !          3427:          int inter_float = FLOAT_TYPE_P (inter_type);
        !          3428:          int inter_prec = TYPE_PRECISION (inter_type);
        !          3429:          int inter_unsignedp = TREE_UNSIGNED (inter_type);
        !          3430:          int final_int = INTEGRAL_TYPE_P (final_type);
        !          3431:          int final_ptr = POINTER_TYPE_P (final_type);
        !          3432:          int final_float = FLOAT_TYPE_P (final_type);
        !          3433:          int final_prec = TYPE_PRECISION (final_type);
        !          3434:          int final_unsignedp = TREE_UNSIGNED (final_type);
        !          3435: 
        !          3436:          /* In addition to the cases of two conversions in a row 
        !          3437:             handled below, if we are converting something to its own
        !          3438:             type via an object of identical or wider precision, neither
        !          3439:             conversion is needed.  */
        !          3440:          if (inside_type == final_type
        !          3441:              && ((inter_int && final_int) || (inter_float && final_float))
        !          3442:              && inter_prec >= final_prec)
        !          3443:            return TREE_OPERAND (TREE_OPERAND (t, 0), 0);
        !          3444: 
        !          3445:          /* Likewise, if the intermediate and final types are either both
        !          3446:             float or both integer, we don't need the middle conversion if
        !          3447:             it is wider than the final type and doesn't change the signedness
        !          3448:             (for integers).  Avoid this if the final type is a pointer
        !          3449:             since then we sometimes need the inner conversion.  Likewise if
        !          3450:             the outer has a precision not equal to the size of its mode.  */
        !          3451:          if ((((inter_int || inter_ptr) && (inside_int || inside_ptr))
        !          3452:               || (inter_float && inside_float))
        !          3453:              && inter_prec >= inside_prec
        !          3454:              && (inter_float || inter_unsignedp == inside_unsignedp)
        !          3455:              && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (final_type))
        !          3456:                    && TYPE_MODE (final_type) == TYPE_MODE (inter_type))
        !          3457:              && ! final_ptr)
        !          3458:            return convert (final_type, TREE_OPERAND (TREE_OPERAND (t, 0), 0));
        !          3459: 
        !          3460:          /* Two conversions in a row are not needed unless:
        !          3461:             - some conversion is floating-point (overstrict for now), or
        !          3462:             - the intermediate type is narrower than both initial and
        !          3463:               final, or
        !          3464:             - the intermediate type and innermost type differ in signedness,
        !          3465:               and the outermost type is wider than the intermediate, or
        !          3466:             - the initial type is a pointer type and the precisions of the
        !          3467:               intermediate and final types differ, or
        !          3468:             - the final type is a pointer type and the precisions of the 
        !          3469:               initial and intermediate types differ.  */
        !          3470:          if (! inside_float && ! inter_float && ! final_float
        !          3471:              && (inter_prec > inside_prec || inter_prec > final_prec)
        !          3472:              && ! (inside_int && inter_int
        !          3473:                    && inter_unsignedp != inside_unsignedp
        !          3474:                    && inter_prec < final_prec)
        !          3475:              && ((inter_unsignedp && inter_prec > inside_prec)
        !          3476:                  == (final_unsignedp && final_prec > inter_prec))
        !          3477:              && ! (inside_ptr && inter_prec != final_prec)
        !          3478:              && ! (final_ptr && inside_prec != inter_prec)
        !          3479:              && ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (final_type))
        !          3480:                    && TYPE_MODE (final_type) == TYPE_MODE (inter_type))
        !          3481:              && ! final_ptr)
        !          3482:            return convert (final_type, TREE_OPERAND (TREE_OPERAND (t, 0), 0));
        !          3483:        }
1.1       root     3484: 
                   3485:       if (TREE_CODE (TREE_OPERAND (t, 0)) == MODIFY_EXPR
1.1.1.3   root     3486:          && TREE_CONSTANT (TREE_OPERAND (TREE_OPERAND (t, 0), 1))
                   3487:          /* Detect assigning a bitfield.  */
                   3488:          && !(TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) == COMPONENT_REF
                   3489:               && DECL_BIT_FIELD (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 0), 0), 1))))
1.1       root     3490:        {
1.1.1.3   root     3491:          /* Don't leave an assignment inside a conversion
1.1.1.4   root     3492:             unless assigning a bitfield.  */
1.1       root     3493:          tree prev = TREE_OPERAND (t, 0);
                   3494:          TREE_OPERAND (t, 0) = TREE_OPERAND (prev, 1);
                   3495:          /* First do the assignment, then return converted constant.  */
                   3496:          t = build (COMPOUND_EXPR, TREE_TYPE (t), prev, fold (t));
                   3497:          TREE_USED (t) = 1;
                   3498:          return t;
                   3499:        }
                   3500:       if (!wins)
                   3501:        {
                   3502:          TREE_CONSTANT (t) = TREE_CONSTANT (arg0);
                   3503:          return t;
                   3504:        }
                   3505:       return fold_convert (t, arg0);
                   3506: 
                   3507: #if 0  /* This loses on &"foo"[0].  */
                   3508:     case ARRAY_REF:
                   3509:        {
                   3510:          int i;
                   3511: 
                   3512:          /* Fold an expression like: "foo"[2] */
                   3513:          if (TREE_CODE (arg0) == STRING_CST
                   3514:              && TREE_CODE (arg1) == INTEGER_CST
                   3515:              && !TREE_INT_CST_HIGH (arg1)
                   3516:              && (i = TREE_INT_CST_LOW (arg1)) < TREE_STRING_LENGTH (arg0))
                   3517:            {
                   3518:              t = build_int_2 (TREE_STRING_POINTER (arg0)[i], 0);
                   3519:              TREE_TYPE (t) = TREE_TYPE (TREE_TYPE (arg0));
1.1.1.5   root     3520:              force_fit_type (t, 0);
1.1       root     3521:            }
                   3522:        }
                   3523:       return t;
                   3524: #endif /* 0 */
                   3525: 
1.1.1.7   root     3526:     case COMPONENT_REF:
                   3527:       if (TREE_CODE (arg0) == CONSTRUCTOR)
                   3528:        {
                   3529:          tree m = purpose_member (arg1, CONSTRUCTOR_ELTS (arg0));
                   3530:          if (m)
                   3531:            t = TREE_VALUE (m);
                   3532:        }
                   3533:       return t;
                   3534: 
1.1       root     3535:     case RANGE_EXPR:
                   3536:       TREE_CONSTANT (t) = wins;
                   3537:       return t;
                   3538: 
                   3539:     case NEGATE_EXPR:
                   3540:       if (wins)
                   3541:        {
                   3542:          if (TREE_CODE (arg0) == INTEGER_CST)
                   3543:            {
1.1.1.4   root     3544:              HOST_WIDE_INT low, high;
                   3545:              int overflow = neg_double (TREE_INT_CST_LOW (arg0),
                   3546:                                         TREE_INT_CST_HIGH (arg0),
                   3547:                                         &low, &high);
                   3548:              t = build_int_2 (low, high);
1.1       root     3549:              TREE_TYPE (t) = type;
1.1.1.6   root     3550:              TREE_OVERFLOW (t)
                   3551:                = (TREE_OVERFLOW (arg0)
1.1.1.5   root     3552:                   | force_fit_type (t, overflow));
1.1.1.6   root     3553:              TREE_CONSTANT_OVERFLOW (t)
                   3554:                = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0);
1.1       root     3555:            }
                   3556:          else if (TREE_CODE (arg0) == REAL_CST)
                   3557:            t = build_real (type, REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
                   3558:          TREE_TYPE (t) = type;
                   3559:        }
                   3560:       else if (TREE_CODE (arg0) == NEGATE_EXPR)
                   3561:        return TREE_OPERAND (arg0, 0);
                   3562: 
                   3563:       /* Convert - (a - b) to (b - a) for non-floating-point.  */
1.1.1.5   root     3564:       else if (TREE_CODE (arg0) == MINUS_EXPR && ! FLOAT_TYPE_P (type))
1.1       root     3565:        return build (MINUS_EXPR, type, TREE_OPERAND (arg0, 1),
                   3566:                      TREE_OPERAND (arg0, 0));
                   3567: 
                   3568:       return t;
                   3569: 
                   3570:     case ABS_EXPR:
                   3571:       if (wins)
                   3572:        {
                   3573:          if (TREE_CODE (arg0) == INTEGER_CST)
                   3574:            {
                   3575:              if (! TREE_UNSIGNED (type)
                   3576:                  && TREE_INT_CST_HIGH (arg0) < 0)
                   3577:                {
1.1.1.4   root     3578:                  HOST_WIDE_INT low, high;
                   3579:                  int overflow = neg_double (TREE_INT_CST_LOW (arg0),
                   3580:                                             TREE_INT_CST_HIGH (arg0),
                   3581:                                             &low, &high);
                   3582:                  t = build_int_2 (low, high);
                   3583:                  TREE_TYPE (t) = type;
1.1.1.6   root     3584:                  TREE_OVERFLOW (t)
                   3585:                    = (TREE_OVERFLOW (arg0)
1.1.1.5   root     3586:                       | force_fit_type (t, overflow));
1.1.1.6   root     3587:                  TREE_CONSTANT_OVERFLOW (t)
                   3588:                    = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0);
1.1       root     3589:                }
                   3590:            }
                   3591:          else if (TREE_CODE (arg0) == REAL_CST)
                   3592:            {
1.1.1.3   root     3593:              if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg0)))
1.1       root     3594:                t = build_real (type,
                   3595:                                REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
                   3596:            }
                   3597:          TREE_TYPE (t) = type;
                   3598:        }
                   3599:       else if (TREE_CODE (arg0) == ABS_EXPR || TREE_CODE (arg0) == NEGATE_EXPR)
                   3600:        return build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0));
                   3601:       return t;
                   3602: 
1.1.1.6   root     3603:     case CONJ_EXPR:
                   3604:       if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
                   3605:        return arg0;
                   3606:       else if (TREE_CODE (arg0) == COMPLEX_EXPR)
                   3607:        return build (COMPLEX_EXPR, TREE_TYPE (arg0),
                   3608:                      TREE_OPERAND (arg0, 0),
                   3609:                      fold (build1 (NEGATE_EXPR,
                   3610:                                    TREE_TYPE (TREE_TYPE (arg0)),
                   3611:                                    TREE_OPERAND (arg0, 1))));
                   3612:       else if (TREE_CODE (arg0) == COMPLEX_CST)
                   3613:        return build_complex (TREE_OPERAND (arg0, 0),
                   3614:                              fold (build1 (NEGATE_EXPR,
                   3615:                                            TREE_TYPE (TREE_TYPE (arg0)),
                   3616:                                            TREE_OPERAND (arg0, 1))));
                   3617:       else if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
                   3618:        return fold (build (TREE_CODE (arg0), type,
                   3619:                            fold (build1 (CONJ_EXPR, type,
                   3620:                                          TREE_OPERAND (arg0, 0))),
                   3621:                            fold (build1 (CONJ_EXPR,
                   3622:                                          type, TREE_OPERAND (arg0, 1)))));
                   3623:       else if (TREE_CODE (arg0) == CONJ_EXPR)
                   3624:        return TREE_OPERAND (arg0, 0);
                   3625:       return t;
                   3626: 
1.1       root     3627:     case BIT_NOT_EXPR:
                   3628:       if (wins)
                   3629:        {
                   3630:          if (TREE_CODE (arg0) == INTEGER_CST)
                   3631:            t = build_int_2 (~ TREE_INT_CST_LOW (arg0),
                   3632:                             ~ TREE_INT_CST_HIGH (arg0));
                   3633:          TREE_TYPE (t) = type;
1.1.1.5   root     3634:          force_fit_type (t, 0);
1.1.1.6   root     3635:          TREE_OVERFLOW (t) = TREE_OVERFLOW (arg0);
1.1.1.4   root     3636:          TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (arg0);
1.1       root     3637:        }
                   3638:       else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
                   3639:        return TREE_OPERAND (arg0, 0);
                   3640:       return t;
                   3641: 
                   3642:     case PLUS_EXPR:
                   3643:       /* A + (-B) -> A - B */
                   3644:       if (TREE_CODE (arg1) == NEGATE_EXPR)
                   3645:        return fold (build (MINUS_EXPR, type, arg0, TREE_OPERAND (arg1, 0)));
1.1.1.5   root     3646:       else if (! FLOAT_TYPE_P (type))
1.1       root     3647:        {
                   3648:          if (integer_zerop (arg1))
                   3649:            return non_lvalue (convert (type, arg0));
                   3650: 
                   3651:          /* If we are adding two BIT_AND_EXPR's, both of which are and'ing
                   3652:             with a constant, and the two constants have no bits in common,
                   3653:             we should treat this as a BIT_IOR_EXPR since this may produce more
                   3654:             simplifications.  */
                   3655:          if (TREE_CODE (arg0) == BIT_AND_EXPR
                   3656:              && TREE_CODE (arg1) == BIT_AND_EXPR
                   3657:              && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
                   3658:              && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
                   3659:              && integer_zerop (const_binop (BIT_AND_EXPR,
                   3660:                                             TREE_OPERAND (arg0, 1),
1.1.1.5   root     3661:                                             TREE_OPERAND (arg1, 1), 0)))
1.1       root     3662:            {
                   3663:              code = BIT_IOR_EXPR;
                   3664:              goto bit_ior;
                   3665:            }
1.1.1.6   root     3666: 
                   3667:          /* (A * C) + (B * C) -> (A+B) * C.  Since we are most concerned
                   3668:             about the case where C is a constant, just try one of the
                   3669:             four possibilities.  */
                   3670: 
                   3671:          if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR
                   3672:              && operand_equal_p (TREE_OPERAND (arg0, 1),
                   3673:                                  TREE_OPERAND (arg1, 1), 0))
                   3674:            return fold (build (MULT_EXPR, type,
                   3675:                                fold (build (PLUS_EXPR, type,
                   3676:                                             TREE_OPERAND (arg0, 0),
                   3677:                                             TREE_OPERAND (arg1, 0))),
                   3678:                                TREE_OPERAND (arg0, 1)));
1.1       root     3679:        }
                   3680:       /* In IEEE floating point, x+0 may not equal x.  */
1.1.1.7   root     3681:       else if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
                   3682:                || flag_fast_math)
1.1       root     3683:               && real_zerop (arg1))
                   3684:        return non_lvalue (convert (type, arg0));
                   3685:     associate:
                   3686:       /* In most languages, can't associate operations on floats
                   3687:         through parentheses.  Rather than remember where the parentheses
1.1.1.7   root     3688:         were, we don't associate floats at all.  It shouldn't matter much.
                   3689:         However, associating multiplications is only very slightly
                   3690:         inaccurate, so do that if -ffast-math is specified.  */
                   3691:       if (FLOAT_TYPE_P (type)
                   3692:          && ! (flag_fast_math && code == MULT_EXPR))
1.1       root     3693:        goto binary;
1.1.1.7   root     3694: 
1.1       root     3695:       /* The varsign == -1 cases happen only for addition and subtraction.
                   3696:         It says that the arg that was split was really CON minus VAR.
                   3697:         The rest of the code applies to all associative operations.  */
                   3698:       if (!wins)
                   3699:        {
1.1.1.3   root     3700:          tree var, con;
1.1       root     3701:          int varsign;
                   3702: 
                   3703:          if (split_tree (arg0, code, &var, &con, &varsign))
                   3704:            {
                   3705:              if (varsign == -1)
                   3706:                {
                   3707:                  /* EXPR is (CON-VAR) +- ARG1.  */
                   3708:                  /* If it is + and VAR==ARG1, return just CONST.  */
                   3709:                  if (code == PLUS_EXPR && operand_equal_p (var, arg1, 0))
                   3710:                    return convert (TREE_TYPE (t), con);
                   3711:                    
1.1.1.5   root     3712:                  /* If ARG0 is a constant, don't change things around;
                   3713:                     instead keep all the constant computations together.  */
                   3714: 
                   3715:                  if (TREE_CONSTANT (arg0))
                   3716:                    return t;
                   3717: 
1.1       root     3718:                  /* Otherwise return (CON +- ARG1) - VAR.  */
1.1.1.8 ! root     3719:                  t = build (MINUS_EXPR, type,
        !          3720:                             fold (build (code, type, con, arg1)), var);
1.1       root     3721:                }
                   3722:              else
                   3723:                {
                   3724:                  /* EXPR is (VAR+CON) +- ARG1.  */
                   3725:                  /* If it is - and VAR==ARG1, return just CONST.  */
                   3726:                  if (code == MINUS_EXPR && operand_equal_p (var, arg1, 0))
                   3727:                    return convert (TREE_TYPE (t), con);
                   3728:                    
1.1.1.5   root     3729:                  /* If ARG0 is a constant, don't change things around;
                   3730:                     instead keep all the constant computations together.  */
                   3731: 
                   3732:                  if (TREE_CONSTANT (arg0))
                   3733:                    return t;
                   3734: 
1.1       root     3735:                  /* Otherwise return VAR +- (ARG1 +- CON).  */
1.1.1.8 ! root     3736:                  tem = fold (build (code, type, arg1, con));
        !          3737:                  t = build (code, type, var, tem);
        !          3738: 
1.1       root     3739:                  if (integer_zerop (tem)
                   3740:                      && (code == PLUS_EXPR || code == MINUS_EXPR))
                   3741:                    return convert (type, var);
                   3742:                  /* If we have x +/- (c - d) [c an explicit integer]
                   3743:                     change it to x -/+ (d - c) since if d is relocatable
                   3744:                     then the latter can be a single immediate insn
                   3745:                     and the former cannot.  */
                   3746:                  if (TREE_CODE (tem) == MINUS_EXPR
                   3747:                      && TREE_CODE (TREE_OPERAND (tem, 0)) == INTEGER_CST)
                   3748:                    {
                   3749:                      tree tem1 = TREE_OPERAND (tem, 1);
                   3750:                      TREE_OPERAND (tem, 1) = TREE_OPERAND (tem, 0);
                   3751:                      TREE_OPERAND (tem, 0) = tem1;
                   3752:                      TREE_SET_CODE (t,
                   3753:                                     (code == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR));
                   3754:                    }
                   3755:                }
                   3756:              return t;
                   3757:            }
                   3758: 
                   3759:          if (split_tree (arg1, code, &var, &con, &varsign))
                   3760:            {
1.1.1.6   root     3761:              if (TREE_CONSTANT (arg1))
                   3762:                return t;
                   3763: 
                   3764:              if (varsign == -1)
                   3765:                TREE_SET_CODE (t,
                   3766:                               (code == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR));
                   3767: 
1.1       root     3768:              /* EXPR is ARG0 +- (CON +- VAR).  */
                   3769:              if (TREE_CODE (t) == MINUS_EXPR
                   3770:                  && operand_equal_p (var, arg0, 0))
                   3771:                {
                   3772:                  /* If VAR and ARG0 cancel, return just CON or -CON.  */
                   3773:                  if (code == PLUS_EXPR)
                   3774:                    return convert (TREE_TYPE (t), con);
                   3775:                  return fold (build1 (NEGATE_EXPR, TREE_TYPE (t),
                   3776:                                       convert (TREE_TYPE (t), con)));
                   3777:                }
1.1.1.6   root     3778: 
1.1.1.8 ! root     3779:              t = build (TREE_CODE (t), type,
        !          3780:                         fold (build (code, TREE_TYPE (t), arg0, con)), var);
        !          3781: 
1.1       root     3782:              if (integer_zerop (TREE_OPERAND (t, 0))
                   3783:                  && TREE_CODE (t) == PLUS_EXPR)
                   3784:                return convert (TREE_TYPE (t), var);
                   3785:              return t;
                   3786:            }
                   3787:        }
                   3788:     binary:
                   3789: #if defined (REAL_IS_NOT_DOUBLE) && ! defined (REAL_ARITHMETIC)
                   3790:       if (TREE_CODE (arg1) == REAL_CST)
                   3791:        return t;
                   3792: #endif /* REAL_IS_NOT_DOUBLE, and no REAL_ARITHMETIC */
                   3793:       if (wins)
1.1.1.5   root     3794:        t1 = const_binop (code, arg0, arg1, 0);
1.1       root     3795:       if (t1 != NULL_TREE)
                   3796:        {
                   3797:          /* The return value should always have
                   3798:             the same type as the original expression.  */
                   3799:          TREE_TYPE (t1) = TREE_TYPE (t);
                   3800:          return t1;
                   3801:        }
                   3802:       return t;
                   3803: 
                   3804:     case MINUS_EXPR:
1.1.1.5   root     3805:       if (! FLOAT_TYPE_P (type))
1.1       root     3806:        {
                   3807:          if (! wins && integer_zerop (arg0))
                   3808:            return build1 (NEGATE_EXPR, type, arg1);
                   3809:          if (integer_zerop (arg1))
                   3810:            return non_lvalue (convert (type, arg0));
1.1.1.6   root     3811: 
                   3812:          /* (A * C) - (B * C) -> (A-B) * C.  Since we are most concerned
                   3813:             about the case where C is a constant, just try one of the
                   3814:             four possibilities.  */
                   3815: 
                   3816:          if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR
                   3817:              && operand_equal_p (TREE_OPERAND (arg0, 1),
                   3818:                                  TREE_OPERAND (arg1, 1), 0))
                   3819:            return fold (build (MULT_EXPR, type,
                   3820:                                fold (build (MINUS_EXPR, type,
                   3821:                                             TREE_OPERAND (arg0, 0),
                   3822:                                             TREE_OPERAND (arg1, 0))),
                   3823:                                TREE_OPERAND (arg0, 1)));
1.1       root     3824:        }
                   3825:       /* Convert A - (-B) to A + B.  */
                   3826:       else if (TREE_CODE (arg1) == NEGATE_EXPR)
                   3827:        return fold (build (PLUS_EXPR, type, arg0, TREE_OPERAND (arg1, 0)));
1.1.1.7   root     3828: 
                   3829:       else if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
                   3830:               || flag_fast_math)
1.1       root     3831:        {
1.1.1.3   root     3832:          /* Except with IEEE floating point, 0-x equals -x.  */
1.1       root     3833:          if (! wins && real_zerop (arg0))
                   3834:            return build1 (NEGATE_EXPR, type, arg1);
1.1.1.3   root     3835:          /* Except with IEEE floating point, x-0 equals x.  */
                   3836:          if (real_zerop (arg1))
1.1       root     3837:            return non_lvalue (convert (type, arg0));
1.1.1.7   root     3838:        }
1.1.1.3   root     3839: 
1.1.1.7   root     3840:       /* Fold &x - &x.  This can happen from &x.foo - &x. 
                   3841:         This is unsafe for certain floats even in non-IEEE formats.
                   3842:         In IEEE, it is unsafe because it does wrong for NaNs.
                   3843:         Also note that operand_equal_p is always false if an operand
                   3844:         is volatile.  */
                   3845: 
                   3846:       if ((! FLOAT_TYPE_P (type) || flag_fast_math)
                   3847:          && operand_equal_p (arg0, arg1, 0))
                   3848:        return convert (type, integer_zero_node);
1.1.1.3   root     3849: 
1.1       root     3850:       goto associate;
                   3851: 
                   3852:     case MULT_EXPR:
1.1.1.5   root     3853:       if (! FLOAT_TYPE_P (type))
1.1       root     3854:        {
                   3855:          if (integer_zerop (arg1))
                   3856:            return omit_one_operand (type, arg1, arg0);
                   3857:          if (integer_onep (arg1))
                   3858:            return non_lvalue (convert (type, arg0));
                   3859: 
1.1.1.7   root     3860:          /* ((A / C) * C) is A if the division is an
                   3861:             EXACT_DIV_EXPR.   Since C is normally a constant,
                   3862:             just check for one of the four possibilities.  */
                   3863: 
                   3864:          if (TREE_CODE (arg0) == EXACT_DIV_EXPR
                   3865:              && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
                   3866:            return TREE_OPERAND (arg0, 0);
                   3867: 
1.1       root     3868:          /* (a * (1 << b)) is (a << b)  */
                   3869:          if (TREE_CODE (arg1) == LSHIFT_EXPR
                   3870:              && integer_onep (TREE_OPERAND (arg1, 0)))
                   3871:            return fold (build (LSHIFT_EXPR, type, arg0,
                   3872:                                TREE_OPERAND (arg1, 1)));
                   3873:          if (TREE_CODE (arg0) == LSHIFT_EXPR
                   3874:              && integer_onep (TREE_OPERAND (arg0, 0)))
                   3875:            return fold (build (LSHIFT_EXPR, type, arg1,
                   3876:                                TREE_OPERAND (arg0, 1)));
                   3877:        }
                   3878:       else
                   3879:        {
1.1.1.3   root     3880:          /* x*0 is 0, except for IEEE floating point.  */
1.1.1.7   root     3881:          if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
                   3882:               || flag_fast_math)
1.1       root     3883:              && real_zerop (arg1))
                   3884:            return omit_one_operand (type, arg1, arg0);
1.1.1.3   root     3885:          /* In IEEE floating point, x*1 is not equivalent to x for snans.
1.1       root     3886:             However, ANSI says we can drop signals,
                   3887:             so we can do this anyway.  */
                   3888:          if (real_onep (arg1))
                   3889:            return non_lvalue (convert (type, arg0));
                   3890:          /* x*2 is x+x */
                   3891:          if (! wins && real_twop (arg1))
                   3892:            {
                   3893:              tree arg = save_expr (arg0);
                   3894:              return build (PLUS_EXPR, type, arg, arg);
                   3895:            }
                   3896:        }
                   3897:       goto associate;
                   3898: 
                   3899:     case BIT_IOR_EXPR:
                   3900:     bit_ior:
                   3901:       if (integer_all_onesp (arg1))
                   3902:        return omit_one_operand (type, arg1, arg0);
                   3903:       if (integer_zerop (arg1))
                   3904:        return non_lvalue (convert (type, arg0));
                   3905:       t1 = distribute_bit_expr (code, type, arg0, arg1);
                   3906:       if (t1 != NULL_TREE)
                   3907:        return t1;
1.1.1.5   root     3908: 
                   3909:       /* (a << C1) | (a >> C2) if A is unsigned and C1+C2 is the size of A
                   3910:         is a rotate of A by C1 bits.  */
                   3911: 
                   3912:       if ((TREE_CODE (arg0) == RSHIFT_EXPR
                   3913:           || TREE_CODE (arg0) == LSHIFT_EXPR)
                   3914:          && (TREE_CODE (arg1) == RSHIFT_EXPR
                   3915:              || TREE_CODE (arg1) == LSHIFT_EXPR)
                   3916:          && TREE_CODE (arg0) != TREE_CODE (arg1)
                   3917:          && operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1,0), 0)
                   3918:          && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0)))
                   3919:          && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
                   3920:          && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
                   3921:          && TREE_INT_CST_HIGH (TREE_OPERAND (arg0, 1)) == 0
                   3922:          && TREE_INT_CST_HIGH (TREE_OPERAND (arg1, 1)) == 0
                   3923:          && ((TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1))
                   3924:               + TREE_INT_CST_LOW (TREE_OPERAND (arg1, 1)))
                   3925:              == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))))
                   3926:        return build (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0),
                   3927:                      TREE_CODE (arg0) == LSHIFT_EXPR
                   3928:                      ? TREE_OPERAND (arg0, 1) : TREE_OPERAND (arg1, 1));
                   3929: 
1.1       root     3930:       goto associate;
                   3931: 
                   3932:     case BIT_XOR_EXPR:
                   3933:       if (integer_zerop (arg1))
                   3934:        return non_lvalue (convert (type, arg0));
                   3935:       if (integer_all_onesp (arg1))
                   3936:        return fold (build1 (BIT_NOT_EXPR, type, arg0));
                   3937:       goto associate;
                   3938: 
                   3939:     case BIT_AND_EXPR:
                   3940:     bit_and:
                   3941:       if (integer_all_onesp (arg1))
                   3942:        return non_lvalue (convert (type, arg0));
                   3943:       if (integer_zerop (arg1))
                   3944:        return omit_one_operand (type, arg1, arg0);
                   3945:       t1 = distribute_bit_expr (code, type, arg0, arg1);
                   3946:       if (t1 != NULL_TREE)
                   3947:        return t1;
                   3948:       /* Simplify ((int)c & 0x377) into (int)c, if c is unsigned char.  */
                   3949:       if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == NOP_EXPR
                   3950:          && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg1, 0))))
                   3951:        {
                   3952:          int prec = TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg1, 0)));
1.1.1.4   root     3953:          if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_WIDE_INT
                   3954:              && (~TREE_INT_CST_LOW (arg0)
                   3955:                  & (((HOST_WIDE_INT) 1 << prec) - 1)) == 0)
1.1       root     3956:            return build1 (NOP_EXPR, type, TREE_OPERAND (arg1, 0));
                   3957:        }
                   3958:       if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) == NOP_EXPR
                   3959:          && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
                   3960:        {
                   3961:          int prec = TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)));
1.1.1.4   root     3962:          if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_WIDE_INT
                   3963:              && (~TREE_INT_CST_LOW (arg1)
                   3964:                  & (((HOST_WIDE_INT) 1 << prec) - 1)) == 0)
1.1       root     3965:            return build1 (NOP_EXPR, type, TREE_OPERAND (arg0, 0));
                   3966:        }
                   3967:       goto associate;
                   3968: 
                   3969:     case BIT_ANDTC_EXPR:
                   3970:       if (integer_all_onesp (arg0))
                   3971:        return non_lvalue (convert (type, arg1));
                   3972:       if (integer_zerop (arg0))
                   3973:        return omit_one_operand (type, arg0, arg1);
                   3974:       if (TREE_CODE (arg1) == INTEGER_CST)
                   3975:        {
                   3976:          arg1 = fold (build1 (BIT_NOT_EXPR, type, arg1));
                   3977:          code = BIT_AND_EXPR;
                   3978:          goto bit_and;
                   3979:        }
                   3980:       goto binary;
                   3981: 
1.1.1.7   root     3982:     case RDIV_EXPR:
                   3983:       /* In most cases, do nothing with a divide by zero.  */
                   3984: #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
                   3985: #ifndef REAL_INFINITY
                   3986:       if (TREE_CODE (arg1) == REAL_CST && real_zerop (arg1))
                   3987:        return t;
                   3988: #endif
                   3989: #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
                   3990: 
                   3991:       /* In IEEE floating point, x/1 is not equivalent to x for snans.
                   3992:         However, ANSI says we can drop signals, so we can do this anyway.  */
                   3993:       if (real_onep (arg1))
                   3994:        return non_lvalue (convert (type, arg0));
                   3995: 
                   3996:       /* If ARG1 is a constant, we can convert this to a multiply by the
                   3997:         reciprocal.  This does not have the same rounding properties,
                   3998:         so only do this if -ffast-math.  We can actually always safely
                   3999:         do it if ARG1 is a power of two, but it's hard to tell if it is
                   4000:         or not in a portable manner.  */
                   4001:       if (TREE_CODE (arg1) == REAL_CST && flag_fast_math
                   4002:          && 0 != (tem = const_binop (code, build_real (type, dconst1),
                   4003:                                      arg1, 0)))
                   4004:        return fold (build (MULT_EXPR, type, arg0, tem));
                   4005: 
                   4006:       goto binary;
                   4007: 
1.1       root     4008:     case TRUNC_DIV_EXPR:
                   4009:     case ROUND_DIV_EXPR:
                   4010:     case FLOOR_DIV_EXPR:
                   4011:     case CEIL_DIV_EXPR:
                   4012:     case EXACT_DIV_EXPR:
                   4013:       if (integer_onep (arg1))
                   4014:        return non_lvalue (convert (type, arg0));
                   4015:       if (integer_zerop (arg1))
                   4016:        return t;
1.1.1.3   root     4017: 
1.1.1.7   root     4018:       /* If we have ((a / C1) / C2) where both division are the same type, try
                   4019:         to simplify.  First see if C1 * C2 overflows or not.  */
                   4020:       if (TREE_CODE (arg0) == code && TREE_CODE (arg1) == INTEGER_CST
                   4021:          && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
                   4022:        {
                   4023:          tree new_divisor;
                   4024: 
                   4025:          new_divisor = const_binop (MULT_EXPR, TREE_OPERAND (arg0, 1), arg1, 0);
                   4026:          tem = const_binop (FLOOR_DIV_EXPR, new_divisor, arg1, 0);
                   4027: 
                   4028:          if (TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) == TREE_INT_CST_LOW (tem)
                   4029:              && TREE_INT_CST_HIGH (TREE_OPERAND (arg0, 1)) == TREE_INT_CST_HIGH (tem))
                   4030:            {
                   4031:              /* If no overflow, divide by C1*C2.  */
                   4032:              return fold (build (code, type, TREE_OPERAND (arg0, 0), new_divisor));
                   4033:            }
                   4034:        }
                   4035: 
1.1.1.6   root     4036:       /* Look for ((a * C1) / C3) or (((a * C1) + C2) / C3),
                   4037:         where C1 % C3 == 0 or C3 % C1 == 0.  We can simplify these
                   4038:         expressions, which often appear in the offsets or sizes of
                   4039:         objects with a varying size.  Only deal with positive divisors
                   4040:         and multiplicands.   If C2 is negative, we must have C2 % C3 == 0.
                   4041: 
                   4042:         Look for NOPs and SAVE_EXPRs inside.  */
                   4043: 
1.1.1.3   root     4044:       if (TREE_CODE (arg1) == INTEGER_CST
1.1.1.7   root     4045:          && tree_int_cst_sgn (arg1) >= 0)
1.1.1.3   root     4046:        {
1.1.1.6   root     4047:          int have_save_expr = 0;
                   4048:          tree c2 = integer_zero_node;
                   4049:          tree xarg0 = arg0;
                   4050: 
                   4051:          if (TREE_CODE (xarg0) == SAVE_EXPR)
                   4052:            have_save_expr = 1, xarg0 = TREE_OPERAND (xarg0, 0);
                   4053: 
                   4054:          STRIP_NOPS (xarg0);
                   4055: 
                   4056:          if (TREE_CODE (xarg0) == PLUS_EXPR
                   4057:              && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST)
                   4058:            c2 = TREE_OPERAND (xarg0, 1), xarg0 = TREE_OPERAND (xarg0, 0);
                   4059:          else if (TREE_CODE (xarg0) == MINUS_EXPR
                   4060:                   && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST
                   4061:                   /* If we are doing this computation unsigned, the negate
                   4062:                      is incorrect.  */
                   4063:                   && ! TREE_UNSIGNED (type))
                   4064:            {
                   4065:              c2 = fold (build1 (NEGATE_EXPR, type, TREE_OPERAND (xarg0, 1)));
                   4066:              xarg0 = TREE_OPERAND (xarg0, 0);
                   4067:            }
1.1.1.3   root     4068: 
1.1.1.6   root     4069:          if (TREE_CODE (xarg0) == SAVE_EXPR)
                   4070:            have_save_expr = 1, xarg0 = TREE_OPERAND (xarg0, 0);
1.1.1.3   root     4071: 
1.1.1.6   root     4072:          STRIP_NOPS (xarg0);
                   4073: 
                   4074:          if (TREE_CODE (xarg0) == MULT_EXPR
                   4075:              && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST
1.1.1.7   root     4076:              && tree_int_cst_sgn (TREE_OPERAND (xarg0, 1)) >= 0
1.1.1.6   root     4077:              && (integer_zerop (const_binop (TRUNC_MOD_EXPR,
                   4078:                                              TREE_OPERAND (xarg0, 1), arg1, 1))
                   4079:                  || integer_zerop (const_binop (TRUNC_MOD_EXPR, arg1,
                   4080:                                                 TREE_OPERAND (xarg0, 1), 1)))
1.1.1.7   root     4081:              && (tree_int_cst_sgn (c2) >= 0
1.1.1.6   root     4082:                  || integer_zerop (const_binop (TRUNC_MOD_EXPR, c2,
                   4083:                                                 arg1, 1))))
                   4084:            {
                   4085:              tree outer_div = integer_one_node;
                   4086:              tree c1 = TREE_OPERAND (xarg0, 1);
                   4087:              tree c3 = arg1;
                   4088: 
                   4089:              /* If C3 > C1, set them equal and do a divide by
                   4090:                 C3/C1 at the end of the operation.  */
                   4091:              if (tree_int_cst_lt (c1, c3))
                   4092:                outer_div = const_binop (code, c3, c1, 0), c3 = c1;
                   4093:                
                   4094:              /* The result is A * (C1/C3) + (C2/C3).  */
                   4095:              t = fold (build (PLUS_EXPR, type,
                   4096:                               fold (build (MULT_EXPR, type,
                   4097:                                            TREE_OPERAND (xarg0, 0),
                   4098:                                            const_binop (code, c1, c3, 1))),
                   4099:                               const_binop (code, c2, c3, 1)));
                   4100: 
                   4101:              if (! integer_onep (outer_div))
1.1.1.7   root     4102:                t = fold (build (code, type, t, convert (type, outer_div)));
1.1.1.6   root     4103: 
                   4104:              if (have_save_expr)
                   4105:                t = save_expr (t);
                   4106: 
                   4107:              return t;
                   4108:            }
1.1.1.3   root     4109:        }
                   4110: 
1.1       root     4111:       goto binary;
                   4112: 
                   4113:     case CEIL_MOD_EXPR:
                   4114:     case FLOOR_MOD_EXPR:
                   4115:     case ROUND_MOD_EXPR:
                   4116:     case TRUNC_MOD_EXPR:
                   4117:       if (integer_onep (arg1))
                   4118:        return omit_one_operand (type, integer_zero_node, arg0);
                   4119:       if (integer_zerop (arg1))
                   4120:        return t;
1.1.1.6   root     4121: 
                   4122:       /* Look for ((a * C1) % C3) or (((a * C1) + C2) % C3),
                   4123:         where C1 % C3 == 0.  Handle similarly to the division case,
                   4124:         but don't bother with SAVE_EXPRs.  */
                   4125: 
                   4126:       if (TREE_CODE (arg1) == INTEGER_CST
                   4127:          && ! integer_zerop (arg1))
                   4128:        {
                   4129:          tree c2 = integer_zero_node;
                   4130:          tree xarg0 = arg0;
                   4131: 
                   4132:          if (TREE_CODE (xarg0) == PLUS_EXPR
                   4133:              && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST)
                   4134:            c2 = TREE_OPERAND (xarg0, 1), xarg0 = TREE_OPERAND (xarg0, 0);
                   4135:          else if (TREE_CODE (xarg0) == MINUS_EXPR
                   4136:                   && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST
                   4137:                   && ! TREE_UNSIGNED (type))
                   4138:            {
                   4139:              c2 = fold (build1 (NEGATE_EXPR, type, TREE_OPERAND (xarg0, 1)));
                   4140:              xarg0 = TREE_OPERAND (xarg0, 0);
                   4141:            }
                   4142: 
                   4143:          STRIP_NOPS (xarg0);
                   4144: 
                   4145:          if (TREE_CODE (xarg0) == MULT_EXPR
                   4146:              && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST
                   4147:              && integer_zerop (const_binop (TRUNC_MOD_EXPR,
                   4148:                                             TREE_OPERAND (xarg0, 1),
                   4149:                                             arg1, 1))
1.1.1.7   root     4150:              && tree_int_cst_sgn (c2) >= 0)
1.1.1.6   root     4151:            /* The result is (C2%C3).  */
                   4152:            return omit_one_operand (type, const_binop (code, c2, arg1, 1),
                   4153:                                     TREE_OPERAND (xarg0, 0));
                   4154:        }
                   4155: 
1.1       root     4156:       goto binary;
                   4157: 
                   4158:     case LSHIFT_EXPR:
                   4159:     case RSHIFT_EXPR:
                   4160:     case LROTATE_EXPR:
                   4161:     case RROTATE_EXPR:
                   4162:       if (integer_zerop (arg1))
                   4163:        return non_lvalue (convert (type, arg0));
                   4164:       /* Since negative shift count is not well-defined,
                   4165:         don't try to compute it in the compiler.  */
1.1.1.8 ! root     4166:       if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1) < 0)
1.1       root     4167:        return t;
1.1.1.8 ! root     4168:       /* Rewrite an LROTATE_EXPR by a constant into an
        !          4169:         RROTATE_EXPR by a new constant.  */
        !          4170:       if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST)
        !          4171:        {
        !          4172:          TREE_SET_CODE (t, RROTATE_EXPR);
        !          4173:          code = RROTATE_EXPR;
        !          4174:          TREE_OPERAND (t, 1) = arg1
        !          4175:            = const_binop
        !          4176:              (MINUS_EXPR,
        !          4177:               convert (TREE_TYPE (arg1),
        !          4178:                        build_int_2 (GET_MODE_BITSIZE (TYPE_MODE (type)), 0)),
        !          4179:               arg1, 0);
        !          4180:          if (tree_int_cst_sgn (arg1) < 0)
        !          4181:            return t;
        !          4182:        }
        !          4183: 
        !          4184:       /* If we have a rotate of a bit operation with the rotate count and
        !          4185:         the second operand of the bit operation both constant,
        !          4186:         permute the two operations.  */
        !          4187:       if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
        !          4188:          && (TREE_CODE (arg0) == BIT_AND_EXPR
        !          4189:              || TREE_CODE (arg0) == BIT_ANDTC_EXPR
        !          4190:              || TREE_CODE (arg0) == BIT_IOR_EXPR
        !          4191:              || TREE_CODE (arg0) == BIT_XOR_EXPR)
        !          4192:          && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
        !          4193:        return fold (build (TREE_CODE (arg0), type,
        !          4194:                            fold (build (code, type,
        !          4195:                                         TREE_OPERAND (arg0, 0), arg1)),
        !          4196:                            fold (build (code, type,
        !          4197:                                         TREE_OPERAND (arg0, 1), arg1))));
        !          4198: 
        !          4199:       /* Two consecutive rotates adding up to the width of the mode can
        !          4200:         be ignored.  */
        !          4201:       if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
        !          4202:          && TREE_CODE (arg0) == RROTATE_EXPR
        !          4203:          && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
        !          4204:          && TREE_INT_CST_HIGH (arg1) == 0
        !          4205:          && TREE_INT_CST_HIGH (TREE_OPERAND (arg0, 1)) == 0
        !          4206:          && ((TREE_INT_CST_LOW (arg1)
        !          4207:               + TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)))
        !          4208:              == GET_MODE_BITSIZE (TYPE_MODE (type))))
        !          4209:        return TREE_OPERAND (arg0, 0);
        !          4210: 
1.1       root     4211:       goto binary;
                   4212: 
                   4213:     case MIN_EXPR:
                   4214:       if (operand_equal_p (arg0, arg1, 0))
                   4215:        return arg0;
1.1.1.5   root     4216:       if (INTEGRAL_TYPE_P (type)
1.1       root     4217:          && operand_equal_p (arg1, TYPE_MIN_VALUE (type), 1))
                   4218:        return omit_one_operand (type, arg1, arg0);
                   4219:       goto associate;
                   4220: 
                   4221:     case MAX_EXPR:
                   4222:       if (operand_equal_p (arg0, arg1, 0))
                   4223:        return arg0;
1.1.1.5   root     4224:       if (INTEGRAL_TYPE_P (type)
1.1       root     4225:          && operand_equal_p (arg1, TYPE_MAX_VALUE (type), 1))
                   4226:        return omit_one_operand (type, arg1, arg0);
                   4227:       goto associate;
                   4228: 
                   4229:     case TRUTH_NOT_EXPR:
                   4230:       /* Note that the operand of this must be an int
                   4231:         and its values must be 0 or 1.
                   4232:         ("true" is a fixed value perhaps depending on the language,
                   4233:         but we don't handle values other than 1 correctly yet.)  */
1.1.1.8 ! root     4234:       tem = invert_truthvalue (arg0);
        !          4235:       /* Avoid infinite recursion.  */
        !          4236:       if (TREE_CODE (tem) == TRUTH_NOT_EXPR)
        !          4237:        return t;
        !          4238:       return convert (type, tem);
1.1       root     4239: 
                   4240:     case TRUTH_ANDIF_EXPR:
                   4241:       /* Note that the operands of this must be ints
                   4242:         and their values must be 0 or 1.
                   4243:         ("true" is a fixed value perhaps depending on the language.)  */
                   4244:       /* If first arg is constant zero, return it.  */
1.1.1.5   root     4245:       if (integer_zerop (arg0))
1.1       root     4246:        return arg0;
                   4247:     case TRUTH_AND_EXPR:
                   4248:       /* If either arg is constant true, drop it.  */
                   4249:       if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
                   4250:        return non_lvalue (arg1);
                   4251:       if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
                   4252:        return non_lvalue (arg0);
1.1.1.5   root     4253:       /* If second arg is constant zero, result is zero, but first arg
                   4254:         must be evaluated.  */
                   4255:       if (integer_zerop (arg1))
                   4256:        return omit_one_operand (type, arg1, arg0);
1.1       root     4257: 
                   4258:     truth_andor:
1.1.1.7   root     4259:       /* We only do these simplifications if we are optimizing.  */
                   4260:       if (!optimize)
                   4261:        return t;
                   4262: 
                   4263:       /* Check for things like (A || B) && (A || C).  We can convert this
                   4264:         to A || (B && C).  Note that either operator can be any of the four
                   4265:         truth and/or operations and the transformation will still be
                   4266:         valid.   Also note that we only care about order for the
                   4267:         ANDIF and ORIF operators.  */
                   4268:       if (TREE_CODE (arg0) == TREE_CODE (arg1)
                   4269:          && (TREE_CODE (arg0) == TRUTH_ANDIF_EXPR
                   4270:              || TREE_CODE (arg0) == TRUTH_ORIF_EXPR
                   4271:              || TREE_CODE (arg0) == TRUTH_AND_EXPR
                   4272:              || TREE_CODE (arg0) == TRUTH_OR_EXPR))
                   4273:        {
                   4274:          tree a00 = TREE_OPERAND (arg0, 0);
                   4275:          tree a01 = TREE_OPERAND (arg0, 1);
                   4276:          tree a10 = TREE_OPERAND (arg1, 0);
                   4277:          tree a11 = TREE_OPERAND (arg1, 1);
                   4278:          int commutative = ((TREE_CODE (arg0) == TRUTH_OR_EXPR
                   4279:                              || TREE_CODE (arg0) == TRUTH_AND_EXPR)
                   4280:                             && (code == TRUTH_AND_EXPR
                   4281:                                 || code == TRUTH_OR_EXPR));
                   4282: 
                   4283:          if (operand_equal_p (a00, a10, 0))
                   4284:            return fold (build (TREE_CODE (arg0), type, a00,
                   4285:                                fold (build (code, type, a01, a11))));
                   4286:          else if (commutative && operand_equal_p (a00, a11, 0))
                   4287:            return fold (build (TREE_CODE (arg0), type, a00,
                   4288:                                fold (build (code, type, a01, a10))));
                   4289:          else if (commutative && operand_equal_p (a01, a10, 0))
                   4290:            return fold (build (TREE_CODE (arg0), type, a01,
                   4291:                                fold (build (code, type, a00, a11))));
                   4292: 
                   4293:          /* This case if tricky because we must either have commutative
                   4294:             operators or else A10 must not have side-effects.  */
                   4295: 
                   4296:          else if ((commutative || ! TREE_SIDE_EFFECTS (a10))
                   4297:                   && operand_equal_p (a01, a11, 0))
                   4298:            return fold (build (TREE_CODE (arg0), type,
                   4299:                                fold (build (code, type, a00, a10)),
                   4300:                                a01));
                   4301:        }
                   4302: 
1.1       root     4303:       /* Check for the possibility of merging component references.  If our
                   4304:         lhs is another similar operation, try to merge its rhs with our
                   4305:         rhs.  Then try to merge our lhs and rhs.  */
1.1.1.7   root     4306:       if (TREE_CODE (arg0) == code
                   4307:          && 0 != (tem = fold_truthop (code, type,
                   4308:                                       TREE_OPERAND (arg0, 1), arg1)))
                   4309:        return fold (build (code, type, TREE_OPERAND (arg0, 0), tem));
                   4310: 
                   4311:       if ((tem = fold_truthop (code, type, arg0, arg1)) != 0)
                   4312:        return tem;
1.1       root     4313: 
                   4314:       return t;
                   4315: 
                   4316:     case TRUTH_ORIF_EXPR:
                   4317:       /* Note that the operands of this must be ints
                   4318:         and their values must be 0 or true.
                   4319:         ("true" is a fixed value perhaps depending on the language.)  */
                   4320:       /* If first arg is constant true, return it.  */
                   4321:       if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
                   4322:        return arg0;
                   4323:     case TRUTH_OR_EXPR:
                   4324:       /* If either arg is constant zero, drop it.  */
                   4325:       if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0))
                   4326:        return non_lvalue (arg1);
                   4327:       if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1))
                   4328:        return non_lvalue (arg0);
1.1.1.5   root     4329:       /* If second arg is constant true, result is true, but we must
                   4330:         evaluate first arg.  */
                   4331:       if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
                   4332:        return omit_one_operand (type, arg1, arg0);
1.1       root     4333:       goto truth_andor;
                   4334: 
1.1.1.5   root     4335:     case TRUTH_XOR_EXPR:
                   4336:       /* If either arg is constant zero, drop it.  */
                   4337:       if (integer_zerop (arg0))
                   4338:        return non_lvalue (arg1);
                   4339:       if (integer_zerop (arg1))
                   4340:        return non_lvalue (arg0);
                   4341:       /* If either arg is constant true, this is a logical inversion.  */
                   4342:       if (integer_onep (arg0))
                   4343:        return non_lvalue (invert_truthvalue (arg1));
                   4344:       if (integer_onep (arg1))
                   4345:        return non_lvalue (invert_truthvalue (arg0));
1.1.1.6   root     4346:       return t;
1.1.1.5   root     4347: 
1.1       root     4348:     case EQ_EXPR:
                   4349:     case NE_EXPR:
                   4350:     case LT_EXPR:
                   4351:     case GT_EXPR:
                   4352:     case LE_EXPR:
                   4353:     case GE_EXPR:
                   4354:       /* If one arg is a constant integer, put it last.  */
                   4355:       if (TREE_CODE (arg0) == INTEGER_CST
                   4356:          && TREE_CODE (arg1) != INTEGER_CST)
                   4357:        {
                   4358:          TREE_OPERAND (t, 0) = arg1;
                   4359:          TREE_OPERAND (t, 1) = arg0;
                   4360:          arg0 = TREE_OPERAND (t, 0);
                   4361:          arg1 = TREE_OPERAND (t, 1);
1.1.1.3   root     4362:          code = swap_tree_comparison (code);
1.1       root     4363:          TREE_SET_CODE (t, code);
                   4364:        }
                   4365: 
                   4366:       /* Convert foo++ == CONST into ++foo == CONST + INCR.
                   4367:         First, see if one arg is constant; find the constant arg
                   4368:         and the other one.  */
                   4369:       {
                   4370:        tree constop = 0, varop;
1.1.1.8 ! root     4371:        int constopnum = -1;
1.1       root     4372: 
                   4373:        if (TREE_CONSTANT (arg1))
1.1.1.8 ! root     4374:          constopnum = 1, constop = arg1, varop = arg0;
1.1       root     4375:        if (TREE_CONSTANT (arg0))
1.1.1.8 ! root     4376:          constopnum = 0, constop = arg0, varop = arg1;
1.1       root     4377: 
                   4378:        if (constop && TREE_CODE (varop) == POSTINCREMENT_EXPR)
                   4379:          {
                   4380:            /* This optimization is invalid for ordered comparisons
                   4381:               if CONST+INCR overflows or if foo+incr might overflow.
1.1.1.3   root     4382:               This optimization is invalid for floating point due to rounding.
1.1       root     4383:               For pointer types we assume overflow doesn't happen.  */
                   4384:            if (TREE_CODE (TREE_TYPE (varop)) == POINTER_TYPE
1.1.1.5   root     4385:                || (! FLOAT_TYPE_P (TREE_TYPE (varop))
1.1.1.3   root     4386:                    && (code == EQ_EXPR || code == NE_EXPR)))
1.1       root     4387:              {
1.1.1.3   root     4388:                tree newconst
                   4389:                  = fold (build (PLUS_EXPR, TREE_TYPE (varop),
                   4390:                                 constop, TREE_OPERAND (varop, 1)));
                   4391:                TREE_SET_CODE (varop, PREINCREMENT_EXPR);
1.1.1.8 ! root     4392: 
        !          4393:                t = build (code, type, TREE_OPERAND (t, 0),
        !          4394:                           TREE_OPERAND (t, 1));
        !          4395:                TREE_OPERAND (t, constopnum) = newconst;
1.1.1.3   root     4396:                return t;
1.1       root     4397:              }
                   4398:          }
                   4399:        else if (constop && TREE_CODE (varop) == POSTDECREMENT_EXPR)
                   4400:          {
                   4401:            if (TREE_CODE (TREE_TYPE (varop)) == POINTER_TYPE
1.1.1.5   root     4402:                || (! FLOAT_TYPE_P (TREE_TYPE (varop))
1.1.1.3   root     4403:                    && (code == EQ_EXPR || code == NE_EXPR)))
1.1       root     4404:              {
1.1.1.3   root     4405:                tree newconst
                   4406:                  = fold (build (MINUS_EXPR, TREE_TYPE (varop),
                   4407:                                 constop, TREE_OPERAND (varop, 1)));
                   4408:                TREE_SET_CODE (varop, PREDECREMENT_EXPR);
1.1.1.8 ! root     4409:                t = build (code, type, TREE_OPERAND (t, 0),
        !          4410:                           TREE_OPERAND (t, 1));
        !          4411:                TREE_OPERAND (t, constopnum) = newconst;
1.1.1.3   root     4412:                return t;
1.1       root     4413:              }
                   4414:          }
                   4415:       }
                   4416: 
                   4417:       /* Change X >= CST to X > (CST - 1) if CST is positive.  */
                   4418:       if (TREE_CODE (arg1) == INTEGER_CST
                   4419:          && TREE_CODE (arg0) != INTEGER_CST
1.1.1.7   root     4420:          && tree_int_cst_sgn (arg1) > 0)
1.1       root     4421:        {
                   4422:          switch (TREE_CODE (t))
                   4423:            {
                   4424:            case GE_EXPR:
                   4425:              code = GT_EXPR;
1.1.1.5   root     4426:              arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
1.1.1.8 ! root     4427:              t = build (code, type, TREE_OPERAND (t, 0), arg1);
1.1       root     4428:              break;
                   4429: 
                   4430:            case LT_EXPR:
                   4431:              code = LE_EXPR;
1.1.1.5   root     4432:              arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
1.1.1.8 ! root     4433:              t = build (code, type, TREE_OPERAND (t, 0), arg1);
        !          4434:              break;
1.1       root     4435:            }
                   4436:        }
                   4437: 
                   4438:       /* If this is an EQ or NE comparison with zero and ARG0 is
                   4439:         (1 << foo) & bar, convert it to (bar >> foo) & 1.  Both require
                   4440:         two operations, but the latter can be done in one less insn
                   4441:         one machine that have only two-operand insns or on which a
                   4442:         constant cannot be the first operand.  */
                   4443:       if (integer_zerop (arg1) && (code == EQ_EXPR || code == NE_EXPR)
                   4444:          && TREE_CODE (arg0) == BIT_AND_EXPR)
                   4445:        {
                   4446:          if (TREE_CODE (TREE_OPERAND (arg0, 0)) == LSHIFT_EXPR
                   4447:              && integer_onep (TREE_OPERAND (TREE_OPERAND (arg0, 0), 0)))
                   4448:            return
                   4449:              fold (build (code, type,
                   4450:                           build (BIT_AND_EXPR, TREE_TYPE (arg0),
                   4451:                                  build (RSHIFT_EXPR,
                   4452:                                         TREE_TYPE (TREE_OPERAND (arg0, 0)),
                   4453:                                         TREE_OPERAND (arg0, 1),
                   4454:                                         TREE_OPERAND (TREE_OPERAND (arg0, 0), 1)),
                   4455:                                  convert (TREE_TYPE (arg0),
                   4456:                                           integer_one_node)),
                   4457:                           arg1));
                   4458:          else if (TREE_CODE (TREE_OPERAND (arg0, 1)) == LSHIFT_EXPR
                   4459:                   && integer_onep (TREE_OPERAND (TREE_OPERAND (arg0, 1), 0)))
                   4460:            return
                   4461:              fold (build (code, type,
                   4462:                           build (BIT_AND_EXPR, TREE_TYPE (arg0),
                   4463:                                  build (RSHIFT_EXPR,
                   4464:                                         TREE_TYPE (TREE_OPERAND (arg0, 1)),
                   4465:                                         TREE_OPERAND (arg0, 0),
                   4466:                                         TREE_OPERAND (TREE_OPERAND (arg0, 1), 1)),
                   4467:                                  convert (TREE_TYPE (arg0),
                   4468:                                           integer_one_node)),
                   4469:                           arg1));
                   4470:        }
                   4471: 
1.1.1.6   root     4472:       /* If this is an NE or EQ comparison of zero against the result of a
                   4473:         signed MOD operation whose second operand is a power of 2, make
                   4474:         the MOD operation unsigned since it is simpler and equivalent.  */
                   4475:       if ((code == NE_EXPR || code == EQ_EXPR)
                   4476:          && integer_zerop (arg1)
                   4477:          && ! TREE_UNSIGNED (TREE_TYPE (arg0))
                   4478:          && (TREE_CODE (arg0) == TRUNC_MOD_EXPR
                   4479:              || TREE_CODE (arg0) == CEIL_MOD_EXPR
                   4480:              || TREE_CODE (arg0) == FLOOR_MOD_EXPR
                   4481:              || TREE_CODE (arg0) == ROUND_MOD_EXPR)
                   4482:          && integer_pow2p (TREE_OPERAND (arg0, 1)))
                   4483:        {
                   4484:          tree newtype = unsigned_type (TREE_TYPE (arg0));
                   4485:          tree newmod = build (TREE_CODE (arg0), newtype,
                   4486:                               convert (newtype, TREE_OPERAND (arg0, 0)),
                   4487:                               convert (newtype, TREE_OPERAND (arg0, 1)));
                   4488: 
                   4489:          return build (code, type, newmod, convert (newtype, arg1));
                   4490:        }
                   4491: 
1.1       root     4492:       /* If this is an NE comparison of zero with an AND of one, remove the
                   4493:         comparison since the AND will give the correct value.  */
                   4494:       if (code == NE_EXPR && integer_zerop (arg1)
                   4495:          && TREE_CODE (arg0) == BIT_AND_EXPR
                   4496:          && integer_onep (TREE_OPERAND (arg0, 1)))
                   4497:        return convert (type, arg0);
                   4498: 
                   4499:       /* If we have (A & C) == C where C is a power of 2, convert this into
                   4500:         (A & C) != 0.  Similarly for NE_EXPR.  */
                   4501:       if ((code == EQ_EXPR || code == NE_EXPR)
                   4502:          && TREE_CODE (arg0) == BIT_AND_EXPR
                   4503:          && integer_pow2p (TREE_OPERAND (arg0, 1))
                   4504:          && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
                   4505:        return build (code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type,
                   4506:                      arg0, integer_zero_node);
                   4507: 
1.1.1.7   root     4508:       /* If X is unsigned, convert X < (1 << Y) into X >> Y == 0
                   4509:         and similarly for >= into !=.  */
                   4510:       if ((code == LT_EXPR || code == GE_EXPR)
                   4511:          && TREE_UNSIGNED (TREE_TYPE (arg0))
                   4512:          && TREE_CODE (arg1) == LSHIFT_EXPR
                   4513:          && integer_onep (TREE_OPERAND (arg1, 0)))
                   4514:        return build (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type, 
                   4515:                      build (RSHIFT_EXPR, TREE_TYPE (arg0), arg0,
                   4516:                             TREE_OPERAND (arg1, 1)),
                   4517:                      convert (TREE_TYPE (arg0), integer_zero_node));
                   4518: 
                   4519:       else if ((code == LT_EXPR || code == GE_EXPR)
                   4520:               && TREE_UNSIGNED (TREE_TYPE (arg0))
                   4521:               && (TREE_CODE (arg1) == NOP_EXPR
                   4522:                   || TREE_CODE (arg1) == CONVERT_EXPR)
                   4523:               && TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR
                   4524:               && integer_onep (TREE_OPERAND (TREE_OPERAND (arg1, 0), 0)))
                   4525:        return
                   4526:          build (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type,
                   4527:                 convert (TREE_TYPE (arg0),
                   4528:                          build (RSHIFT_EXPR, TREE_TYPE (arg0), arg0,
                   4529:                                 TREE_OPERAND (TREE_OPERAND (arg1, 0), 1))),
                   4530:                 convert (TREE_TYPE (arg0), integer_zero_node));
                   4531: 
1.1.1.3   root     4532:       /* Simplify comparison of something with itself.  (For IEEE
                   4533:         floating-point, we can only do some of these simplifications.)  */
                   4534:       if (operand_equal_p (arg0, arg1, 0))
1.1       root     4535:        {
                   4536:          switch (code)
                   4537:            {
                   4538:            case EQ_EXPR:
                   4539:            case GE_EXPR:
                   4540:            case LE_EXPR:
1.1.1.5   root     4541:              if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
1.1.1.3   root     4542:                {
                   4543:                  t = build_int_2 (1, 0);
                   4544:                  TREE_TYPE (t) = type;
                   4545:                  return t;
                   4546:                }
                   4547:              code = EQ_EXPR;
                   4548:              TREE_SET_CODE (t, code);
                   4549:              break;
                   4550: 
1.1       root     4551:            case NE_EXPR:
1.1.1.3   root     4552:              /* For NE, we can only do this simplification if integer.  */
1.1.1.5   root     4553:              if (! INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
1.1.1.3   root     4554:                break;
                   4555:              /* ... fall through ... */
1.1       root     4556:            case GT_EXPR:
                   4557:            case LT_EXPR:
                   4558:              t = build_int_2 (0, 0);
                   4559:              TREE_TYPE (t) = type;
                   4560:              return t;
                   4561:            }
                   4562:        }
                   4563: 
                   4564:       /* An unsigned comparison against 0 can be simplified.  */
                   4565:       if (integer_zerop (arg1)
1.1.1.5   root     4566:          && (INTEGRAL_TYPE_P (TREE_TYPE (arg1))
1.1       root     4567:              || TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE)
                   4568:          && TREE_UNSIGNED (TREE_TYPE (arg1)))
                   4569:        {
                   4570:          switch (TREE_CODE (t))
                   4571:            {
                   4572:            case GT_EXPR:
1.1.1.3   root     4573:              code = NE_EXPR;
1.1       root     4574:              TREE_SET_CODE (t, NE_EXPR);
                   4575:              break;
                   4576:            case LE_EXPR:
1.1.1.3   root     4577:              code = EQ_EXPR;
1.1       root     4578:              TREE_SET_CODE (t, EQ_EXPR);
                   4579:              break;
                   4580:            case GE_EXPR:
1.1.1.6   root     4581:              return omit_one_operand (type,
                   4582:                                       convert (type, integer_one_node),
                   4583:                                       arg0);
1.1       root     4584:            case LT_EXPR:
1.1.1.6   root     4585:              return omit_one_operand (type,
                   4586:                                       convert (type, integer_zero_node),
                   4587:                                       arg0);
1.1       root     4588:            }
                   4589:        }
                   4590: 
1.1.1.3   root     4591:       /* If we are comparing an expression that just has comparisons
                   4592:         of two integer values, arithmetic expressions of those comparisons,
                   4593:         and constants, we can simplify it.  There are only three cases
                   4594:         to check: the two values can either be equal, the first can be
                   4595:         greater, or the second can be greater.  Fold the expression for
                   4596:         those three values.  Since each value must be 0 or 1, we have
                   4597:         eight possibilities, each of which corresponds to the constant 0
                   4598:         or 1 or one of the six possible comparisons.
                   4599: 
                   4600:         This handles common cases like (a > b) == 0 but also handles
                   4601:         expressions like  ((x > y) - (y > x)) > 0, which supposedly
                   4602:         occur in macroized code.  */
                   4603: 
                   4604:       if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) != INTEGER_CST)
                   4605:        {
                   4606:          tree cval1 = 0, cval2 = 0;
1.1.1.6   root     4607:          int save_p = 0;
1.1.1.3   root     4608: 
1.1.1.6   root     4609:          if (twoval_comparison_p (arg0, &cval1, &cval2, &save_p)
1.1.1.3   root     4610:              /* Don't handle degenerate cases here; they should already
                   4611:                 have been handled anyway.  */
                   4612:              && cval1 != 0 && cval2 != 0
                   4613:              && ! (TREE_CONSTANT (cval1) && TREE_CONSTANT (cval2))
                   4614:              && TREE_TYPE (cval1) == TREE_TYPE (cval2)
1.1.1.5   root     4615:              && INTEGRAL_TYPE_P (TREE_TYPE (cval1))
1.1.1.3   root     4616:              && ! operand_equal_p (TYPE_MIN_VALUE (TREE_TYPE (cval1)),
                   4617:                                    TYPE_MAX_VALUE (TREE_TYPE (cval2)), 0))
                   4618:            {
                   4619:              tree maxval = TYPE_MAX_VALUE (TREE_TYPE (cval1));
                   4620:              tree minval = TYPE_MIN_VALUE (TREE_TYPE (cval1));
                   4621: 
                   4622:              /* We can't just pass T to eval_subst in case cval1 or cval2
                   4623:                 was the same as ARG1.  */
                   4624: 
                   4625:              tree high_result
                   4626:                = fold (build (code, type,
                   4627:                               eval_subst (arg0, cval1, maxval, cval2, minval),
                   4628:                               arg1));
                   4629:              tree equal_result
                   4630:                = fold (build (code, type,
                   4631:                               eval_subst (arg0, cval1, maxval, cval2, maxval),
                   4632:                               arg1));
                   4633:              tree low_result
                   4634:                = fold (build (code, type,
                   4635:                               eval_subst (arg0, cval1, minval, cval2, maxval),
                   4636:                               arg1));
                   4637: 
                   4638:              /* All three of these results should be 0 or 1.  Confirm they
                   4639:                 are.  Then use those values to select the proper code
                   4640:                 to use.  */
                   4641: 
                   4642:              if ((integer_zerop (high_result)
                   4643:                   || integer_onep (high_result))
                   4644:                  && (integer_zerop (equal_result)
                   4645:                      || integer_onep (equal_result))
                   4646:                  && (integer_zerop (low_result)
                   4647:                      || integer_onep (low_result)))
                   4648:                {
                   4649:                  /* Make a 3-bit mask with the high-order bit being the
                   4650:                     value for `>', the next for '=', and the low for '<'.  */
                   4651:                  switch ((integer_onep (high_result) * 4)
                   4652:                          + (integer_onep (equal_result) * 2)
                   4653:                          + integer_onep (low_result))
                   4654:                    {
                   4655:                    case 0:
                   4656:                      /* Always false.  */
                   4657:                      return omit_one_operand (type, integer_zero_node, arg0);
                   4658:                    case 1:
                   4659:                      code = LT_EXPR;
                   4660:                      break;
                   4661:                    case 2:
                   4662:                      code = EQ_EXPR;
                   4663:                      break;
                   4664:                    case 3:
                   4665:                      code = LE_EXPR;
                   4666:                      break;
                   4667:                    case 4:
                   4668:                      code = GT_EXPR;
                   4669:                      break;
                   4670:                    case 5:
                   4671:                      code = NE_EXPR;
                   4672:                      break;
                   4673:                    case 6:
                   4674:                      code = GE_EXPR;
                   4675:                      break;
                   4676:                    case 7:
                   4677:                      /* Always true.  */
                   4678:                      return omit_one_operand (type, integer_one_node, arg0);
                   4679:                    }
                   4680: 
1.1.1.6   root     4681:                  t = build (code, type, cval1, cval2);
                   4682:                  if (save_p)
                   4683:                    return save_expr (t);
                   4684:                  else
                   4685:                    return fold (t);
1.1.1.3   root     4686:                }
                   4687:            }
                   4688:        }
                   4689: 
                   4690:       /* If this is a comparison of a field, we may be able to simplify it.  */
                   4691:       if ((TREE_CODE (arg0) == COMPONENT_REF
                   4692:                || TREE_CODE (arg0) == BIT_FIELD_REF)
                   4693:               && (code == EQ_EXPR || code == NE_EXPR)
                   4694:               /* Handle the constant case even without -O
                   4695:                  to make sure the warnings are given.  */
                   4696:               && (optimize || TREE_CODE (arg1) == INTEGER_CST))
                   4697:        {
                   4698:          t1 = optimize_bit_field_compare (code, type, arg0, arg1);
                   4699:          return t1 ? t1 : t;
                   4700:        }
                   4701: 
1.1.1.7   root     4702:       /* If this is a comparison of complex values and either or both
                   4703:         sizes are a COMPLEX_EXPR, it is best to split up the comparisons
                   4704:         and join them with a TRUTH_ANDIF_EXPR or TRUTH_ORIF_EXPR.  This
                   4705:         may prevent needless evaluations.  */
                   4706:       if ((code == EQ_EXPR || code == NE_EXPR)
                   4707:          && TREE_CODE (TREE_TYPE (arg0)) == COMPLEX_TYPE
                   4708:          && (TREE_CODE (arg0) == COMPLEX_EXPR
                   4709:              || TREE_CODE (arg1) == COMPLEX_EXPR))
                   4710:        {
                   4711:          tree subtype = TREE_TYPE (TREE_TYPE (arg0));
                   4712:          tree real0 = fold (build1 (REALPART_EXPR, subtype, arg0));
                   4713:          tree imag0 = fold (build1 (IMAGPART_EXPR, subtype, arg0));
                   4714:          tree real1 = fold (build1 (REALPART_EXPR, subtype, arg1));
                   4715:          tree imag1 = fold (build1 (IMAGPART_EXPR, subtype, arg1));
                   4716: 
                   4717:          return fold (build ((code == EQ_EXPR ? TRUTH_ANDIF_EXPR
                   4718:                               : TRUTH_ORIF_EXPR),
                   4719:                              type,
                   4720:                              fold (build (code, type, real0, real1)),
                   4721:                              fold (build (code, type, imag0, imag1))));
                   4722:        }
                   4723: 
1.1.1.3   root     4724:       /* From here on, the only cases we handle are when the result is
                   4725:         known to be a constant.
                   4726: 
                   4727:         To compute GT, swap the arguments and do LT.
1.1       root     4728:         To compute GE, do LT and invert the result.
                   4729:         To compute LE, swap the arguments, do LT and invert the result.
1.1.1.3   root     4730:         To compute NE, do EQ and invert the result.
                   4731: 
                   4732:         Therefore, the code below must handle only EQ and LT.  */
                   4733: 
1.1       root     4734:       if (code == LE_EXPR || code == GT_EXPR)
                   4735:        {
1.1.1.3   root     4736:          tem = arg0, arg0 = arg1, arg1 = tem;
                   4737:          code = swap_tree_comparison (code);
                   4738:        }
                   4739: 
                   4740:       /* Note that it is safe to invert for real values here because we
                   4741:         will check below in the one case that it matters.  */
                   4742: 
                   4743:       invert = 0;
                   4744:       if (code == NE_EXPR || code == GE_EXPR)
                   4745:        {
                   4746:          invert = 1;
                   4747:          code = invert_tree_comparison (code);
1.1       root     4748:        }
                   4749: 
                   4750:       /* Compute a result for LT or EQ if args permit;
                   4751:         otherwise return T.  */
1.1.1.3   root     4752:       if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
1.1       root     4753:        {
1.1.1.3   root     4754:          if (code == EQ_EXPR)
                   4755:            t1 = build_int_2 ((TREE_INT_CST_LOW (arg0)
                   4756:                               == TREE_INT_CST_LOW (arg1))
                   4757:                              && (TREE_INT_CST_HIGH (arg0)
                   4758:                                  == TREE_INT_CST_HIGH (arg1)),
                   4759:                              0);
1.1       root     4760:          else
1.1.1.3   root     4761:            t1 = build_int_2 ((TREE_UNSIGNED (TREE_TYPE (arg0))
                   4762:                               ? INT_CST_LT_UNSIGNED (arg0, arg1)
                   4763:                               : INT_CST_LT (arg0, arg1)),
                   4764:                              0);
1.1       root     4765:        }
1.1.1.3   root     4766: 
1.1       root     4767:       /* Assume a nonexplicit constant cannot equal an explicit one,
                   4768:         since such code would be undefined anyway.
                   4769:         Exception: on sysvr4, using #pragma weak,
                   4770:         a label can come out as 0.  */
                   4771:       else if (TREE_CODE (arg1) == INTEGER_CST
                   4772:               && !integer_zerop (arg1)
                   4773:               && TREE_CONSTANT (arg0)
                   4774:               && TREE_CODE (arg0) == ADDR_EXPR
1.1.1.3   root     4775:               && code == EQ_EXPR)
                   4776:        t1 = build_int_2 (0, 0);
                   4777: 
1.1       root     4778:       /* Two real constants can be compared explicitly.  */
1.1.1.3   root     4779:       else if (TREE_CODE (arg0) == REAL_CST && TREE_CODE (arg1) == REAL_CST)
1.1       root     4780:        {
1.1.1.3   root     4781:          /* If either operand is a NaN, the result is false with two
                   4782:             exceptions: First, an NE_EXPR is true on NaNs, but that case
                   4783:             is already handled correctly since we will be inverting the
                   4784:             result for NE_EXPR.  Second, if we had inverted a LE_EXPR
                   4785:             or a GE_EXPR into a LT_EXPR, we must return true so that it
                   4786:             will be inverted into false.  */
                   4787: 
                   4788:          if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg0))
                   4789:              || REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)))
                   4790:            t1 = build_int_2 (invert && code == LT_EXPR, 0);
                   4791: 
                   4792:          else if (code == EQ_EXPR)
                   4793:            t1 = build_int_2 (REAL_VALUES_EQUAL (TREE_REAL_CST (arg0),
                   4794:                                                 TREE_REAL_CST (arg1)),
                   4795:                              0);
1.1       root     4796:          else
1.1.1.3   root     4797:            t1 = build_int_2 (REAL_VALUES_LESS (TREE_REAL_CST (arg0),
                   4798:                                                TREE_REAL_CST (arg1)),
                   4799:                              0);
1.1       root     4800:        }
                   4801: 
1.1.1.3   root     4802:       if (t1 == NULL_TREE)
                   4803:        return t;
                   4804: 
                   4805:       if (invert)
                   4806:        TREE_INT_CST_LOW (t1) ^= 1;
                   4807: 
                   4808:       TREE_TYPE (t1) = type;
                   4809:       return t1;
1.1       root     4810: 
                   4811:     case COND_EXPR:
1.1.1.6   root     4812:       /* Pedantic ANSI C says that a conditional expression is never an lvalue,
                   4813:         so all simple results must be passed through pedantic_non_lvalue.  */
1.1       root     4814:       if (TREE_CODE (arg0) == INTEGER_CST)
1.1.1.6   root     4815:        return pedantic_non_lvalue
                   4816:          (TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1)));
1.1       root     4817:       else if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0))
1.1.1.8 ! root     4818:        return pedantic_omit_one_operand (type, arg1, arg0);
1.1       root     4819: 
1.1.1.3   root     4820:       /* If the second operand is zero, invert the comparison and swap
                   4821:         the second and third operands.  Likewise if the second operand
                   4822:         is constant and the third is not or if the third operand is
                   4823:         equivalent to the first operand of the comparison.  */
1.1       root     4824: 
1.1.1.3   root     4825:       if (integer_zerop (arg1)
                   4826:          || (TREE_CONSTANT (arg1) && ! TREE_CONSTANT (TREE_OPERAND (t, 2)))
                   4827:          || (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
                   4828:              && operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0),
                   4829:                                                 TREE_OPERAND (t, 2),
                   4830:                                                 TREE_OPERAND (arg0, 1))))
                   4831:        {
                   4832:          /* See if this can be inverted.  If it can't, possibly because
                   4833:             it was a floating-point inequality comparison, don't do
                   4834:             anything.  */
                   4835:          tem = invert_truthvalue (arg0);
                   4836: 
                   4837:          if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
                   4838:            {
1.1.1.8 ! root     4839:              t = build (code, type, tem,
        !          4840:                         TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
        !          4841:              arg0 = tem;
        !          4842:              arg1 = TREE_OPERAND (t, 2);
        !          4843:              STRIP_NOPS (arg1);
1.1.1.3   root     4844:            }
                   4845:        }
1.1       root     4846: 
1.1.1.3   root     4847:       /* If we have A op B ? A : C, we may be able to convert this to a
                   4848:         simpler expression, depending on the operation and the values
1.1.1.4   root     4849:         of B and C.  IEEE floating point prevents this though,
                   4850:         because A or B might be -0.0 or a NaN.  */
1.1.1.3   root     4851: 
                   4852:       if (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
1.1.1.4   root     4853:          && (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
1.1.1.7   root     4854:              || ! FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 0)))
                   4855:              || flag_fast_math)
1.1.1.3   root     4856:          && operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0),
                   4857:                                             arg1, TREE_OPERAND (arg0, 1)))
                   4858:        {
                   4859:          tree arg2 = TREE_OPERAND (t, 2);
                   4860:          enum tree_code comp_code = TREE_CODE (arg0);
                   4861: 
1.1.1.8 ! root     4862:          STRIP_NOPS (arg2);
        !          4863: 
1.1.1.3   root     4864:          /* If we have A op 0 ? A : -A, this is A, -A, abs (A), or abs (-A),
                   4865:             depending on the comparison operation.  */
1.1.1.8 ! root     4866:          if ((FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 1)))
        !          4867:               ? real_zerop (TREE_OPERAND (arg0, 1))
        !          4868:               : integer_zerop (TREE_OPERAND (arg0, 1)))
1.1.1.3   root     4869:              && TREE_CODE (arg2) == NEGATE_EXPR
                   4870:              && operand_equal_p (TREE_OPERAND (arg2, 0), arg1, 0))
                   4871:            switch (comp_code)
                   4872:              {
                   4873:              case EQ_EXPR:
1.1.1.6   root     4874:                return pedantic_non_lvalue
                   4875:                  (fold (build1 (NEGATE_EXPR, type, arg1)));
1.1.1.3   root     4876:              case NE_EXPR:
1.1.1.6   root     4877:                return pedantic_non_lvalue (convert (type, arg1));
1.1.1.3   root     4878:              case GE_EXPR:
                   4879:              case GT_EXPR:
1.1.1.6   root     4880:                return pedantic_non_lvalue
1.1.1.8 ! root     4881:                  (convert (type, fold (build1 (ABS_EXPR,
        !          4882:                                                TREE_TYPE (arg1), arg1))));
1.1.1.3   root     4883:              case LE_EXPR:
                   4884:              case LT_EXPR:
1.1.1.6   root     4885:                return pedantic_non_lvalue
                   4886:                  (fold (build1 (NEGATE_EXPR, type,
1.1.1.8 ! root     4887:                                 convert (type,
        !          4888:                                          fold (build1 (ABS_EXPR,
        !          4889:                                                        TREE_TYPE (arg1),
        !          4890:                                                        arg1))))));
1.1.1.3   root     4891:              }
1.1       root     4892: 
1.1.1.3   root     4893:          /* If this is A != 0 ? A : 0, this is simply A.  For ==, it is
                   4894:             always zero.  */
1.1       root     4895: 
1.1.1.3   root     4896:          if (integer_zerop (TREE_OPERAND (arg0, 1)) && integer_zerop (arg2))
                   4897:            {
                   4898:              if (comp_code == NE_EXPR)
1.1.1.6   root     4899:                return pedantic_non_lvalue (convert (type, arg1));
1.1.1.3   root     4900:              else if (comp_code == EQ_EXPR)
1.1.1.6   root     4901:                return pedantic_non_lvalue (convert (type, integer_zero_node));
1.1.1.3   root     4902:            }
1.1       root     4903: 
1.1.1.3   root     4904:          /* If this is A op B ? A : B, this is either A, B, min (A, B),
                   4905:             or max (A, B), depending on the operation.  */
1.1       root     4906: 
1.1.1.3   root     4907:          if (operand_equal_for_comparison_p (TREE_OPERAND (arg0, 1),
                   4908:                                              arg2, TREE_OPERAND (arg0, 0)))
1.1.1.8 ! root     4909:            {
        !          4910:              tree comp_op0 = TREE_OPERAND (arg0, 0);
        !          4911:              tree comp_op1 = TREE_OPERAND (arg0, 1);
        !          4912:              tree comp_type = TREE_TYPE (comp_op0);
        !          4913: 
        !          4914:              switch (comp_code)
        !          4915:                {
        !          4916:                case EQ_EXPR:
        !          4917:                  return pedantic_non_lvalue (convert (type, arg2));
        !          4918:                case NE_EXPR:
        !          4919:                  return pedantic_non_lvalue (convert (type, arg1));
        !          4920:                case LE_EXPR:
        !          4921:                case LT_EXPR:
        !          4922:                  return pedantic_non_lvalue
        !          4923:                    (convert (type, (fold (build (MIN_EXPR, comp_type,
        !          4924:                                                  comp_op0, comp_op1)))));
        !          4925:                case GE_EXPR:
        !          4926:                case GT_EXPR:
        !          4927:                  return pedantic_non_lvalue
        !          4928:                    (convert (type, fold (build (MAX_EXPR, comp_type,
        !          4929:                                                 comp_op0, comp_op1))));
        !          4930:                }
        !          4931:            }
1.1       root     4932: 
1.1.1.3   root     4933:          /* If this is A op C1 ? A : C2 with C1 and C2 constant integers,
                   4934:             we might still be able to simplify this.  For example,
                   4935:             if C1 is one less or one more than C2, this might have started
1.1.1.4   root     4936:             out as a MIN or MAX and been transformed by this function.
1.1.1.5   root     4937:             Only good for INTEGER_TYPEs, because we need TYPE_MAX_VALUE.  */
1.1.1.3   root     4938: 
1.1.1.5   root     4939:          if (INTEGRAL_TYPE_P (type)
1.1.1.4   root     4940:              && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
1.1.1.3   root     4941:              && TREE_CODE (arg2) == INTEGER_CST)
                   4942:            switch (comp_code)
                   4943:              {
                   4944:              case EQ_EXPR:
                   4945:                /* We can replace A with C1 in this case.  */
1.1.1.8 ! root     4946:                arg1 = convert (type, TREE_OPERAND (arg0, 1));
        !          4947:                t = build (code, type, TREE_OPERAND (t, 0), arg1,
        !          4948:                           TREE_OPERAND (t, 2));
1.1.1.3   root     4949:                break;
                   4950: 
                   4951:              case LT_EXPR:
                   4952:                /* If C1 is C2 + 1, this is min(A, C2).  */
                   4953:                if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type), 1)
                   4954:                    && operand_equal_p (TREE_OPERAND (arg0, 1),
                   4955:                                        const_binop (PLUS_EXPR, arg2,
1.1.1.5   root     4956:                                                     integer_one_node, 0), 1))
1.1.1.6   root     4957:                  return pedantic_non_lvalue
                   4958:                    (fold (build (MIN_EXPR, type, arg1, arg2)));
1.1.1.3   root     4959:                break;
                   4960: 
                   4961:              case LE_EXPR:
                   4962:                /* If C1 is C2 - 1, this is min(A, C2).  */
                   4963:                if (! operand_equal_p (arg2, TYPE_MIN_VALUE (type), 1)
                   4964:                    && operand_equal_p (TREE_OPERAND (arg0, 1),
                   4965:                                        const_binop (MINUS_EXPR, arg2,
1.1.1.5   root     4966:                                                     integer_one_node, 0), 1))
1.1.1.6   root     4967:                  return pedantic_non_lvalue
                   4968:                    (fold (build (MIN_EXPR, type, arg1, arg2)));
1.1.1.3   root     4969:                break;
                   4970: 
                   4971:              case GT_EXPR:
                   4972:                /* If C1 is C2 - 1, this is max(A, C2).  */
                   4973:                if (! operand_equal_p (arg2, TYPE_MIN_VALUE (type), 1)
                   4974:                    && operand_equal_p (TREE_OPERAND (arg0, 1),
                   4975:                                        const_binop (MINUS_EXPR, arg2,
1.1.1.5   root     4976:                                                     integer_one_node, 0), 1))
1.1.1.6   root     4977:                  return pedantic_non_lvalue
                   4978:                    (fold (build (MAX_EXPR, type, arg1, arg2)));
1.1.1.3   root     4979:                break;
                   4980: 
                   4981:              case GE_EXPR:
                   4982:                /* If C1 is C2 + 1, this is max(A, C2).  */
                   4983:                if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type), 1)
                   4984:                    && operand_equal_p (TREE_OPERAND (arg0, 1),
                   4985:                                        const_binop (PLUS_EXPR, arg2,
1.1.1.5   root     4986:                                                     integer_one_node, 0), 1))
1.1.1.6   root     4987:                  return pedantic_non_lvalue
                   4988:                    (fold (build (MAX_EXPR, type, arg1, arg2)));
1.1.1.3   root     4989:                break;
                   4990:              }
                   4991:        }
                   4992: 
1.1.1.8 ! root     4993:       /* If the second operand is simpler than the third, swap them
        !          4994:         since that produces better jump optimization results.  */
        !          4995:       if ((TREE_CONSTANT (arg1) || TREE_CODE_CLASS (TREE_CODE (arg1)) == 'd'
        !          4996:           || TREE_CODE (arg1) == SAVE_EXPR)
        !          4997:          && ! (TREE_CONSTANT (TREE_OPERAND (t, 2))
        !          4998:                || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 2))) == 'd'
        !          4999:                || TREE_CODE (TREE_OPERAND (t, 2)) == SAVE_EXPR))
        !          5000:        {
        !          5001:          /* See if this can be inverted.  If it can't, possibly because
        !          5002:             it was a floating-point inequality comparison, don't do
        !          5003:             anything.  */
        !          5004:          tem = invert_truthvalue (arg0);
        !          5005: 
        !          5006:          if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
        !          5007:            {
        !          5008:              t = build (code, type, tem,
        !          5009:                         TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
        !          5010:              arg0 = tem;
        !          5011:              arg1 = TREE_OPERAND (t, 2);
        !          5012:              STRIP_NOPS (arg1);
        !          5013:            }
        !          5014:        }
        !          5015: 
1.1.1.3   root     5016:       /* Convert A ? 1 : 0 to simply A.  */
                   5017:       if (integer_onep (TREE_OPERAND (t, 1))
                   5018:          && integer_zerop (TREE_OPERAND (t, 2))
                   5019:          /* If we try to convert TREE_OPERAND (t, 0) to our type, the
                   5020:             call to fold will try to move the conversion inside 
                   5021:             a COND, which will recurse.  In that case, the COND_EXPR
                   5022:             is probably the best choice, so leave it alone.  */
                   5023:          && type == TREE_TYPE (arg0))
1.1.1.6   root     5024:        return pedantic_non_lvalue (arg0);
1.1       root     5025: 
1.1.1.3   root     5026:       /* Look for expressions of the form A & 2 ? 2 : 0.  The result of this
                   5027:         operation is simply A & 2.  */
1.1       root     5028: 
                   5029:       if (integer_zerop (TREE_OPERAND (t, 2))
                   5030:          && TREE_CODE (arg0) == NE_EXPR
                   5031:          && integer_zerop (TREE_OPERAND (arg0, 1))
1.1.1.3   root     5032:          && integer_pow2p (arg1)
                   5033:          && TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_AND_EXPR
                   5034:          && operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1),
                   5035:                              arg1, 1))
1.1.1.6   root     5036:        return pedantic_non_lvalue (convert (type, TREE_OPERAND (arg0, 0)));
1.1       root     5037: 
                   5038:       return t;
                   5039: 
                   5040:     case COMPOUND_EXPR:
1.1.1.5   root     5041:       /* When pedantic, a compound expression can be neither an lvalue
                   5042:         nor an integer constant expression.  */
                   5043:       if (TREE_SIDE_EFFECTS (arg0) || pedantic)
                   5044:        return t;
                   5045:       /* Don't let (0, 0) be null pointer constant.  */
                   5046:       if (integer_zerop (arg1))
                   5047:        return non_lvalue (arg1);
                   5048:       return arg1;
                   5049: 
                   5050:     case COMPLEX_EXPR:
                   5051:       if (wins)
                   5052:        return build_complex (arg0, arg1);
                   5053:       return t;
                   5054: 
                   5055:     case REALPART_EXPR:
                   5056:       if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
                   5057:        return t;
                   5058:       else if (TREE_CODE (arg0) == COMPLEX_EXPR)
                   5059:        return omit_one_operand (type, TREE_OPERAND (arg0, 0),
                   5060:                                 TREE_OPERAND (arg0, 1));
                   5061:       else if (TREE_CODE (arg0) == COMPLEX_CST)
                   5062:        return TREE_REALPART (arg0);
                   5063:       else if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
                   5064:        return fold (build (TREE_CODE (arg0), type,
                   5065:                            fold (build1 (REALPART_EXPR, type,
                   5066:                                          TREE_OPERAND (arg0, 0))),
                   5067:                            fold (build1 (REALPART_EXPR,
                   5068:                                          type, TREE_OPERAND (arg0, 1)))));
                   5069:       return t;
                   5070: 
                   5071:     case IMAGPART_EXPR:
                   5072:       if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
                   5073:        return convert (type, integer_zero_node);
                   5074:       else if (TREE_CODE (arg0) == COMPLEX_EXPR)
                   5075:        return omit_one_operand (type, TREE_OPERAND (arg0, 1),
                   5076:                                 TREE_OPERAND (arg0, 0));
                   5077:       else if (TREE_CODE (arg0) == COMPLEX_CST)
                   5078:        return TREE_IMAGPART (arg0);
                   5079:       else if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
                   5080:        return fold (build (TREE_CODE (arg0), type,
                   5081:                            fold (build1 (IMAGPART_EXPR, type,
                   5082:                                          TREE_OPERAND (arg0, 0))),
                   5083:                            fold (build1 (IMAGPART_EXPR, type,
                   5084:                                          TREE_OPERAND (arg0, 1)))));
1.1       root     5085:       return t;
                   5086: 
1.1.1.8 ! root     5087:       /* Pull arithmetic ops out of the CLEANUP_POINT_EXPR where
        !          5088:          appropriate.  */
        !          5089:     case CLEANUP_POINT_EXPR:
        !          5090:       if (! TREE_SIDE_EFFECTS (arg0))
        !          5091:        return convert (type, arg0);
        !          5092: 
        !          5093:       {
        !          5094:        enum tree_code code0 = TREE_CODE (arg0);
        !          5095:        int kind0 = TREE_CODE_CLASS (code0);
        !          5096:        tree arg00 = TREE_OPERAND (arg0, 0);
        !          5097:        tree arg01;
        !          5098: 
        !          5099:        if (kind0 == '1' || code0 == TRUTH_NOT_EXPR)
        !          5100:          return fold (build1 (code0, type, 
        !          5101:                               fold (build1 (CLEANUP_POINT_EXPR,
        !          5102:                                             TREE_TYPE (arg00), arg00))));
        !          5103: 
        !          5104:        if (kind0 == '<' || kind0 == '2'
        !          5105:            || code0 == TRUTH_ANDIF_EXPR || code0 == TRUTH_ORIF_EXPR
        !          5106:            || code0 == TRUTH_AND_EXPR   || code0 == TRUTH_OR_EXPR
        !          5107:            || code0 == TRUTH_XOR_EXPR)
        !          5108:          {
        !          5109:            arg01 = TREE_OPERAND (arg0, 1);
        !          5110: 
        !          5111:            if (! TREE_SIDE_EFFECTS (arg00))
        !          5112:              return fold (build (code0, type, arg00,
        !          5113:                                  fold (build1 (CLEANUP_POINT_EXPR,
        !          5114:                                                TREE_TYPE (arg01), arg01))));
        !          5115: 
        !          5116:            if (! TREE_SIDE_EFFECTS (arg01))
        !          5117:              return fold (build (code0, type,
        !          5118:                                  fold (build1 (CLEANUP_POINT_EXPR,
        !          5119:                                                TREE_TYPE (arg00), arg00)),
        !          5120:                                  arg01));
        !          5121:          }
        !          5122: 
        !          5123:        return t;
        !          5124:       }
        !          5125: 
1.1       root     5126:     default:
                   5127:       return t;
                   5128:     } /* switch (code) */
                   5129: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.