https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125291

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2026-05-13
     Ever confirmed|0                           |1

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Xi Ruoyao from comment #4)
> Tentative untested patch:
> 
> diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
> index ecdef7529a6..b55ae0586c8 100644
> --- a/gcc/tree-scalar-evolution.cc
> +++ b/gcc/tree-scalar-evolution.cc
> @@ -1377,10 +1377,16 @@ simplify_peeled_chrec (class loop *loop, tree arg,
> tree init_cond)
>         && wi::to_widest (init_cond) == wi::to_widest (left_before)
>         && !scev_probably_wraps_p (NULL_TREE, left_before, right, NULL,
>                                    loop, false))
> -     return build_polynomial_chrec (loop->num, init_cond,
> -                                    chrec_convert (TREE_TYPE (ev),
> -                                                   right, NULL,
> -                                                   false, NULL_TREE));
> +     {
> +       tree r = build_polynomial_chrec (loop->num, init_cond,
> +                                        chrec_convert (TREE_TYPE (ev),
> +                                                       right, NULL,
> +                                                       false, NULL_TREE));
> +       /* (u8)[6, 260, 514] is [6, 4, 2], not [6, 260, 514].  */
> +       if (tree_int_cst_sign_bit (right)
> +           == (scev_direction (r) == EV_DIR_DECREASES))
> +         return r;

Hmm, wouldn't it be better to always sign-extend 'right'?  Thanks for
working on a fix.  I'm not sure right is always an INTEGER_CST btw.

> +     }
>        return chrec_dont_know;
>      }

Reply via email to