https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119509
--- Comment #8 from Nick Hudson <skrll at netbsd dot org> ---
(In reply to Andrew Pinski from comment #7)
> (In reply to Nick Hudson from comment #4)
> > (In reply to Andrew Pinski from comment #2)
> > > _5 = val_2(D) & 0xffff00;
> > > _1 = _5 > 0xff;
> > >
> > > Confirmed.
> > >
> > > GCC does handle:
> > > ```
> > > unsigned
> > > foo0(unsigned val)
> > > {
> > > return (val & (~0xff000000)) > 0xff;
> > > }
> > > ```
> > >
> > > Correctly.
> >
> > where does this happen?
> >
> > I've tried to find it in gcc/match.pd, but failed.
>
> ```
> (for cmp (le gt)
> eqcmp (eq ne)
> (simplify
> (cmp (bit_and@0 @1 INTEGER_CST@2) INTEGER_CST@3)
> (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
> (with
> {
> tree ty = TREE_TYPE (@0);
> unsigned prec = TYPE_PRECISION (ty);
> wide_int mask = wi::to_wide (@2, prec);
> wide_int rhs = wi::to_wide (@3, prec);
> signop sgn = TYPE_SIGN (ty);
> }
> (if ((mask & (mask + 1)) == 0 && wi::gt_p (rhs, 0, sgn)
> && (rhs & (rhs + 1)) == 0 && wi::ge_p (mask, rhs, sgn))
> (eqcmp (bit_and @1 { wide_int_to_tree (ty, mask - rhs); })
> { build_zero_cst (ty); }))))))
> ```
>
> You can find out via -fdump-tree-original-folding:
> Applying pattern match.pd:7941, generic-match-3.cc:3327
Yeah, I eventually worked this out and that how I created my candidate fix (if
I can call it that)