[Bug middle-end/38756] 107t.ivopts introduces pointer truncation

rguenther at suse dot de gcc-bugzilla@gcc.gnu.org
Thu Jun 21 12:12:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38756

--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> 2012-06-21 12:12:24 UTC ---
On Thu, 21 Jun 2012, bigotp at acm dot org wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38756
> 
> --- Comment #3 from Peter A. Bigot <bigotp at acm dot org> 2012-06-21 12:04:34 UTC ---
> commit af66de00843896ad5d2980952994b31cadbf8421
> Author: Peter A. Bigot <pabigot@users.sourceforge.net>
> Date:   Thu Jun 21 06:35:44 2012 -0500
> 
>     Anticipatory patch for PR middle-end/38756
> 
>     Do not truncate to size_type when adding the step factor to a pointer.
> 
> diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
> index 0693c21..f8372fd 100644
> --- a/gcc/tree-ssa-loop-ivopts.c
> +++ b/gcc/tree-ssa-loop-ivopts.c
> @@ -6199,6 +6199,11 @@ rewrite_use_nonlinear_expr (struct ivopts_data *data,
>        step = cand->iv->step;
>        ctype = TREE_TYPE (step);
>        utype = TREE_TYPE (cand->var_after);
> +      if (TYPE_PRECISION (ctype) < TYPE_PRECISION (utype))
> +       {
> +         ctype = generic_type_for (utype);
> +         step = fold_convert (ctype, unshare_expr (step));
> +       }
>        if (TREE_CODE (step) == NEGATE_EXPR)
>         {
>           incr_code = MINUS_EXPR;

So the truncation happens here?

      /* Otherwise, add the necessary computations to express
         the iv.  */
      op = fold_convert (ctype, cand->var_before);
      comp = fold_convert (utype,
                           build2 (incr_code, ctype, op,
                                   unshare_expr (step)));

I think it makes sense to do the computation in
generic_type_for (utype) anyways - even if that truncates the
step.  Because we truncate to utype anyways.

Thus

      type = generic_type_for (utype);
      op = fold_convert (type, cand->var_before);
      comp = fold_convert (utype,
                           fold_build2 (incr_code, type, op,
                    fold_convert (type, unshare_expr 
(step))));

unconditionally.



More information about the Gcc-bugs mailing list