On Thu, 2026-05-14 at 09:51 +0200, Richard Biener wrote:

/* snip */

> > diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
> > index f524786f33b..ec3c9ab4f3d 100644
> > --- a/gcc/tree-scalar-evolution.cc
> > +++ b/gcc/tree-scalar-evolution.cc
> > @@ -1391,10 +1391,22 @@ 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 tp = TREE_TYPE (right);
> > +
> > +      /* We likely need a sign-extension to make things like
> > +         u8(6, 4, 2) => i32(6, 4, 2), instead of i32(6, 260, 514).
> > +         But u8(1, 129) shouldn't be i32(1, -127) either.  */
> > +      if (TYPE_UNSIGNED (tp)
> > +          && wi::to_widest (TYPE_MAX_VALUE (tp)) <
> > +         (wi::to_widest (init_cond) + wi::to_widest (right)))
> 
> I’d say we just want the TYPE_UNSIGNED check here, esp. it shouldn’t depend 
> on init_cond and also work for symbolic right.

So wouldn't doing so make u8(1, 129) => i32(1, -127) and misoptimize
that?  Or maybe we cannot have a loop iterating only twice here?
> 

-- 
Xi Ruoyao <[email protected]>

Reply via email to