https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103509
Bug ID: 103509 Summary: ((-1u >> t) & b) != 0 is not optimized to b != 0 Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: bool f1(bool a, int t) { unsigned tt = -1; tt >>= t; return (a&tt) != 0; } bool f2(bool a, int t) { unsigned tt = -1; tt >>= t; return (tt) != 0; } As shown by the above, we know that (-1u>>t)!=0 is always true Therefore we should be able to optimize f1 to just a!=0