On 3/3/2026 5:05 AM, Daniel Henrique Barboza wrote: > From: Daniel Barboza <[email protected]> > > Note that we're not adding its counterpart: > > "(A>>bool) != 0 -> (unsigned)A) > bool" > > Because it will collide with patterns that handles builtin_clz (e.g. > clz-complement-int.c tree-ssa test). > > Bootstrapped and regression tested in x86. > > PR tree-optimization/119420 > > gcc/ChangeLog: > > * match.pd(`(A>>bool) EQ 0 -> (unsigned)A) LE bool`): New > pattern. > > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/pr119420.c: New test. > --- > gcc/match.pd | 8 ++++++++ > gcc/testsuite/gcc.dg/tree-ssa/pr119420.c | 23 +++++++++++++++++++++++ > 2 files changed, 31 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr119420.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index 7f16fd4e081..348e9f45a28 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -5367,6 +5367,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > @0))))) > #endif > > +/* PR119420: (A >> bool) == 0 -> (unsigned)a <= (unsigned)bool; */ > +(simplify > + (eq (rshift @0 zero_one_valued_p@1) integer_zerop) > + (with { > + tree utype = unsigned_type_for (TREE_TYPE (@0)); > + } > + (le (convert:utype @0) (convert:utype @1)))) Formatting nit. Either bring the open curly down to its own line or put the whole thing on 1 max 80 column line like { tree utype ... ; } I would make a note about the clz/ctz interaction in the comment before the match.pd pattern. Otherwise folks would have to come to this discussion to find that nugget. OK for gcc-17 with those two NFC changes and when gcc-17 is open for development. Jeff
