[wide-int 4/8] Tweak uses of new API

Richard Biener richard.guenther@gmail.com
Wed Apr 23 09:53:00 GMT 2014


On Tue, Apr 22, 2014 at 9:55 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> This is an assorted bunch of API tweaks:
>
> - use neg_p instead of lts_p (..., 0)
> - use STATIC_ASSERT for things that are known at compile time
> - avoid unnecessary wide(st)_int temporaries and arithmetic
> - remove an unnecessary template parameter
> - use to_short_addr for an offset_int->HOST_WIDE_INT offset change
>
> Tested on x86_64-linux-gnu.  OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> Index: gcc/ada/gcc-interface/cuintp.c
> ===================================================================
> --- gcc/ada/gcc-interface/cuintp.c      2014-04-22 20:31:10.680896299 +0100
> +++ gcc/ada/gcc-interface/cuintp.c      2014-04-22 20:31:24.526996049 +0100
> @@ -160,7 +160,7 @@ UI_From_gnu (tree Input)
>       in a signed 64-bit integer.  */
>    if (tree_fits_shwi_p (Input))
>      return UI_From_Int (tree_to_shwi (Input));
> -  else if (wi::lts_p (Input, 0) && TYPE_UNSIGNED (gnu_type))
> +  else if (wi::neg_p (Input) && TYPE_UNSIGNED (gnu_type))
>      return No_Uint;
>  #endif
>
> Index: gcc/expmed.c
> ===================================================================
> --- gcc/expmed.c        2014-04-22 20:31:10.680896299 +0100
> +++ gcc/expmed.c        2014-04-22 20:31:24.527996056 +0100
> @@ -4971,7 +4971,7 @@ make_tree (tree type, rtx x)
>        return t;
>
>      case CONST_DOUBLE:
> -      gcc_assert (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT);
> +      STATIC_ASSERT (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT);
>        if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode)
>         t = wide_int_to_tree (type,
>                               wide_int::from_array (&CONST_DOUBLE_LOW (x), 2,
> Index: gcc/fold-const.c
> ===================================================================
> --- gcc/fold-const.c    2014-04-22 20:31:10.680896299 +0100
> +++ gcc/fold-const.c    2014-04-22 20:31:24.530996079 +0100
> @@ -4274,9 +4274,8 @@ build_range_check (location_t loc, tree
>    if (integer_onep (low) && TREE_CODE (high) == INTEGER_CST)
>      {
>        int prec = TYPE_PRECISION (etype);
> -      wide_int osb = wi::set_bit_in_zero (prec - 1, prec) - 1;
>
> -      if (osb == high)
> +      if (wi::mask (prec - 1, false, prec) == high)
>         {
>           if (TYPE_UNSIGNED (etype))
>             {
> @@ -12950,7 +12949,7 @@ fold_binary_loc (location_t loc,
>           && operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg0,
>                                                                         1)),
>                               arg1, 0)
> -         && wi::bit_and (TREE_OPERAND (arg0, 0), 1) == 1)
> +         && wi::extract_uhwi (TREE_OPERAND (arg0, 0), 0, 1) == 1)
>         {
>           return omit_two_operands_loc (loc, type,
>                                     code == NE_EXPR
> Index: gcc/predict.c
> ===================================================================
> --- gcc/predict.c       2014-04-22 20:31:10.680896299 +0100
> +++ gcc/predict.c       2014-04-22 20:31:24.531996086 +0100
> @@ -1309,33 +1309,34 @@ predict_iv_comparison (struct loop *loop
>        bool overflow, overall_overflow = false;
>        widest_int compare_count, tem;
>
> -      widest_int loop_bound = wi::to_widest (loop_bound_var);
> -      widest_int compare_bound = wi::to_widest (compare_var);
> -      widest_int base = wi::to_widest (compare_base);
> -      widest_int compare_step = wi::to_widest (compare_step_var);
> -
>        /* (loop_bound - base) / compare_step */
> -      tem = wi::sub (loop_bound, base, SIGNED, &overflow);
> +      tem = wi::sub (wi::to_widest (loop_bound_var),
> +                    wi::to_widest (compare_base), SIGNED, &overflow);
>        overall_overflow |= overflow;
> -      widest_int loop_count = wi::div_trunc (tem, compare_step, SIGNED,
> -                                            &overflow);
> +      widest_int loop_count = wi::div_trunc (tem,
> +                                            wi::to_widest (compare_step_var),
> +                                            SIGNED, &overflow);
>        overall_overflow |= overflow;
>
> -      if (!wi::neg_p (compare_step)
> +      if (!wi::neg_p (wi::to_widest (compare_step_var))
>            ^ (compare_code == LT_EXPR || compare_code == LE_EXPR))
>         {
>           /* (loop_bound - compare_bound) / compare_step */
> -         tem = wi::sub (loop_bound, compare_bound, SIGNED, &overflow);
> +         tem = wi::sub (wi::to_widest (loop_bound_var),
> +                        wi::to_widest (compare_var), SIGNED, &overflow);
>           overall_overflow |= overflow;
> -         compare_count = wi::div_trunc (tem, compare_step, SIGNED, &overflow);
> +         compare_count = wi::div_trunc (tem, wi::to_widest (compare_step_var),
> +                                        SIGNED, &overflow);
>           overall_overflow |= overflow;
>         }
>        else
>          {
>           /* (compare_bound - base) / compare_step */
> -         tem = wi::sub (compare_bound, base, SIGNED, &overflow);
> +         tem = wi::sub (wi::to_widest (compare_var),
> +                        wi::to_widest (compare_base), SIGNED, &overflow);
>           overall_overflow |= overflow;
> -          compare_count = wi::div_trunc (tem, compare_step, SIGNED, &overflow);
> +          compare_count = wi::div_trunc (tem, wi::to_widest (compare_step_var),
> +                                        SIGNED, &overflow);
>           overall_overflow |= overflow;
>         }
>        if (compare_code == LE_EXPR || compare_code == GE_EXPR)
> Index: gcc/real.c
> ===================================================================
> --- gcc/real.c  2014-04-22 20:31:10.680896299 +0100
> +++ gcc/real.c  2014-04-22 20:31:24.528996063 +0100
> @@ -1446,7 +1446,7 @@ real_to_integer (const REAL_VALUE_TYPE *
>        w = SIGSZ * HOST_BITS_PER_LONG + words * HOST_BITS_PER_WIDE_INT;
>        tmp = real_int::from_array
>         (val, (w + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT, w);
> -      tmp = wi::lrshift<real_int> (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
> +      tmp = wi::lrshift (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp);
>        result = wide_int::from (tmp, precision, UNSIGNED);
>
>        if (r->sign)
> Index: gcc/tree-chrec.c
> ===================================================================
> --- gcc/tree-chrec.c    2014-04-22 20:31:10.680896299 +0100
> +++ gcc/tree-chrec.c    2014-04-22 20:31:24.531996086 +0100
> @@ -490,21 +490,18 @@ tree_fold_binomial (tree type, tree n, u
>    if (k == 1)
>      return fold_convert (type, n);
>
> -  /* Numerator = n.  */
> -  wide_int num = n;
> -
>    /* Check that k <= n.  */
> -  if (wi::ltu_p (num, k))
> +  if (wi::ltu_p (n, k))
>      return NULL_TREE;
>
>    /* Denominator = 2.  */
>    wide_int denom = wi::two (TYPE_PRECISION (TREE_TYPE (n)));
>
>    /* Index = Numerator-1.  */
> -  wide_int idx = num - 1;
> +  wide_int idx = wi::sub (n, 1);
>
>    /* Numerator = Numerator*Index = n*(n-1).  */
> -  num = wi::smul (num, idx, &overflow);
> +  wide_int num = wi::smul (n, idx, &overflow);
>    if (overflow)
>      return NULL_TREE;
>
> Index: gcc/varasm.c
> ===================================================================
> --- gcc/varasm.c        2014-04-22 20:31:10.680896299 +0100
> +++ gcc/varasm.c        2014-04-22 20:31:24.532996093 +0100
> @@ -4898,7 +4898,7 @@ output_constructor_regular_field (oc_loc
>        offset_int idx = wi::sext (wi::to_offset (local->index)
>                                  - wi::to_offset (local->min_index), prec);
>        fieldpos = (idx * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local->val))))
> -       .to_shwi ();
> +       .to_short_addr ();
>      }
>    else if (local->field != NULL_TREE)
>      fieldpos = int_byte_position (local->field);



More information about the Gcc-patches mailing list