https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69946
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 37803 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37803&action=edit gcc6-pr69946.patch What about this untested patch? Ideas for better name of the new helper function? Seems that both rs6000_is_valid_shift_mask and rs6000_insn_for_shift_mask were doing pretty much the same thing in their first halves (preparation), except that for insert we assume that the shift count is always CONST_INT. So, this patch moves all that preparation into the helper, and uses it in all the 4 functions.