On Fri, 14 Mar 2025, Jakub Jelinek wrote: > Hi! > > The following testcase ICEs since r15-8025. > tree_nop_conversion_p doesn't imply TREE_TYPE (@0) is uselessly convertible > to type, e.g. they could be INTEGER_TYPEs with the same precision but > different TYPE_SIGN. > > The following patch just adds a convert so that it creates a valid IL > even in those cases. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK. Richard. > 2025-03-14 Jakub Jelinek <ja...@redhat.com> > > PR tree-optimization/119287 > * match.pd (((X >> C1) & C2) * (1 << C1) to X & (C2 << C1)): Use > (convert @0) instead of @0 in the substitution. > > * gcc.dg/pr119287.c: New test. > > --- gcc/match.pd.jj 2025-03-13 14:05:09.689017389 +0100 > +++ gcc/match.pd 2025-03-14 12:13:02.563169756 +0100 > @@ -5284,7 +5284,7 @@ (define_operator_list SYNC_FETCH_AND_AND > || tree_int_cst_sgn (@2) >= 0) > && wi::to_wide (@3) == wi::set_bit_in_zero (shift, prec)) > (with { auto mask = wide_int::from (wi::to_wide (@2), prec, UNSIGNED); } > - (bit_and @0 { wide_int_to_tree (type, mask << shift); })))))) > + (bit_and (convert @0) { wide_int_to_tree (type, mask << shift); })))))) > > /* ~(~X >> Y) -> X >> Y (for arithmetic shift). */ > (simplify > --- gcc/testsuite/gcc.dg/pr119287.c.jj 2025-03-14 12:27:37.470247725 > +0100 > +++ gcc/testsuite/gcc.dg/pr119287.c 2025-03-14 12:27:04.367696980 +0100 > @@ -0,0 +1,16 @@ > +/* PR tree-optimization/119287 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fwrapv" } */ > + > +unsigned a; > +int b; > +signed char c, d; > + > +void > +foo (void) > +{ > + c = a >> 14 & 1; > + for (; d;) > + c = 1; > + b = c << 14; > +} > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)