https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120221
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed|2025-05-11 00:00:00 |2025-05-12 CC| |pheeck at gcc dot gnu.org Status|UNCONFIRMED |NEW --- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> --- So <bb 2> [local count: 1073741816]: _1 = (long unsigned int) val_5(D); _2 = _1 >> 3; _3 = _2 & 3; if (_3 == 0) goto <bb 5>; [33.33%] else goto <bb 3>; [66.67%] <bb 3> [local count: 715827875]: if (_3 == 2) could be transformed to _1 = (long unsigned int) val_5(D); _2 = _1; _3 = _2 & (3 << 3); if (_3 == 0 << 3) goto <bb 5>; [33.33%] else goto <bb 3>; [66.67%] <bb 3> [local count: 715827875]: if (_3 == 2 << 3) for a case where we only check a right-shifted value without AND we'd have to add a AND operation masking out the shifted bits to elide the shift. Extra care has to be taken when the tested value can be negative, the shift can duplicate the sign bit into the set of relevant bits (depending on shift amount and the existing AND mask this can or can not be disregarded).