On Mon, Aug 23, 2021 at 1:09 PM Jakub Jelinek via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Mon, Aug 23, 2021 at 01:25:13AM +0100, Roger Sayle wrote:
> > This patch has been tested on x86_64-pc-linux-gnu with "make bootstrap"
> > and "make -k check" with no new failures.  Ok for mainline?
> >
> >
> > 2021-08-23  Roger Sayle  <ro...@nextmovesoftware.com>
> >
> > gcc/ChangeLog
> >       * match.pd (shift transformations): Change the sign of an
> >       LSHIFT_EXPR if it reduces the number of explicit conversions.
>
> This broke bootstrap on i686-linux, where it incorrectly simplifies
> a cast from LSHIFT_EXPR with integral type to pointer type of the
> same precision into LSHIFT_EXPR performed on the pointer type,
> which is invalid IL.
And a reduced testcase for that failure can be found in PR 102029 too.

Thanks,
Andrew

>
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index 0fcfd0e..978a1b0 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -3385,6 +3385,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >      (if (integer_zerop (@2) || integer_all_onesp (@2))
> >       (cmp @0 @2)))))
> >
> > +/* Both signed and unsigned lshift produce the same result, so use
> > +   the form that minimizes the number of conversions.  */
> > +(simplify
> > + (convert (lshift:s@0 (convert:s@1 @2) INTEGER_CST@3))
> > + (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
>
> I think you want
>         && INTEGRAL_TYPE_P (TREE_TYPE (@1))
> here as well.
>
> > +      && INTEGRAL_TYPE_P (TREE_TYPE (@2))
> > +      && TYPE_PRECISION (TREE_TYPE (@2)) <= TYPE_PRECISION (type))
> > +  (lshift (convert @2) @3)))
> > +
>
>         Jakub
>

Reply via email to