http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54830
--- Comment #1 from Oleg Endo <olegendo at gcc dot gnu.org> 2012-10-18 19:24:36 UTC --- Created attachment 28487 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28487 Reduced test case This is the reduced test case. It shows that there are actually two redundant zero/sign extensions when compiling with -m4 {-ml|-mb} -O2: swap.w r5,r5 ! 88 rotlsi3_16 ... exts.w r5,r5 ! 89 *extendhisi2_compact_reg ... extu.b r5,r9 ! 10 *zero_extendqisi2_compact ... extu.b r9,r12 ! 11 *zero_extendqisi2_compact ... Turning on the REE pass (-free) doesn't seem to help this either. Adding the following pattern to sh.md: (define_insn_and_split "*" [(set (match_operand:SI 0 "register_operand") (zero_extract:SI (match_operand:SI 1 "register_operand") (const_int 8) (const_int 16)))] "TARGET_SH1" "#" "&& 1" [(set (match_dup 0) (lshiftrt:SI (match_dup 1) (const_int 16))) (set (match_dup 0) (zero_extend:SI (match_dup 2)))] { operands[2] = gen_lowpart (QImode, operands[0]); }) eliminates the first sign-extension (exts.w) only. The second zero-extension can be eliminated by extending sh_try_omit_signzero_extend in sh.c accordingly.