https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82853
--- Comment #19 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 44656 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44656&action=edit gcc9-pr82853-wip.patch Untested WIP patch which does this during expansion if it is cheaper according to target costs. As the FIXMEs say, I'm not yet trying Alex' proposal with doing the subtraction on X (can't be used unconditionally, need to prove that values from -C2 to -1 u% C1 aren't 0), and am not trying even C1 when rotates aren't available (either could just expand the rotate anyway using 2 shifts + or, or comparison + mask + comparison + bitwise and (though that would complicate the callers equite a bit).