https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77664
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |easyhack, | |missed-optimization Status|UNCONFIRMED |NEW Last reconfirmed| |2016-09-21 Ever confirmed|0 |1 Severity|normal |enhancement --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed, The general optimization is the following: (si >= 0) & si < (int)ushorteri -> ((unsigned)si) < (unsigned)ushorteri Or in almost match.pd syntax (but needs some changes to get to the correct format and it needs to handle le/gt instead of just ge/lt): (simplify (bit_and (ge @0 integer_zerop) (lt @0 (convert @2))) (if (signed_type(@0) && unsigned_type(@2) && sizeof(@0) >= sizeof(@2)) (lt { build_convert(unsignedtypeof(@0), @0); } { build_convert(unsignedtypeof(@0), @2); }))