https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67328
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |WAITING Last reconfirmed| |2015-08-25 Ever confirmed|0 |1 --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- Note this is already fold-const.c:optimize_bit_field_compare at work. With -DALT (non-working code) we get ;; Function test_pic (null) ;; enabled by -tree-original { if ((BIT_FIELD_REF <*info, 8, 0> & 3) + 254 <= 1) and ;; Function test_exe (null) ;; enabled by -tree-original { if ((SAVE_EXPR <BIT_FIELD_REF <*info, 8, 0> & 3>) == 0 || (SAVE_EXPR <BIT_FIELD_REF <*info, 8, 0> & 3>) == 2) from it. Without -DALT ;; Function test_pic (null) ;; enabled by -tree-original { if ((SAVE_EXPR <BIT_FIELD_REF <*info, 8, 0> & 3>) == 3 || (SAVE_EXPR <BIT_FIELD_REF <*info, 8, 0> & 3>) == 1) ;; Function test_exe (null) ;; enabled by -tree-original { if ((BIT_FIELD_REF <*info, 8, 0> & 3) <= 1) I see more that a single bit test for both cases btw, mostly because we need to mask the padding. Not sure what optimal code you expect here.