]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/expr.c
Merge from trunk.
[thirdparty/gcc.git] / gcc / expr.c
index 968438b2fbac32438114556331bcbc03fa54c4e1..cdc1baff5afea5847647e5b0fce8e9c4c31d5fcb 100644 (file)
@@ -722,64 +722,33 @@ convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int uns
   if (mode == oldmode)
     return x;
 
-  /* There is one case that we must handle specially: If we are converting
-     a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
-     we are to interpret the constant as unsigned, gen_lowpart will do
-     the wrong if the constant appears negative.  What we want to do is
-     make the high-order word of the constant zero, not all ones.  */
-
-  if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
-      && GET_MODE_BITSIZE (mode) == HOST_BITS_PER_DOUBLE_INT
-      && CONST_INT_P (x) && INTVAL (x) < 0)
+  if (CONST_SCALAR_INT_P (x) 
+      && GET_MODE_CLASS (mode) == MODE_INT)
     {
-      double_int val = double_int::from_uhwi (INTVAL (x));
-
-      /* We need to zero extend VAL.  */
-      if (oldmode != VOIDmode)
-       val = val.zext (GET_MODE_BITSIZE (oldmode));
-
-      return immed_double_int_const (val, mode);
+      /* If the caller did not tell us the old mode, then there is
+        not much to do with respect to canonization.  We have to assume
+        that all the bits are significant.  */
+      if (GET_MODE_CLASS (oldmode) != MODE_INT)
+       oldmode = MAX_MODE_INT;
+      wide_int w = wide_int::from (std::make_pair (x, oldmode),
+                                  GET_MODE_PRECISION (mode),
+                                  unsignedp ? UNSIGNED : SIGNED);
+      return immed_wide_int_const (w, mode);
     }
 
   /* We can do this with a gen_lowpart if both desired and current modes
      are integer, and this is either a constant integer, a register, or a
-     non-volatile MEM.  Except for the constant case where MODE is no
-     wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand.  */
-
-  if ((CONST_INT_P (x)
-       && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT)
-      || (GET_MODE_CLASS (mode) == MODE_INT
-         && GET_MODE_CLASS (oldmode) == MODE_INT
-         && (CONST_DOUBLE_AS_INT_P (x) 
-             || (GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (oldmode)
-                 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
-                      && direct_load[(int) mode])
-                     || (REG_P (x)
-                         && (! HARD_REGISTER_P (x)
-                             || HARD_REGNO_MODE_OK (REGNO (x), mode))
-                         && TRULY_NOOP_TRUNCATION_MODES_P (mode,
-                                                           GET_MODE (x))))))))
-    {
-      /* ?? If we don't know OLDMODE, we have to assume here that
-        X does not need sign- or zero-extension.   This may not be
-        the case, but it's the best we can do.  */
-      if (CONST_INT_P (x) && oldmode != VOIDmode
-         && GET_MODE_PRECISION (mode) > GET_MODE_PRECISION (oldmode))
-       {
-         HOST_WIDE_INT val = INTVAL (x);
-
-         /* We must sign or zero-extend in this case.  Start by
-            zero-extending, then sign extend if we need to.  */
-         val &= GET_MODE_MASK (oldmode);
-         if (! unsignedp
-             && val_signbit_known_set_p (oldmode, val))
-           val |= ~GET_MODE_MASK (oldmode);
-
-         return gen_int_mode (val, mode);
-       }
-
-      return gen_lowpart (mode, x);
-    }
+     non-volatile MEM. */
+  if (GET_MODE_CLASS (mode) == MODE_INT
+      && GET_MODE_CLASS (oldmode) == MODE_INT
+      && GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (oldmode)
+      && ((MEM_P (x) && !MEM_VOLATILE_P (x) && direct_load[(int) mode])
+          || (REG_P (x)
+              && (!HARD_REGISTER_P (x)
+                  || HARD_REGNO_MODE_OK (REGNO (x), mode))
+              && TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (x)))))
+
+   return gen_lowpart (mode, x);
 
   /* Converting from integer constant into mode is always equivalent to an
      subreg operation.  */
@@ -1805,6 +1774,7 @@ emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
            {
              rtx first, second;
 
+             /* TODO: const_wide_int can have sizes other than this...  */
              gcc_assert (2 * len == ssize);
              split_double (src, &first, &second);
              if (i)
@@ -5301,10 +5271,10 @@ store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
                               &alt_rtl);
     }
 
-  /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
-     the same as that of TARGET, adjust the constant.  This is needed, for
-     example, in case it is a CONST_DOUBLE and we want only a word-sized
-     value.  */
+  /* If TEMP is a VOIDmode constant and the mode of the type of EXP is
+     not the same as that of TARGET, adjust the constant.  This is
+     needed, for example, in case it is a CONST_DOUBLE or
+     CONST_WIDE_INT and we want only a word-sized value.  */
   if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
       && TREE_CODE (exp) != ERROR_MARK
       && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
@@ -6653,7 +6623,7 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
   enum machine_mode mode = VOIDmode;
   bool blkmode_bitfield = false;
   tree offset = size_zero_node;
-  double_int bit_offset = double_int_zero;
+  offset_int bit_offset = 0;
 
   /* First get the mode, signedness, and size.  We do this from just the
      outermost expression.  */
@@ -6716,7 +6686,7 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
       switch (TREE_CODE (exp))
        {
        case BIT_FIELD_REF:
-         bit_offset += tree_to_double_int (TREE_OPERAND (exp, 2));
+         bit_offset += wi::to_offset (TREE_OPERAND (exp, 2));
          break;
 
        case COMPONENT_REF:
@@ -6731,7 +6701,7 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
              break;
 
            offset = size_binop (PLUS_EXPR, offset, this_offset);
-           bit_offset += tree_to_double_int (DECL_FIELD_BIT_OFFSET (field));
+           bit_offset += wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
 
            /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN.  */
          }
@@ -6763,7 +6733,7 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
          break;
 
        case IMAGPART_EXPR:
-         bit_offset += double_int::from_uhwi (*pbitsize);
+         bit_offset += *pbitsize;
          break;
 
        case VIEW_CONVERT_EXPR:
@@ -6784,9 +6754,9 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
              tree off = TREE_OPERAND (exp, 1);
              if (!integer_zerop (off))
                {
-                 double_int boff, coff = mem_ref_offset (exp);
-                 boff = coff.lshift (BITS_PER_UNIT == 8
-                                     ? 3 : exact_log2 (BITS_PER_UNIT));
+                 offset_int boff, coff = mem_ref_offset (exp);
+                 boff = wi::lshift (coff, (BITS_PER_UNIT == 8
+                                           ? 3 : exact_log2 (BITS_PER_UNIT)));
                  bit_offset += boff;
                }
              exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
@@ -6810,11 +6780,12 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
      this conversion.  */
   if (TREE_CODE (offset) == INTEGER_CST)
     {
-      double_int tem = tree_to_double_int (offset);
-      tem = tem.sext (TYPE_PRECISION (sizetype));
-      tem = tem.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
+      offset_int tem = wi::sext (wi::to_offset (offset),
+                                TYPE_PRECISION (sizetype));
+      tem = wi::lshift (tem, (BITS_PER_UNIT == 8
+                             ? 3 : exact_log2 (BITS_PER_UNIT)));
       tem += bit_offset;
-      if (tem.fits_shwi ())
+      if (wi::fits_shwi_p (tem))
        {
          *pbitpos = tem.to_shwi ();
          *poffset = offset = NULL_TREE;
@@ -6825,20 +6796,20 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
   if (offset)
     {
       /* Avoid returning a negative bitpos as this may wreak havoc later.  */
-      if (bit_offset.is_negative ())
+      if (wi::neg_p (bit_offset))
         {
-         double_int mask
-           = double_int::mask (BITS_PER_UNIT == 8
-                              ? 3 : exact_log2 (BITS_PER_UNIT));
-         double_int tem = bit_offset.and_not (mask);
+         offset_int mask
+           = wi::mask <offset_int> (BITS_PER_UNIT == 8
+                                    ? 3 : exact_log2 (BITS_PER_UNIT),
+                                    false);
+         offset_int tem = bit_offset.and_not (mask);
          /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
             Subtract it to BIT_OFFSET and add it (scaled) to OFFSET.  */
          bit_offset -= tem;
-         tem = tem.arshift (BITS_PER_UNIT == 8
-                            ? 3 : exact_log2 (BITS_PER_UNIT),
-                            HOST_BITS_PER_DOUBLE_INT);
+         tem = wi::arshift (tem, (BITS_PER_UNIT == 8
+                                  ? 3 : exact_log2 (BITS_PER_UNIT)));
          offset = size_binop (PLUS_EXPR, offset,
-                              double_int_to_tree (sizetype, tem));
+                              wide_int_to_tree (sizetype, tem));
        }
 
       *pbitpos = bit_offset.to_shwi ();
@@ -7769,11 +7740,12 @@ expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
 
   /* All elts simple constants => refer to a constant in memory.  But
      if this is a non-BLKmode mode, let it store a field at a time
-     since that should make a CONST_INT or CONST_DOUBLE when we
-     fold.  Likewise, if we have a target we can use, it is best to
-     store directly into the target unless the type is large enough
-     that memcpy will be used.  If we are making an initializer and
-     all operands are constant, put it in memory as well.
+     since that should make a CONST_INT, CONST_WIDE_INT or
+     CONST_DOUBLE when we fold.  Likewise, if we have a target we can
+     use, it is best to store directly into the target unless the type
+     is large enough that memcpy will be used.  If we are making an
+     initializer and all operands are constant, put it in memory as
+     well.
 
      FIXME: Avoid trying to fill vector constructors piece-meal.
      Output them with output_constant_def below unless we're sure
@@ -8243,17 +8215,18 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
              && TREE_CONSTANT (treeop1))
            {
              rtx constant_part;
+             HOST_WIDE_INT wc;
+             enum machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop1));
 
              op1 = expand_expr (treeop1, subtarget, VOIDmode,
                                 EXPAND_SUM);
-             /* Use immed_double_const to ensure that the constant is
+             /* Use wi::shwi to ensure that the constant is
                 truncated according to the mode of OP1, then sign extended
                 to a HOST_WIDE_INT.  Using the constant directly can result
                 in non-canonical RTL in a 64x32 cross compile.  */
-             constant_part
-               = immed_double_const (TREE_INT_CST_LOW (treeop0),
-                                     (HOST_WIDE_INT) 0,
-                                     TYPE_MODE (TREE_TYPE (treeop1)));
+             wc = TREE_INT_CST_LOW (treeop0);
+             constant_part =
+               immed_wide_int_const (wi::shwi (wc, wmode), wmode);
              op1 = plus_constant (mode, op1, INTVAL (constant_part));
              if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
                op1 = force_operand (op1, target);
@@ -8265,6 +8238,8 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
                   && TREE_CONSTANT (treeop0))
            {
              rtx constant_part;
+             HOST_WIDE_INT wc;
+             enum machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop0));
 
              op0 = expand_expr (treeop0, subtarget, VOIDmode,
                                 (modifier == EXPAND_INITIALIZER
@@ -8279,14 +8254,13 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
                    return simplify_gen_binary (PLUS, mode, op0, op1);
                  goto binop2;
                }
-             /* Use immed_double_const to ensure that the constant is
+             /* Use wi::shwi to ensure that the constant is
                 truncated according to the mode of OP1, then sign extended
                 to a HOST_WIDE_INT.  Using the constant directly can result
                 in non-canonical RTL in a 64x32 cross compile.  */
+             wc = TREE_INT_CST_LOW (treeop1);
              constant_part
-               = immed_double_const (TREE_INT_CST_LOW (treeop1),
-                                     (HOST_WIDE_INT) 0,
-                                     TYPE_MODE (TREE_TYPE (treeop0)));
+               = immed_wide_int_const (wi::shwi (wc, wmode), wmode);
              op0 = plus_constant (mode, op0, INTVAL (constant_part));
              if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
                op0 = force_operand (op0, target);
@@ -8815,10 +8789,14 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
         for unsigned bitfield expand this as XOR with a proper constant
         instead.  */
       if (reduce_bit_field && TYPE_UNSIGNED (type))
-       temp = expand_binop (mode, xor_optab, op0,
-                            immed_double_int_const
-                              (double_int::mask (TYPE_PRECISION (type)), mode),
-                            target, 1, OPTAB_LIB_WIDEN);
+       {
+         wide_int mask = wi::mask (TYPE_PRECISION (type),
+                                   false, GET_MODE_PRECISION (mode));
+
+         temp = expand_binop (mode, xor_optab, op0,
+                              immed_wide_int_const (mask, mode),
+                              target, 1, OPTAB_LIB_WIDEN);
+       }
       else
        temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
       gcc_assert (temp);
@@ -9469,11 +9447,19 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
       return decl_rtl;
 
     case INTEGER_CST:
-      temp = immed_double_const (TREE_INT_CST_LOW (exp),
-                                TREE_INT_CST_HIGH (exp), mode);
-
-      return temp;
-
+      {
+       tree type = TREE_TYPE (exp);
+       /* One could argue that GET_MODE_PRECISION (TYPE_MODE (type))
+          should always be the same as TYPE_PRECISION (type).
+          However, it is not.  Since we are converting from tree to
+          rtl, we have to expose this ugly truth here.  */
+       temp = immed_wide_int_const (wide_int::from
+                                      (exp,
+                                       GET_MODE_PRECISION (TYPE_MODE (type)),
+                                       TYPE_SIGN (type)),
+                                    TYPE_MODE (type));
+       return temp;
+      }
     case VECTOR_CST:
       {
        tree tmp = NULL_TREE;
@@ -9657,7 +9643,7 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
           might end up in a register.  */
        if (mem_ref_refers_to_non_mem_p (exp))
          {
-           HOST_WIDE_INT offset = mem_ref_offset (exp).low;
+           HOST_WIDE_INT offset = mem_ref_offset (exp).to_short_addr ();
            base = TREE_OPERAND (base, 0);
            if (offset == 0
                && tree_fits_uhwi_p (TYPE_SIZE (type))
@@ -9692,8 +9678,7 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
        op0 = memory_address_addr_space (mode, op0, as);
        if (!integer_zerop (TREE_OPERAND (exp, 1)))
          {
-           rtx off
-             = immed_double_int_const (mem_ref_offset (exp), address_mode);
+           rtx off = immed_wide_int_const (mem_ref_offset (exp), address_mode);
            op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
            op0 = memory_address_addr_space (mode, op0, as);
          }
@@ -10557,9 +10542,10 @@ reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
     }
   else if (TYPE_UNSIGNED (type))
     {
-      rtx mask = immed_double_int_const (double_int::mask (prec),
-                                        GET_MODE (exp));
-      return expand_and (GET_MODE (exp), exp, mask, target);
+      enum machine_mode mode = GET_MODE (exp);
+      rtx mask = immed_wide_int_const 
+       (wi::mask (prec, false, GET_MODE_PRECISION (mode)), mode);
+      return expand_and (mode, exp, mask, target);
     }
   else
     {
@@ -11133,8 +11119,8 @@ const_vector_from_tree (tree exp)
        RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
                                                         inner);
       else
-       RTVEC_ELT (v, i) = immed_double_int_const (tree_to_double_int (elt),
-                                                  inner);
+       RTVEC_ELT (v, i) 
+         = immed_wide_int_const (elt, TYPE_MODE (TREE_TYPE (elt)));
     }
 
   return gen_rtx_CONST_VECTOR (mode, v);