On Thu, Oct 08, 2026 at 09:32:29AM -0600, Jeff Law wrote:
> > +#if GIMPLE
> > +/* PR126644: A << CST >> CST -> A
> > +   As long as the upper CST bits of A are known to be zero.  */
> > +(simplify
> > + (rshift (lshift@2 @0 INTEGER_CST@1) @1)
> > +  (if (INTEGRAL_TYPE_P (type)
> > +       && INTEGRAL_TYPE_P (TREE_TYPE (@0))

Also, why this test?  There is no convert, so @0's type
must be necessarily the same type as type for GENERIC and
a uselessly compatible type with it in GIMPLE.

> > +       && tree_fits_uhwi_p (@1)
> > +       && tree_to_uhwi (@1) < TYPE_PRECISION (type)
> > +       && single_use (@2))
> > +   (with {
> > +      unsigned int prec = TYPE_PRECISION (type);
> > +      wide_int mask = wi::mask (prec - tree_to_uhwi (@1),
> > +                           true, prec);
> > +    }
> > +    (if ((tree_nonzero_bits (@0) & mask) == 0)
> > +     @0))))
> > +#endif
> > +
> Doesn't this fail from a correctness standpoint if we're dealing with a
> signed type?  The upper CST bits may be zero, but CST+1 may be on, so after
> the left shift that on bit is in the sign bit, then we shift it right
> (arithmetically if the type is signed), filling in 1s rather than 0s in the
> vacated bits.

Yes.  For unsigned types, tree_nonzero_bits is ok I guess, for signed types
it would need to check number of sign bit copies (which we don't track
unlike RTL), but it can be figured out from VRP info, if both lower_bound ()
and upper_bound () have the right number of sign bit copies, then anything
in between does as well.

        Jakub

Reply via email to