OSDN Git Service

* config/s390/s390.c: Follow spelling convention.
[pf3gnuchains/gcc-fork.git] / gcc / expmed.c
index 9435a62..317dcc4 100644 (file)
@@ -1,7 +1,7 @@
 /* Medium-level subroutines: convert bit-field store and extract
    and shifts, multiplies and divides to rtl instructions.
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -33,31 +33,29 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "optabs.h"
 #include "real.h"
 #include "recog.h"
+#include "langhooks.h"
 
 static void store_fixed_bit_field      PARAMS ((rtx, unsigned HOST_WIDE_INT,
                                                 unsigned HOST_WIDE_INT,
-                                                unsigned HOST_WIDE_INT, rtx,
-                                                unsigned int));
+                                                unsigned HOST_WIDE_INT, rtx));
 static void store_split_bit_field      PARAMS ((rtx, unsigned HOST_WIDE_INT,
-                                                unsigned HOST_WIDE_INT, rtx,
-                                                unsigned int));
+                                                unsigned HOST_WIDE_INT, rtx));
 static rtx extract_fixed_bit_field     PARAMS ((enum machine_mode, rtx,
                                                 unsigned HOST_WIDE_INT,
                                                 unsigned HOST_WIDE_INT,
                                                 unsigned HOST_WIDE_INT,
-                                                rtx, int, unsigned int));
+                                                rtx, int));
 static rtx mask_rtx                    PARAMS ((enum machine_mode, int,
                                                 int, int));
 static rtx lshift_value                        PARAMS ((enum machine_mode, rtx,
                                                 int, int));
 static rtx extract_split_bit_field     PARAMS ((rtx, unsigned HOST_WIDE_INT,
-                                                unsigned HOST_WIDE_INT, int,
-                                                unsigned int));
+                                                unsigned HOST_WIDE_INT, int));
 static void do_cmp_and_jump            PARAMS ((rtx, rtx, enum rtx_code,
                                                 enum machine_mode, rtx));
 
 /* Non-zero means divides or modulus operations are relatively cheap for
-   powers of two, so don't use branches; emit the operation instead. 
+   powers of two, so don't use branches; emit the operation instead.
    Usually, this will mean that the MD file will emit non-branch
    sequences.  */
 
@@ -106,16 +104,15 @@ static int mul_highpart_cost[NUM_MACHINE_MODES];
 void
 init_expmed ()
 {
-  /* This is "some random pseudo register" for purposes of calling recog
-     to see what insns exist.  */
-  rtx reg = gen_rtx_REG (word_mode, 10000);
-  rtx shift_insn, shiftadd_insn, shiftsub_insn;
+  rtx reg, shift_insn, shiftadd_insn, shiftsub_insn;
   int dummy;
   int m;
   enum machine_mode mode, wider_mode;
 
   start_sequence ();
 
+  /* This is "some random pseudo register" for purposes of calling recog
+     to see what insns exist.  */
   reg = gen_rtx_REG (word_mode, 10000);
 
   zero_cost = rtx_cost (const0_rtx, 0);
@@ -146,19 +143,18 @@ init_expmed ()
 
   for (m = 1; m < MAX_BITS_PER_WORD; m++)
     {
+      rtx c_int = GEN_INT ((HOST_WIDE_INT) 1 << m);
       shift_cost[m] = shiftadd_cost[m] = shiftsub_cost[m] = 32000;
 
       XEXP (SET_SRC (PATTERN (shift_insn)), 1) = GEN_INT (m);
       if (recog (PATTERN (shift_insn), shift_insn, &dummy) >= 0)
        shift_cost[m] = rtx_cost (SET_SRC (PATTERN (shift_insn)), SET);
 
-      XEXP (XEXP (SET_SRC (PATTERN (shiftadd_insn)), 0), 1)
-       = GEN_INT ((HOST_WIDE_INT) 1 << m);
+      XEXP (XEXP (SET_SRC (PATTERN (shiftadd_insn)), 0), 1) = c_int;
       if (recog (PATTERN (shiftadd_insn), shiftadd_insn, &dummy) >= 0)
        shiftadd_cost[m] = rtx_cost (SET_SRC (PATTERN (shiftadd_insn)), SET);
 
-      XEXP (XEXP (SET_SRC (PATTERN (shiftsub_insn)), 0), 1)
-       = GEN_INT ((HOST_WIDE_INT) 1 << m);
+      XEXP (XEXP (SET_SRC (PATTERN (shiftsub_insn)), 0), 1) = c_int;
       if (recog (PATTERN (shiftsub_insn), shiftsub_insn, &dummy) >= 0)
        shiftsub_cost[m] = rtx_cost (SET_SRC (PATTERN (shiftsub_insn)), SET);
     }
@@ -289,13 +285,12 @@ mode_for_extraction (pattern, opno)
    else, we use the mode of operand 3.  */
 
 rtx
-store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
+store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, total_size)
      rtx str_rtx;
      unsigned HOST_WIDE_INT bitsize;
      unsigned HOST_WIDE_INT bitnum;
      enum machine_mode fieldmode;
      rtx value;
-     unsigned int align;
      HOST_WIDE_INT total_size;
 {
   unsigned int unit
@@ -303,14 +298,10 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
   unsigned HOST_WIDE_INT offset = bitnum / unit;
   unsigned HOST_WIDE_INT bitpos = bitnum % unit;
   rtx op0 = str_rtx;
+  int byte_offset;
 
   enum machine_mode op_mode = mode_for_extraction (EP_insv, 3);
 
-  /* It is wrong to have align==0, since every object is aligned at
-     least at a bit boundary.  This usually means a bug elsewhere.  */
-  if (align == 0)
-    abort ();
-
   /* Discount the part of the structure before the desired byte.
      We need to know how many bytes are safe to reference after it.  */
   if (total_size >= 0)
@@ -333,7 +324,12 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
   value = protect_from_queue (value, 0);
 
   if (flag_force_mem)
-    value = force_not_mem (value);
+    {
+      int old_generating_concat_p = generating_concat_p;
+      generating_concat_p = 0;
+      value = force_not_mem (value);
+      generating_concat_p = old_generating_concat_p;
+    }
 
   /* If the target is a register, overwriting the entire object, or storing
      a full-word or multi-word field can be done with just a SUBREG.
@@ -341,15 +337,19 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
      If the target is memory, storing any naturally aligned field can be
      done with a simple store.  For targets that support fast unaligned
      memory, any naturally sized, unit aligned field can be done directly.  */
-     
+
+  byte_offset = (bitnum % BITS_PER_WORD) / BITS_PER_UNIT
+                + (offset * UNITS_PER_WORD);
+
   if (bitpos == 0
       && bitsize == GET_MODE_BITSIZE (fieldmode)
       && (GET_CODE (op0) != MEM
-         ? (GET_MODE_SIZE (fieldmode) >= UNITS_PER_WORD
+         ? ((GET_MODE_SIZE (fieldmode) >= UNITS_PER_WORD
             || GET_MODE_SIZE (GET_MODE (op0)) == GET_MODE_SIZE (fieldmode))
-         : (! SLOW_UNALIGNED_ACCESS (fieldmode, align)
+            && byte_offset % GET_MODE_SIZE (fieldmode) == 0)
+         : (! SLOW_UNALIGNED_ACCESS (fieldmode, MEM_ALIGN (op0))
             || (offset * BITS_PER_UNIT % bitsize == 0
-                && align % GET_MODE_BITSIZE (fieldmode) == 0))))
+                && MEM_ALIGN (op0) % GET_MODE_BITSIZE (fieldmode) == 0))))
     {
       if (GET_MODE (op0) != fieldmode)
        {
@@ -366,9 +366,7 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
                abort ();
            }
          if (GET_CODE (op0) == REG)
-           op0 = gen_rtx_SUBREG (fieldmode, op0,
-                                 (bitnum % BITS_PER_WORD) / BITS_PER_UNIT
-                                 + (offset * UNITS_PER_WORD));
+           op0 = gen_rtx_SUBREG (fieldmode, op0, byte_offset);
          else
            op0 = adjust_address (op0, fieldmode, offset);
        }
@@ -393,6 +391,15 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
       }
   }
 
+  /* We may be accessing data outside the field, which means
+     we can alias adjacent data.  */
+  if (GET_CODE (op0) == MEM)
+    {
+      op0 = shallow_copy_rtx (op0);
+      set_mem_alias_set (op0, 0);
+      set_mem_expr (op0, 0);
+    }
+
   /* If OP0 is a register, BITPOS must count within a word.
      But as we have it, it counts within whatever size OP0 now has.
      On a bigendian machine, these are not the same, so convert.  */
@@ -472,10 +479,10 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
             if I is 1, use the next to lowest word; and so on.  */
          unsigned int wordnum = (backwards ? nwords - i - 1 : i);
          unsigned int bit_offset = (backwards
-                           ? MAX ((int) bitsize - ((int) i + 1)
-                                  * BITS_PER_WORD,
-                                  0)
-                           : (int) i * BITS_PER_WORD);
+                                    ? MAX ((int) bitsize - ((int) i + 1)
+                                           * BITS_PER_WORD,
+                                           0)
+                                    : (int) i * BITS_PER_WORD);
 
          store_bit_field (op0, MIN (BITS_PER_WORD,
                                     bitsize - i * BITS_PER_WORD),
@@ -484,7 +491,7 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
                                                  (GET_MODE (value) == VOIDmode
                                                   ? fieldmode
                                                   : GET_MODE (value))),
-                          align, total_size);
+                          total_size);
        }
       return value;
     }
@@ -519,20 +526,15 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
       offset = 0;
     }
   else
-    {
-      op0 = protect_from_queue (op0, 1);
-    }
+    op0 = protect_from_queue (op0, 1);
 
   /* If VALUE is a floating-point mode, access it as an integer of the
      corresponding size.  This can occur on a machine with 64 bit registers
      that uses SFmode for float.  This can also occur for unaligned float
      structure fields.  */
-  if (GET_MODE_CLASS (GET_MODE (value)) == MODE_FLOAT)
-    {
-      if (GET_CODE (value) != REG)
-       value = copy_to_reg (value);
-      value = gen_rtx_SUBREG (word_mode, value, 0);
-    }
+  if (GET_MODE_CLASS (GET_MODE (value)) != MODE_INT
+      && GET_MODE_CLASS (GET_MODE (value)) != MODE_PARTIAL_INT)
+    value = gen_lowpart (word_mode, value);
 
   /* Now OFFSET is nonzero only if OP0 is memory
      and is therefore always measured in bytes.  */
@@ -574,19 +576,19 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
          if (GET_MODE (op0) == BLKmode
              || GET_MODE_SIZE (GET_MODE (op0)) > GET_MODE_SIZE (maxmode))
            bestmode
-             = get_best_mode (bitsize, bitnum, align, maxmode,
+             = get_best_mode (bitsize, bitnum, MEM_ALIGN (op0), maxmode,
                               MEM_VOLATILE_P (op0));
          else
            bestmode = GET_MODE (op0);
 
          if (bestmode == VOIDmode
-             || (SLOW_UNALIGNED_ACCESS (bestmode, align)
-                 && GET_MODE_BITSIZE (bestmode) > align))
+             || (SLOW_UNALIGNED_ACCESS (bestmode, MEM_ALIGN (op0))
+                 && GET_MODE_BITSIZE (bestmode) > MEM_ALIGN (op0)))
            goto insv_loses;
 
-         /* Adjust address to point to the containing unit of that mode.  */
+         /* Adjust address to point to the containing unit of that mode.
+            Compute offset as multiple of this unit, counting in bytes.  */
          unit = GET_MODE_BITSIZE (bestmode);
-         /* Compute offset as multiple of this unit, counting in bytes.  */
          offset = (bitnum / unit) * GET_MODE_SIZE (bestmode);
          bitpos = bitnum % unit;
          op0 = adjust_address (op0, bestmode,  offset);
@@ -595,7 +597,7 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
             the unit.  */
          tempreg = copy_to_reg (op0);
          store_bit_field (tempreg, bitsize, bitpos, fieldmode, value,
-                          align, total_size);
+                          total_size);
          emit_move_insn (op0, tempreg);
          return value;
        }
@@ -638,12 +640,22 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
                 if we must narrow it, be sure we do it correctly.  */
 
              if (GET_MODE_SIZE (GET_MODE (value)) < GET_MODE_SIZE (maxmode))
-               value1 = simplify_gen_subreg (maxmode, value1, GET_MODE (value1), 0);
+               {
+                 rtx tmp;
+
+                 tmp = simplify_subreg (maxmode, value1, GET_MODE (value), 0);
+                 if (! tmp)
+                   tmp = simplify_gen_subreg (maxmode,
+                                              force_reg (GET_MODE (value),
+                                                         value1),
+                                              GET_MODE (value), 0);
+                 value1 = tmp;
+               }
              else
                value1 = gen_lowpart (maxmode, value1);
            }
          else if (GET_CODE (value) == CONST_INT)
-           value1 = GEN_INT (trunc_int_for_mode (INTVAL (value), maxmode));
+           value1 = gen_int_mode (INTVAL (value), maxmode);
          else if (!CONSTANT_P (value))
            /* Parse phase is supposed to make VALUE's data type
               match that of the component reference, which is a type
@@ -662,15 +674,15 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
       if (pat)
        emit_insn (pat);
       else
-        {
+       {
          delete_insns_since (last);
-         store_fixed_bit_field (op0, offset, bitsize, bitpos, value, align);
+         store_fixed_bit_field (op0, offset, bitsize, bitpos, value);
        }
     }
   else
     insv_loses:
     /* Insv is not available; store using shifts and boolean ops.  */
-    store_fixed_bit_field (op0, offset, bitsize, bitpos, value, align);
+    store_fixed_bit_field (op0, offset, bitsize, bitpos, value);
   return value;
 }
 \f
@@ -682,16 +694,14 @@ store_bit_field (str_rtx, bitsize, bitnum, fieldmode, value, align, total_size)
     (If OP0 is a register, it may be a full word or a narrower mode,
      but BITPOS still counts within a full word,
      which is significant on bigendian machines.)
-   STRUCT_ALIGN is the alignment the structure is known to have.
 
    Note that protect_from_queue has already been done on OP0 and VALUE.  */
 
 static void
-store_fixed_bit_field (op0, offset, bitsize, bitpos, value, struct_align)
+store_fixed_bit_field (op0, offset, bitsize, bitpos, value)
      rtx op0;
      unsigned HOST_WIDE_INT offset, bitsize, bitpos;
      rtx value;
-     unsigned int struct_align;
 {
   enum machine_mode mode;
   unsigned int total_bits = BITS_PER_WORD;
@@ -699,9 +709,6 @@ store_fixed_bit_field (op0, offset, bitsize, bitpos, value, struct_align)
   int all_zero = 0;
   int all_one = 0;
 
-  if (! SLOW_UNALIGNED_ACCESS (word_mode, struct_align))
-    struct_align = BIGGEST_ALIGNMENT;
-    
   /* There is a case not handled here:
      a structure with a known alignment of just a halfword
      and a field split across two aligned halfwords within the structure.
@@ -716,8 +723,7 @@ store_fixed_bit_field (op0, offset, bitsize, bitpos, value, struct_align)
       /* Special treatment for a bit field split across two registers.  */
       if (bitsize + bitpos > BITS_PER_WORD)
        {
-         store_split_bit_field (op0, bitsize, bitpos,
-                                value, BITS_PER_WORD);
+         store_split_bit_field (op0, bitsize, bitpos, value);
          return;
        }
     }
@@ -725,24 +731,22 @@ store_fixed_bit_field (op0, offset, bitsize, bitpos, value, struct_align)
     {
       /* Get the proper mode to use for this field.  We want a mode that
         includes the entire field.  If such a mode would be larger than
-        a word, we won't be doing the extraction the normal way.  
+        a word, we won't be doing the extraction the normal way.
         We don't want a mode bigger than the destination.  */
 
       mode = GET_MODE (op0);
       if (GET_MODE_BITSIZE (mode) == 0
-          || GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (word_mode))
-        mode = word_mode;
+         || GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (word_mode))
+       mode = word_mode;
       mode = get_best_mode (bitsize, bitpos + offset * BITS_PER_UNIT,
-                           struct_align, mode,
-                           GET_CODE (op0) == MEM && MEM_VOLATILE_P (op0));
+                           MEM_ALIGN (op0), mode, MEM_VOLATILE_P (op0));
 
       if (mode == VOIDmode)
        {
          /* The only way this should occur is if the field spans word
             boundaries.  */
-         store_split_bit_field (op0,
-                                bitsize, bitpos + offset * BITS_PER_UNIT,
-                                value, struct_align);
+         store_split_bit_field (op0, bitsize, bitpos + offset * BITS_PER_UNIT,
+                                value);
          return;
        }
 
@@ -856,17 +860,14 @@ store_fixed_bit_field (op0, offset, bitsize, bitpos, value, struct_align)
    BITSIZE is the field width; BITPOS the position of its first bit
    (within the word).
    VALUE is the value to store.
-   ALIGN is the known alignment of OP0.
-   This is also the size of the memory objects to be used.
 
    This does not yet handle fields wider than BITS_PER_WORD.  */
 
 static void
-store_split_bit_field (op0, bitsize, bitpos, value, align)
+store_split_bit_field (op0, bitsize, bitpos, value)
      rtx op0;
      unsigned HOST_WIDE_INT bitsize, bitpos;
      rtx value;
-     unsigned int align;
 {
   unsigned int unit;
   unsigned int bitsdone = 0;
@@ -876,7 +877,7 @@ store_split_bit_field (op0, bitsize, bitpos, value, align)
   if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG)
     unit = BITS_PER_WORD;
   else
-    unit = MIN (align, BITS_PER_WORD);
+    unit = MIN (MEM_ALIGN (op0), BITS_PER_WORD);
 
   /* If VALUE is a constant other than a CONST_INT, get it into a register in
      WORD_MODE.  If we can do this using gen_lowpart_common, do so.  Note
@@ -932,18 +933,10 @@ store_split_bit_field (op0, bitsize, bitpos, value, align)
          else
            /* The args are chosen so that the last part includes the
               lsb.  Give extract_bit_field the value it needs (with
-              endianness compensation) to fetch the piece we want.
-
-              ??? We have no idea what the alignment of VALUE is, so
-              we have to use a guess.  */
-           part
-             = extract_fixed_bit_field
-               (word_mode, value, 0, thissize,
-                total_bits - bitsize + bitsdone, NULL_RTX, 1,
-                GET_MODE (value) == VOIDmode
-                ? UNITS_PER_WORD
-                : (GET_MODE (value) == BLKmode
-                   ? 1 : GET_MODE_ALIGNMENT (GET_MODE (value))));
+              endianness compensation) to fetch the piece we want.  */
+           part = extract_fixed_bit_field (word_mode, value, 0, thissize,
+                                           total_bits - bitsize + bitsdone,
+                                           NULL_RTX, 1);
        }
       else
        {
@@ -953,13 +946,8 @@ store_split_bit_field (op0, bitsize, bitpos, value, align)
                             >> bitsdone)
                            & (((HOST_WIDE_INT) 1 << thissize) - 1));
          else
-           part
-             = extract_fixed_bit_field
-               (word_mode, value, 0, thissize, bitsdone, NULL_RTX, 1,
-                GET_MODE (value) == VOIDmode
-                ? UNITS_PER_WORD
-                : (GET_MODE (value) == BLKmode
-                   ? 1 : GET_MODE_ALIGNMENT (GET_MODE (value))));
+           part = extract_fixed_bit_field (word_mode, value, 0, thissize,
+                                           bitsdone, NULL_RTX, 1);
        }
 
       /* If OP0 is a register, then handle OFFSET here.
@@ -985,8 +973,8 @@ store_split_bit_field (op0, bitsize, bitpos, value, align)
 
       /* OFFSET is in UNITs, and UNIT is in bits.
          store_fixed_bit_field wants offset in bytes.  */
-      store_fixed_bit_field (word, offset * unit / BITS_PER_UNIT,
-                            thissize, thispos, part, align);
+      store_fixed_bit_field (word, offset * unit / BITS_PER_UNIT, thissize,
+                            thispos, part);
       bitsdone += thissize;
     }
 }
@@ -1003,7 +991,6 @@ store_split_bit_field (op0, bitsize, bitpos, value, align)
    TMODE is the mode the caller would like the value to have;
    but the value may be returned with type MODE instead.
 
-   ALIGN is the alignment that STR_RTX is known to have.
    TOTAL_SIZE is the size in bytes of the containing structure,
    or -1 if varying.
 
@@ -1014,14 +1001,13 @@ store_split_bit_field (op0, bitsize, bitpos, value, align)
 
 rtx
 extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
-                  target, mode, tmode, align, total_size)
+                  target, mode, tmode, total_size)
      rtx str_rtx;
      unsigned HOST_WIDE_INT bitsize;
      unsigned HOST_WIDE_INT bitnum;
      int unsignedp;
      rtx target;
      enum machine_mode mode, tmode;
-     unsigned int align;
      HOST_WIDE_INT total_size;
 {
   unsigned int unit
@@ -1034,6 +1020,8 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
   enum machine_mode int_mode;
   enum machine_mode extv_mode = mode_for_extraction (EP_extv, 0);
   enum machine_mode extzv_mode = mode_for_extraction (EP_extzv, 0);
+  enum machine_mode mode1;
+  int byte_offset;
 
   /* Discount the part of the structure before the desired byte.
      We need to know how many bytes are safe to reference after it.  */
@@ -1089,10 +1077,19 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
       }
   }
 
+  /* We may be accessing data outside the field, which means
+     we can alias adjacent data.  */
+  if (GET_CODE (op0) == MEM)
+    {
+      op0 = shallow_copy_rtx (op0);
+      set_mem_alias_set (op0, 0);
+      set_mem_expr (op0, 0);
+    }
+
   /* ??? We currently assume TARGET is at least as big as BITSIZE.
      If that's wrong, the solution is to test for it and set TARGET to 0
      if needed.  */
-  
+
   /* If OP0 is a register, BITPOS must count within a word.
      But as we have it, it counts within whatever size OP0 now has.
      On a bigendian machine, these are not the same, so convert.  */
@@ -1107,13 +1104,22 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
      So too extracting a subword value in
      the least significant part of the register.  */
 
+  byte_offset = (bitnum % BITS_PER_WORD) / BITS_PER_UNIT
+                + (offset * UNITS_PER_WORD);
+
+  mode1  = (VECTOR_MODE_P (tmode)
+           ? mode
+           : mode_for_size (bitsize, GET_MODE_CLASS (tmode), 0));
+
   if (((GET_CODE (op0) != MEM
        && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
-                                 GET_MODE_BITSIZE (GET_MODE (op0))))
+                                 GET_MODE_BITSIZE (GET_MODE (op0)))
+       && GET_MODE_SIZE (mode1) != 0
+       && byte_offset % GET_MODE_SIZE (mode1) == 0)
        || (GET_CODE (op0) == MEM
-          && (! SLOW_UNALIGNED_ACCESS (mode, align)
+          && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (op0))
               || (offset * BITS_PER_UNIT % bitsize == 0
-                  && align % bitsize == 0))))
+                  && MEM_ALIGN (op0) % bitsize == 0))))
       && ((bitsize >= BITS_PER_WORD && bitsize == GET_MODE_BITSIZE (mode)
           && bitpos % BITS_PER_WORD == 0)
          || (mode_for_size (bitsize, GET_MODE_CLASS (tmode), 0) != BLKmode
@@ -1125,10 +1131,6 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
                  ? bitpos + bitsize == BITS_PER_WORD
                  : bitpos == 0))))
     {
-      enum machine_mode mode1
-       = (VECTOR_MODE_P (tmode) ? mode
-          : mode_for_size (bitsize, GET_MODE_CLASS (tmode), 0));
-
       if (mode1 != GET_MODE (op0))
        {
          if (GET_CODE (op0) == SUBREG)
@@ -1141,12 +1143,10 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
                /* Else we've got some float mode source being extracted into
                   a different float mode destination -- this combination of
                   subregs results in Severe Tire Damage.  */
-               abort ();
+               goto no_subreg_mode_swap;
            }
          if (GET_CODE (op0) == REG)
-           op0 = gen_rtx_SUBREG (mode1, op0,
-                                 (bitnum % BITS_PER_WORD) / BITS_PER_UNIT
-                                 + (offset * UNITS_PER_WORD));
+           op0 = gen_rtx_SUBREG (mode1, op0, byte_offset);
          else
            op0 = adjust_address (op0, mode1, offset);
        }
@@ -1154,9 +1154,10 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
        return convert_to_mode (tmode, op0, unsignedp);
       return op0;
     }
+ no_subreg_mode_swap:
 
   /* Handle fields bigger than a word.  */
-  
+
   if (bitsize > BITS_PER_WORD)
     {
       /* Here we transfer the words of the field
@@ -1192,7 +1193,7 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
            = extract_bit_field (op0, MIN (BITS_PER_WORD,
                                           bitsize - i * BITS_PER_WORD),
                                 bitnum + bit_offset, 1, target_part, mode,
-                                word_mode, align, total_size);
+                                word_mode, total_size);
 
          if (target_part == 0)
            abort ();
@@ -1211,11 +1212,11 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
 
              total_words = GET_MODE_SIZE (GET_MODE (target)) / UNITS_PER_WORD;
              for (i = nwords; i < total_words; i++)
-               {
-                 int wordnum = WORDS_BIG_ENDIAN ? total_words - i - 1 : i;
-                 rtx target_part = operand_subword (target, wordnum, 1, VOIDmode);
-                 emit_move_insn (target_part, const0_rtx);
-               }
+               emit_move_insn
+                 (operand_subword (target,
+                                   WORDS_BIG_ENDIAN ? total_words - i - 1 : i,
+                                   1, VOIDmode),
+                  const0_rtx);
            }
          return target;
        }
@@ -1228,20 +1229,20 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
                           build_int_2 (GET_MODE_BITSIZE (mode) - bitsize, 0),
                           NULL_RTX, 0);
     }
-  
+
   /* From here on we know the desired field is smaller than a word.  */
 
   /* Check if there is a correspondingly-sized integer field, so we can
      safely extract it as one size of integer, if necessary; then
      truncate or extend to the size that is wanted; then use SUBREGs or
      convert_to_mode to get one of the modes we really wanted.  */
-  
+
   int_mode = int_mode_for_mode (tmode);
   if (int_mode == BLKmode)
     int_mode = int_mode_for_mode (mode);
   if (int_mode == BLKmode)
-    abort();    /* Should probably push op0 out to memory and then
-                  do a load.  */
+    abort ();    /* Should probably push op0 out to memory and then
+                   do a load.  */
 
   /* OFFSET is the number of words or bytes (UNIT says which)
      from STR_RTX to the first word or byte containing part of the field.  */
@@ -1259,9 +1260,7 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
       offset = 0;
     }
   else
-    {
-      op0 = protect_from_queue (str_rtx, 1);
-    }
+    op0 = protect_from_queue (str_rtx, 1);
 
   /* Now OFFSET is nonzero only for memory operands.  */
 
@@ -1303,14 +1302,15 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
                  if (GET_MODE (xop0) == BLKmode
                      || (GET_MODE_SIZE (GET_MODE (op0))
                          > GET_MODE_SIZE (maxmode)))
-                   bestmode = get_best_mode (bitsize, bitnum, align, maxmode,
+                   bestmode = get_best_mode (bitsize, bitnum,
+                                             MEM_ALIGN (xop0), maxmode,
                                              MEM_VOLATILE_P (xop0));
                  else
                    bestmode = GET_MODE (xop0);
 
                  if (bestmode == VOIDmode
-                     || (SLOW_UNALIGNED_ACCESS (bestmode, align)
-                         && GET_MODE_BITSIZE (bestmode) > align))
+                     || (SLOW_UNALIGNED_ACCESS (bestmode, MEM_ALIGN (xop0))
+                         && GET_MODE_BITSIZE (bestmode) > MEM_ALIGN (xop0)))
                    goto extzv_loses;
 
                  /* Compute offset as multiple of this unit,
@@ -1390,13 +1390,13 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
            {
              delete_insns_since (last);
              target = extract_fixed_bit_field (int_mode, op0, offset, bitsize,
-                                               bitpos, target, 1, align);
+                                               bitpos, target, 1);
            }
        }
       else
-        extzv_loses:
-      target = extract_fixed_bit_field (int_mode, op0, offset, bitsize, 
-                                       bitpos, target, 1, align);
+      extzv_loses:
+       target = extract_fixed_bit_field (int_mode, op0, offset, bitsize,
+                                         bitpos, target, 1);
     }
   else
     {
@@ -1432,14 +1432,15 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
                  if (GET_MODE (xop0) == BLKmode
                      || (GET_MODE_SIZE (GET_MODE (op0))
                          > GET_MODE_SIZE (maxmode)))
-                   bestmode = get_best_mode (bitsize, bitnum, align, maxmode,
+                   bestmode = get_best_mode (bitsize, bitnum,
+                                             MEM_ALIGN (xop0), maxmode,
                                              MEM_VOLATILE_P (xop0));
                  else
                    bestmode = GET_MODE (xop0);
 
                  if (bestmode == VOIDmode
-                     || (SLOW_UNALIGNED_ACCESS (bestmode, align)
-                         && GET_MODE_BITSIZE (bestmode) > align))
+                     || (SLOW_UNALIGNED_ACCESS (bestmode, MEM_ALIGN (xop0))
+                         && GET_MODE_BITSIZE (bestmode) > MEM_ALIGN (xop0)))
                    goto extv_loses;
 
                  /* Compute offset as multiple of this unit,
@@ -1518,13 +1519,13 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
            {
              delete_insns_since (last);
              target = extract_fixed_bit_field (int_mode, op0, offset, bitsize,
-                                               bitpos, target, 0, align);
+                                               bitpos, target, 0);
            }
-       } 
+       }
       else
-       extv_loses:
-      target = extract_fixed_bit_field (int_mode, op0, offset, bitsize, 
-                                       bitpos, target, 0, align);
+      extv_loses:
+       target = extract_fixed_bit_field (int_mode, op0, offset, bitsize,
+                                         bitpos, target, 0);
     }
   if (target == spec_target)
     return target;
@@ -1535,14 +1536,13 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
       /* If the target mode is floating-point, first convert to the
         integer mode of that size and then access it as a floating-point
         value via a SUBREG.  */
-      if (GET_MODE_CLASS (tmode) == MODE_FLOAT)
+      if (GET_MODE_CLASS (tmode) != MODE_INT
+         && GET_MODE_CLASS (tmode) != MODE_PARTIAL_INT)
        {
          target = convert_to_mode (mode_for_size (GET_MODE_BITSIZE (tmode),
                                                   MODE_INT, 0),
                                    target, unsignedp);
-         if (GET_CODE (target) != REG)
-           target = copy_to_reg (target);
-         return gen_rtx_SUBREG (tmode, target, 0);
+         return gen_lowpart (tmode, target);
        }
       else
        return convert_to_mode (tmode, target, unsignedp);
@@ -1564,18 +1564,15 @@ extract_bit_field (str_rtx, bitsize, bitnum, unsignedp,
    UNSIGNEDP is nonzero for an unsigned bit field (don't sign-extend value).
    If TARGET is nonzero, attempts to store the value there
    and return TARGET, but this is not guaranteed.
-   If TARGET is not used, create a pseudo-reg of mode TMODE for the value.
-
-   ALIGN is the alignment that STR_RTX is known to have.  */
+   If TARGET is not used, create a pseudo-reg of mode TMODE for the value.  */
 
 static rtx
 extract_fixed_bit_field (tmode, op0, offset, bitsize, bitpos,
-                        target, unsignedp, align)
+                        target, unsignedp)
      enum machine_mode tmode;
      rtx op0, target;
      unsigned HOST_WIDE_INT offset, bitsize, bitpos;
      int unsignedp;
-     unsigned int align;
 {
   unsigned int total_bits = BITS_PER_WORD;
   enum machine_mode mode;
@@ -1584,8 +1581,7 @@ extract_fixed_bit_field (tmode, op0, offset, bitsize, bitpos,
     {
       /* Special treatment for a bit field split across two registers.  */
       if (bitsize + bitpos > BITS_PER_WORD)
-       return extract_split_bit_field (op0, bitsize, bitpos,
-                                       unsignedp, align);
+       return extract_split_bit_field (op0, bitsize, bitpos, unsignedp);
     }
   else
     {
@@ -1593,16 +1589,15 @@ extract_fixed_bit_field (tmode, op0, offset, bitsize, bitpos,
         includes the entire field.  If such a mode would be larger than
         a word, we won't be doing the extraction the normal way.  */
 
-      mode = get_best_mode (bitsize, bitpos + offset * BITS_PER_UNIT, align,
-                           word_mode,
-                           GET_CODE (op0) == MEM && MEM_VOLATILE_P (op0));
+      mode = get_best_mode (bitsize, bitpos + offset * BITS_PER_UNIT,
+                           MEM_ALIGN (op0), word_mode, MEM_VOLATILE_P (op0));
 
       if (mode == VOIDmode)
        /* The only way this should occur is if the field spans word
           boundaries.  */
        return extract_split_bit_field (op0, bitsize,
                                        bitpos + offset * BITS_PER_UNIT,
-                                       unsignedp, align);
+                                       unsignedp);
 
       total_bits = GET_MODE_BITSIZE (mode);
 
@@ -1628,12 +1623,9 @@ extract_fixed_bit_field (tmode, op0, offset, bitsize, bitpos,
   mode = GET_MODE (op0);
 
   if (BYTES_BIG_ENDIAN)
-    {
-      /* BITPOS is the distance between our msb and that of OP0.
-        Convert it to the distance from the lsb.  */
-
-      bitpos = total_bits - bitsize - bitpos;
-    }
+    /* BITPOS is the distance between our msb and that of OP0.
+       Convert it to the distance from the lsb.  */
+    bitpos = total_bits - bitsize - bitpos;
 
   /* Now BITPOS is always the distance between the field's lsb and that of OP0.
      We have reduced the big-endian case to the little-endian case.  */
@@ -1660,16 +1652,7 @@ extract_fixed_bit_field (tmode, op0, offset, bitsize, bitpos,
       /* Unless the msb of the field used to be the msb when we shifted,
         mask out the upper bits.  */
 
-      if (GET_MODE_BITSIZE (mode) != bitpos + bitsize
-#if 0
-#ifdef SLOW_ZERO_EXTEND
-         /* Always generate an `and' if
-            we just zero-extended op0 and SLOW_ZERO_EXTEND, since it
-            will combine fruitfully with the zero-extend.  */
-         || tmode != mode
-#endif
-#endif
-         )
+      if (GET_MODE_BITSIZE (mode) != bitpos + bitsize)
        return expand_binop (GET_MODE (op0), and_optab, op0,
                             mask_rtx (GET_MODE (op0), 0, bitsize, 0),
                             target, 1, OPTAB_LIB_WIDEN);
@@ -1694,7 +1677,8 @@ extract_fixed_bit_field (tmode, op0, offset, bitsize, bitpos,
 
   if (GET_MODE_BITSIZE (mode) != (bitsize + bitpos))
     {
-      tree amount = build_int_2 (GET_MODE_BITSIZE (mode) - (bitsize + bitpos), 0);
+      tree amount
+       = build_int_2 (GET_MODE_BITSIZE (mode) - (bitsize + bitpos), 0);
       /* Maybe propagate the target for the shift.  */
       /* But not if we will return the result--could confuse integrate.c.  */
       rtx subtarget = (target != 0 && GET_CODE (target) == REG
@@ -1704,7 +1688,7 @@ extract_fixed_bit_field (tmode, op0, offset, bitsize, bitpos,
     }
 
   return expand_shift (RSHIFT_EXPR, mode, op0,
-                      build_int_2 (GET_MODE_BITSIZE (mode) - bitsize, 0), 
+                      build_int_2 (GET_MODE_BITSIZE (mode) - bitsize, 0),
                       target, 0);
 }
 \f
@@ -1729,7 +1713,7 @@ mask_rtx (mode, bitpos, bitsize, complement)
   if (bitpos + bitsize < HOST_BITS_PER_WIDE_INT)
     masklow &= ((unsigned HOST_WIDE_INT) -1
                >> (HOST_BITS_PER_WIDE_INT - bitpos - bitsize));
-  
+
   if (bitpos <= HOST_BITS_PER_WIDE_INT)
     maskhigh = -1;
   else
@@ -1784,17 +1768,13 @@ lshift_value (mode, value, bitpos, bitsize)
 
    OP0 is the REG, SUBREG or MEM rtx for the first of the two words.
    BITSIZE is the field width; BITPOS, position of its first bit, in the word.
-   UNSIGNEDP is 1 if should zero-extend the contents; else sign-extend.
-
-   ALIGN is the known alignment of OP0.  This is also the size of the
-   memory objects to be used.  */
+   UNSIGNEDP is 1 if should zero-extend the contents; else sign-extend.  */
 
 static rtx
-extract_split_bit_field (op0, bitsize, bitpos, unsignedp, align)
+extract_split_bit_field (op0, bitsize, bitpos, unsignedp)
      rtx op0;
      unsigned HOST_WIDE_INT bitsize, bitpos;
      int unsignedp;
-     unsigned int align;
 {
   unsigned int unit;
   unsigned int bitsdone = 0;
@@ -1806,7 +1786,7 @@ extract_split_bit_field (op0, bitsize, bitpos, unsignedp, align)
   if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG)
     unit = BITS_PER_WORD;
   else
-    unit = MIN (align, BITS_PER_WORD);
+    unit = MIN (MEM_ALIGN (op0), BITS_PER_WORD);
 
   while (bitsdone < bitsize)
     {
@@ -1851,7 +1831,7 @@ extract_split_bit_field (op0, bitsize, bitpos, unsignedp, align)
         extract_fixed_bit_field wants offset in bytes.  */
       part = extract_fixed_bit_field (word_mode, word,
                                      offset * unit / BITS_PER_UNIT,
-                                     thissize, thispos, 0, 1, align);
+                                     thissize, thispos, 0, 1);
       bitsdone += thissize;
 
       /* Shift this part into place for the result.  */
@@ -1947,12 +1927,12 @@ expand_shift (code, mode, shifted, amount, target, unsignedp)
   if (SHIFT_COUNT_TRUNCATED)
     {
       if (GET_CODE (op1) == CONST_INT
-          && ((unsigned HOST_WIDE_INT) INTVAL (op1) >=
+         && ((unsigned HOST_WIDE_INT) INTVAL (op1) >=
              (unsigned HOST_WIDE_INT) GET_MODE_BITSIZE (mode)))
-        op1 = GEN_INT ((unsigned HOST_WIDE_INT) INTVAL (op1)
+       op1 = GEN_INT ((unsigned HOST_WIDE_INT) INTVAL (op1)
                       % GET_MODE_BITSIZE (mode));
       else if (GET_CODE (op1) == SUBREG
-              && SUBREG_BYTE (op1) == 0)
+              && subreg_lowpart_p (op1))
        op1 = SUBREG_REG (op1);
     }
 #endif
@@ -2023,7 +2003,7 @@ expand_shift (code, mode, shifted, amount, target, unsignedp)
              && (unsigned int) INTVAL (op1) < GET_MODE_BITSIZE (mode))
            temp = expand_binop (mode,
                                 left ? rotr_optab : rotl_optab,
-                                shifted, 
+                                shifted,
                                 GEN_INT (GET_MODE_BITSIZE (mode)
                                          - INTVAL (op1)),
                                 target, unsignedp, methods);
@@ -2054,7 +2034,7 @@ expand_shift (code, mode, shifted, amount, target, unsignedp)
        }
 
       /* We used to try extzv here for logical right shifts, but that was
-        only useful for one machine, the VAX, and caused poor code 
+        only useful for one machine, the VAX, and caused poor code
         generation there for lshrdi3, so the code was deleted and a
         define_expand for lshrsi3 was added to vax.md.  */
     }
@@ -2195,7 +2175,7 @@ synth_mult (alg_out, t, cost_limit)
       for (w = 1; (w & t) != 0; w <<= 1)
        ;
       /* If T was -1, then W will be zero after the loop.  This is another
-        case where T ends with ...111.  Handling this with (T + 1) and 
+        case where T ends with ...111.  Handling this with (T + 1) and
         subtract 1 produces slightly better code and results in algorithm
         selection much faster than treating it like the ...0111 case
         below.  */
@@ -2475,7 +2455,7 @@ expand_mult (mode, op0, op1, target, unsignedp)
                   && ! preserve)
                  ? target : 0;
              rtx accum_target = preserve ? 0 : accum;
-             
+
              switch (alg.op[opno])
                {
                case alg_shift:
@@ -2557,7 +2537,7 @@ expand_mult (mode, op0, op1, target, unsignedp)
                }
 
              insn = get_last_insn ();
-             set_unique_reg_note (insn, 
+             set_unique_reg_note (insn,
                                   REG_EQUAL,
                                   gen_rtx_MULT (nmode, tem,
                                                 GEN_INT (val_so_far)));
@@ -2583,10 +2563,10 @@ expand_mult (mode, op0, op1, target, unsignedp)
 
   /* This used to use umul_optab if unsigned, but for non-widening multiply
      there is no difference between signed and unsigned.  */
-  op0 = expand_binop (mode, 
+  op0 = expand_binop (mode,
                      ! unsignedp
-                       && flag_trapv && (GET_MODE_CLASS(mode) == MODE_INT)
-                       ? smulv_optab : smul_optab,
+                     && flag_trapv && (GET_MODE_CLASS(mode) == MODE_INT)
+                     ? smulv_optab : smul_optab,
                      op0, op1, target, unsignedp, OPTAB_LIB_WIDEN);
   if (op0 == 0)
     abort ();
@@ -2679,7 +2659,7 @@ choose_multiplier (d, n, precision, multiplier_ptr, post_shift_ptr, lgup_ptr)
     abort ();
   /* assert that mlow < mhigh.  */
   if (! (mlow_hi < mhigh_hi || (mlow_hi == mhigh_hi && mlow_lo < mhigh_lo)))
-    abort();
+    abort ();
 
   /* If precision == N, then mlow, mhigh exceed 2^N
      (but they do not exceed 2^(N+1)).  */
@@ -2765,7 +2745,7 @@ expand_mult_highpart_adjust (mode, adj_operand, op0, op1, target, unsignedp)
   tem = expand_shift (RSHIFT_EXPR, mode, op0,
                      build_int_2 (GET_MODE_BITSIZE (mode) - 1, 0),
                      NULL_RTX, 0);
-  tem = expand_and (tem, op1, NULL_RTX);
+  tem = expand_and (mode, tem, op1, NULL_RTX);
   adj_operand
     = force_operand (gen_rtx_fmt_ee (adj_code, mode, adj_operand, tem),
                     adj_operand);
@@ -2773,7 +2753,7 @@ expand_mult_highpart_adjust (mode, adj_operand, op0, op1, target, unsignedp)
   tem = expand_shift (RSHIFT_EXPR, mode, op1,
                      build_int_2 (GET_MODE_BITSIZE (mode) - 1, 0),
                      NULL_RTX, 0);
-  tem = expand_and (tem, op0, NULL_RTX);
+  tem = expand_and (mode, tem, op0, NULL_RTX);
   target = force_operand (gen_rtx_fmt_ee (adj_code, mode, adj_operand, tem),
                          target);
 
@@ -2809,17 +2789,14 @@ expand_mult_highpart (mode, op0, cnst1, target, unsignedp, max_cost)
   if (size > HOST_BITS_PER_WIDE_INT)
     abort ();
 
-  op1 = GEN_INT (trunc_int_for_mode (cnst1, mode));
+  op1 = gen_int_mode (cnst1, mode);
 
-  if (GET_MODE_BITSIZE (wider_mode) <= HOST_BITS_PER_INT)
-    wide_op1 = op1;
-  else
-    wide_op1
-      = immed_double_const (cnst1,
-                           (unsignedp
-                            ? (HOST_WIDE_INT) 0
-                            : -(cnst1 >> (HOST_BITS_PER_WIDE_INT - 1))),
-                           wider_mode);
+  wide_op1
+    = immed_double_const (cnst1,
+                         (unsignedp
+                          ? (HOST_WIDE_INT) 0
+                          : -(cnst1 >> (HOST_BITS_PER_WIDE_INT - 1))),
+                         wider_mode);
 
   /* expand_mult handles constant multiplication of word_mode
      or narrower.  It does a poor job for large modes.  */
@@ -2874,7 +2851,7 @@ expand_mult_highpart (mode, op0, cnst1, target, unsignedp, max_cost)
     {
       op1 = force_reg (mode, op1);
       goto try;
-    } 
+    }
 
   /* Try widening the mode and perform a non-widening multiplication.  */
   moptab = smul_optab;
@@ -3034,9 +3011,9 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
   if (! unsignedp && op1 == constm1_rtx)
     {
       if (rem_flag)
-        return const0_rtx;
+       return const0_rtx;
       return expand_unop (mode, flag_trapv && GET_MODE_CLASS(mode) == MODE_INT
-                        ? negv_optab : neg_optab, op0, target, 0);
+                         ? negv_optab : neg_optab, op0, target, 0);
     }
 
   if (target
@@ -3072,9 +3049,12 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
      not straightforward to generalize this.  Maybe we should make an array
      of possible modes in init_expmed?  Save this for GCC 2.7.  */
 
-  optab1 = (op1_is_pow2 ? (unsignedp ? lshr_optab : ashr_optab)
+  optab1 = ((op1_is_pow2 && op1 != const0_rtx)
+           ? (unsignedp ? lshr_optab : ashr_optab)
            : (unsignedp ? udiv_optab : sdiv_optab));
-  optab2 = (op1_is_pow2 ? optab1 : (unsignedp ? udivmod_optab : sdivmod_optab));
+  optab2 = ((op1_is_pow2 && op1 != const0_rtx)
+           ? optab1
+           : (unsignedp ? udivmod_optab : sdivmod_optab));
 
   for (compute_mode = mode; compute_mode != VOIDmode;
        compute_mode = GET_MODE_WIDER_MODE (compute_mode))
@@ -3281,7 +3261,7 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
                if (insn != last
                    && (set = single_set (insn)) != 0
                    && SET_DEST (set) == quotient)
-                 set_unique_reg_note (insn, 
+                 set_unique_reg_note (insn,
                                       REG_EQUAL,
                                       gen_rtx_UDIV (compute_mode, op0, op1));
              }
@@ -3296,7 +3276,7 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
                if (rem_flag && d < 0)
                  {
                    d = abs_d;
-                   op1 = GEN_INT (trunc_int_for_mode (abs_d, compute_mode));
+                   op1 = gen_int_mode (abs_d, compute_mode);
                  }
 
                if (d == 1)
@@ -3313,7 +3293,16 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
                      goto fail1;
                  }
                else if (EXACT_POWER_OF_2_OR_ZERO_P (d)
-                        && (rem_flag ? smod_pow2_cheap : sdiv_pow2_cheap))
+                        && (rem_flag ? smod_pow2_cheap : sdiv_pow2_cheap)
+                        /* ??? The cheap metric is computed only for
+                           word_mode.  If this operation is wider, this may
+                           not be so.  Assume true if the optab has an
+                           expander for this mode.  */
+                        && (((rem_flag ? smod_optab : sdiv_optab)
+                             ->handlers[(int) compute_mode].insn_code
+                             != CODE_FOR_nothing)
+                            || (sdivmod_optab->handlers[(int) compute_mode]
+                                .insn_code != CODE_FOR_nothing)))
                  ;
                else if (EXACT_POWER_OF_2_OR_ZERO_P (abs_d))
                  {
@@ -3326,8 +3315,8 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
                        t1 = copy_to_mode_reg (compute_mode, op0);
                        do_cmp_and_jump (t1, const0_rtx, GE,
                                         compute_mode, label);
-                       expand_inc (t1, GEN_INT (trunc_int_for_mode
-                                                (abs_d - 1, compute_mode)));
+                       expand_inc (t1, gen_int_mode (abs_d - 1,
+                                                     compute_mode));
                        emit_label (label);
                        quotient = expand_shift (RSHIFT_EXPR, compute_mode, t1,
                                                 build_int_2 (lgup, 0),
@@ -3360,7 +3349,7 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
                            && SET_DEST (set) == quotient
                            && abs_d < ((unsigned HOST_WIDE_INT) 1
                                        << (HOST_BITS_PER_WIDE_INT - 1)))
-                         set_unique_reg_note (insn, 
+                         set_unique_reg_note (insn,
                                               REG_EQUAL,
                                               gen_rtx_DIV (compute_mode,
                                                            op0,
@@ -3451,7 +3440,7 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
                if (insn != last
                    && (set = single_set (insn)) != 0
                    && SET_DEST (set) == quotient)
-                 set_unique_reg_note (insn, 
+                 set_unique_reg_note (insn,
                                       REG_EQUAL,
                                       gen_rtx_DIV (compute_mode, op0, op1));
              }
@@ -3867,8 +3856,7 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
            t1 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
                               build_int_2 (pre_shift, 0), NULL_RTX, unsignedp);
            quotient = expand_mult (compute_mode, t1,
-                                   GEN_INT (trunc_int_for_mode
-                                            (ml, compute_mode)),
+                                   gen_int_mode (ml, compute_mode),
                                    NULL_RTX, 0);
 
            insn = get_last_insn ();
@@ -3944,7 +3932,7 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
            emit_label (label);
          }
        return gen_lowpart (mode, rem_flag ? remainder : quotient);
-       
+
       default:
        abort ();
       }
@@ -3957,8 +3945,8 @@ expand_divmod (rem_flag, code, mode, op0, op1, target, unsignedp)
       if (rem_flag)
        {
          /* Try to produce the remainder without producing the quotient.
-            If we seem to have a divmod patten that does not require widening,
-            don't try windening here.  We should really have an WIDEN argument
+            If we seem to have a divmod pattern that does not require widening,
+            don't try widening here.  We should really have an WIDEN argument
             to expand_twoval_binop, since what we'd really like to do here is
             1) try a mod insn in compute_mode
             2) try a divmod insn in compute_mode
@@ -4083,42 +4071,61 @@ make_tree (type, x)
        }
 
       return t;
-         
+
+    case CONST_VECTOR:
+      {
+       int i, units;
+       rtx elt;
+       tree t = NULL_TREE;
+
+       units = CONST_VECTOR_NUNITS (x);
+
+       /* Build a tree with vector elements.  */
+       for (i = units - 1; i >= 0; --i)
+         {
+           elt = CONST_VECTOR_ELT (x, i);
+           t = tree_cons (NULL_TREE, make_tree (type, elt), t);
+         }
+
+       return build_vector (type, t);
+      }
+
     case PLUS:
       return fold (build (PLUS_EXPR, type, make_tree (type, XEXP (x, 0)),
                          make_tree (type, XEXP (x, 1))));
-                                                      
+
     case MINUS:
       return fold (build (MINUS_EXPR, type, make_tree (type, XEXP (x, 0)),
                          make_tree (type, XEXP (x, 1))));
-                                                      
+
     case NEG:
       return fold (build1 (NEGATE_EXPR, type, make_tree (type, XEXP (x, 0))));
 
     case MULT:
       return fold (build (MULT_EXPR, type, make_tree (type, XEXP (x, 0)),
                          make_tree (type, XEXP (x, 1))));
-                                                     
+
     case ASHIFT:
       return fold (build (LSHIFT_EXPR, type, make_tree (type, XEXP (x, 0)),
                          make_tree (type, XEXP (x, 1))));
-                                                     
+
     case LSHIFTRT:
+      t = (*lang_hooks.types.unsigned_type) (type);
       return fold (convert (type,
-                           build (RSHIFT_EXPR, unsigned_type (type),
-                                  make_tree (unsigned_type (type),
-                                             XEXP (x, 0)),
+                           build (RSHIFT_EXPR, t,
+                                  make_tree (t, XEXP (x, 0)),
                                   make_tree (type, XEXP (x, 1)))));
-                                                     
+
     case ASHIFTRT:
+      t = (*lang_hooks.types.signed_type) (type);
       return fold (convert (type,
-                           build (RSHIFT_EXPR, signed_type (type),
-                                  make_tree (signed_type (type), XEXP (x, 0)),
+                           build (RSHIFT_EXPR, t,
+                                  make_tree (t, XEXP (x, 0)),
                                   make_tree (type, XEXP (x, 1)))));
-                                                     
+
     case DIV:
       if (TREE_CODE (type) != REAL_TYPE)
-       t = signed_type (type);
+       t = (*lang_hooks.types.signed_type) (type);
       else
        t = type;
 
@@ -4127,11 +4134,18 @@ make_tree (type, x)
                                   make_tree (t, XEXP (x, 0)),
                                   make_tree (t, XEXP (x, 1)))));
     case UDIV:
-      t = unsigned_type (type);
+      t = (*lang_hooks.types.unsigned_type) (type);
       return fold (convert (type,
                            build (TRUNC_DIV_EXPR, t,
                                   make_tree (t, XEXP (x, 0)),
                                   make_tree (t, XEXP (x, 1)))));
+
+    case SIGN_EXTEND:
+    case ZERO_EXTEND:
+      t = (*lang_hooks.types.type_for_mode) (GET_MODE (XEXP (x, 0)),
+                                            GET_CODE (x) == ZERO_EXTEND);
+      return fold (convert (type, make_tree (t, XEXP (x, 0))));
+
    default:
       t = make_node (RTL_EXPR);
       TREE_TYPE (t) = type;
@@ -4151,6 +4165,44 @@ make_tree (type, x)
     }
 }
 
+/* Check whether the multiplication X * MULT + ADD overflows.
+   X, MULT and ADD must be CONST_*.
+   MODE is the machine mode for the computation.
+   X and MULT must have mode MODE.  ADD may have a different mode.
+   So can X (defaults to same as MODE).
+   UNSIGNEDP is non-zero to do unsigned multiplication.  */
+
+bool
+const_mult_add_overflow_p (x, mult, add, mode, unsignedp)
+     rtx x, mult, add;
+     enum machine_mode mode;
+     int unsignedp;
+{
+  tree type, mult_type, add_type, result;
+
+  type = (*lang_hooks.types.type_for_mode) (mode, unsignedp);
+
+  /* In order to get a proper overflow indication from an unsigned
+     type, we have to pretend that it's a sizetype.  */
+  mult_type = type;
+  if (unsignedp)
+    {
+      mult_type = copy_node (type);
+      TYPE_IS_SIZETYPE (mult_type) = 1;
+    }
+
+  add_type = (GET_MODE (add) == VOIDmode ? mult_type
+             : (*lang_hooks.types.type_for_mode) (GET_MODE (add), unsignedp));
+
+  result = fold (build (PLUS_EXPR, mult_type,
+                       fold (build (MULT_EXPR, mult_type,
+                                    make_tree (mult_type, x),
+                                    make_tree (mult_type, mult))),
+                       make_tree (add_type, add)));
+
+  return TREE_CONSTANT_OVERFLOW (result);
+}
+
 /* Return an rtx representing the value of X * MULT + ADD.
    TARGET is a suggestion for where to store the result (an rtx).
    MODE is the machine mode for the computation.
@@ -4165,9 +4217,10 @@ expand_mult_add (x, target, mult, add, mode, unsignedp)
      enum machine_mode mode;
      int unsignedp;
 {
-  tree type = type_for_mode (mode, unsignedp);
+  tree type = (*lang_hooks.types.type_for_mode) (mode, unsignedp);
   tree add_type = (GET_MODE (add) == VOIDmode
-                  ? type : type_for_mode (GET_MODE (add), unsignedp));
+                  ? type: (*lang_hooks.types.type_for_mode) (GET_MODE (add),
+                                                             unsignedp));
   tree result =  fold (build (PLUS_EXPR, type,
                              fold (build (MULT_EXPR, type,
                                           make_tree (type, x),
@@ -4183,23 +4236,16 @@ expand_mult_add (x, target, mult, add, mode, unsignedp)
    If TARGET is 0, a pseudo-register or constant is returned.  */
 
 rtx
-expand_and (op0, op1, target)
+expand_and (mode, op0, op1, target)
+     enum machine_mode mode;
      rtx op0, op1, target;
 {
-  enum machine_mode mode = VOIDmode;
-  rtx tem;
+  rtx tem = 0;
 
-  if (GET_MODE (op0) != VOIDmode)
-    mode = GET_MODE (op0);
-  else if (GET_MODE (op1) != VOIDmode)
-    mode = GET_MODE (op1);
-
-  if (mode != VOIDmode)
+  if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
+    tem = simplify_binary_operation (AND, mode, op0, op1);
+  if (tem == 0)
     tem = expand_binop (mode, and_optab, op0, op1, target, 0, OPTAB_LIB_WIDEN);
-  else if (GET_CODE (op0) == CONST_INT && GET_CODE (op1) == CONST_INT)
-    tem = GEN_INT (INTVAL (op0) & INTVAL (op1));
-  else
-    abort ();
 
   if (target == 0)
     target = tem;
@@ -4213,7 +4259,7 @@ expand_and (op0, op1, target)
    Return 0 if that cannot be done.
 
    MODE is the mode to use for OP0 and OP1 should they be CONST_INTs.  If
-   it is VOIDmode, they cannot both be CONST_INT.  
+   it is VOIDmode, they cannot both be CONST_INT.
 
    UNSIGNEDP is for the case where we have to widen the operands
    to perform the operation.  It says to use zero-extension.
@@ -4240,6 +4286,10 @@ emit_store_flag (target, code, op0, op1, mode, unsignedp, normalizep)
   rtx last = get_last_insn ();
   rtx pattern, comparison;
 
+  /* ??? Ok to do this and then fail? */
+  op0 = protect_from_queue (op0, 0);
+  op1 = protect_from_queue (op1, 0);
+
   if (unsignedp)
     code = unsigned_condition (code);
 
@@ -4257,7 +4307,7 @@ emit_store_flag (target, code, op0, op1, mode, unsignedp, normalizep)
   if (mode == VOIDmode)
     mode = GET_MODE (op0);
 
-  /* For some comparisons with 1 and -1, we can convert this to 
+  /* For some comparisons with 1 and -1, we can convert this to
      comparisons with zero.  This will often produce more opportunities for
      store-flag insns.  */
 
@@ -4295,7 +4345,8 @@ emit_store_flag (target, code, op0, op1, mode, unsignedp, normalizep)
      the comparison into one involving a single word.  */
   if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD * 2
       && GET_MODE_CLASS (mode) == MODE_INT
-      && op1 == const0_rtx)
+      && op1 == const0_rtx
+      && (GET_CODE (op0) != MEM || ! MEM_VOLATILE_P (op0)))
     {
       if (code == EQ || code == NE)
        {
@@ -4376,19 +4427,20 @@ emit_store_flag (target, code, op0, op1, mode, unsignedp, normalizep)
       last = get_last_insn ();
 
       comparison
-       = compare_from_rtx (op0, op1, code, unsignedp, mode, NULL_RTX, 0);
+       = compare_from_rtx (op0, op1, code, unsignedp, mode, NULL_RTX);
       if (GET_CODE (comparison) == CONST_INT)
        return (comparison == const0_rtx ? const0_rtx
                : normalizep == 1 ? const1_rtx
                : normalizep == -1 ? constm1_rtx
                : const_true_rtx);
 
-      /* If the code of COMPARISON doesn't match CODE, something is
-        wrong; we can no longer be sure that we have the operation.  
-        We could handle this case, but it should not happen.  */
+      /* The code of COMPARISON may not match CODE if compare_from_rtx
+        decided to swap its operands and reverse the original code.
 
-      if (GET_CODE (comparison) != code)
-       abort ();
+        We know that compare_from_rtx returns either a CONST_INT or
+        a new comparison code, so it is safe to just extract the
+        code from COMPARISON.  */
+      code = GET_CODE (comparison);
 
       /* Get a reference to the target in the proper mode for this insn.  */
       compare_mode = insn_data[(int) icode].operand[0].mode;
@@ -4452,14 +4504,14 @@ emit_store_flag (target, code, op0, op1, mode, unsignedp, normalizep)
                                subtarget, normalizep == 1);
          else if (STORE_FLAG_VALUE & 1)
            {
-             op0 = expand_and (op0, const1_rtx, subtarget);
+             op0 = expand_and (compare_mode, op0, const1_rtx, subtarget);
              if (normalizep == -1)
                op0 = expand_unop (compare_mode, neg_optab, op0, op0, 0);
            }
          else
            abort ();
 
-         /* If we were converting to a smaller mode, do the 
+         /* If we were converting to a smaller mode, do the
             conversion now.  */
          if (target_mode != compare_mode)
            {
@@ -4504,7 +4556,7 @@ emit_store_flag (target, code, op0, op1, mode, unsignedp, normalizep)
       return tem;
     }
 
-  /* Some other cases we can do are EQ, NE, LE, and GT comparisons with 
+  /* Some other cases we can do are EQ, NE, LE, and GT comparisons with
      the constant zero.  Reject all other comparisons at this point.  Only
      do LE and GT if branches are expensive since they are expensive on
      2-operand machines.  */
@@ -4566,22 +4618,22 @@ emit_store_flag (target, code, op0, op1, mode, unsignedp, normalizep)
       tem = expand_binop (mode, sub_optab, tem, op0, subtarget, 0,
                          OPTAB_WIDEN);
     }
-                                   
+
   if (code == EQ || code == NE)
     {
       /* For EQ or NE, one way to do the comparison is to apply an operation
         that converts the operand into a positive number if it is non-zero
         or zero if it was originally zero.  Then, for EQ, we subtract 1 and
         for NE we negate.  This puts the result in the sign bit.  Then we
-        normalize with a shift, if needed. 
+        normalize with a shift, if needed.
 
         Two operations that can do the above actions are ABS and FFS, so try
         them.  If that doesn't work, and MODE is smaller than a full word,
         we can use zero-extension to the wider mode (an unsigned conversion)
         as the operation.  */
 
-      /* Note that ABS doesn't yield a positive number for INT_MIN, but 
-        that is compensated by the subsequent overflow when subtracting 
+      /* Note that ABS doesn't yield a positive number for INT_MIN, but
+        that is compensated by the subsequent overflow when subtracting
         one / negating.  */
 
       if (abs_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
@@ -4676,7 +4728,7 @@ emit_store_flag_force (target, code, op0, op1, mode, unsignedp, normalizep)
 
   emit_move_insn (target, const1_rtx);
   label = gen_label_rtx ();
-  do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode, NULL_RTX, 0,
+  do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode, NULL_RTX,
                           NULL_RTX, label);
 
   emit_move_insn (target, const0_rtx);
@@ -4734,24 +4786,22 @@ do_cmp_and_jump (arg1, arg2, op, mode, label)
             that's the only equality operations we do */
        case EQ:
          if (arg2 != const0_rtx || mode != GET_MODE(arg1))
-           abort();
+           abort ();
          do_jump_by_parts_equality_rtx (arg1, label2, label);
          break;
 
        case NE:
          if (arg2 != const0_rtx || mode != GET_MODE(arg1))
-           abort();
+           abort ();
          do_jump_by_parts_equality_rtx (arg1, label, label2);
          break;
 
        default:
-         abort();
+         abort ();
        }
 
       emit_label (label2);
     }
   else
-    {
-      emit_cmp_and_jump_insns (arg1, arg2, op, NULL_RTX, mode, 0, 0, label);
-    }
+    emit_cmp_and_jump_insns (arg1, arg2, op, NULL_RTX, mode, 0, label);
 }