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

--- Comment #6 from Xi Ruoyao <xry111 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;
> +     }
>        return chrec_dont_know;
>      }

It works for libarchive.  I'm starting bootstrap & regtest runs for the patch
on both x86_64 and loongarch64, before calling it a day.

Reply via email to