https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65979
--- Comment #13 from Kazumoto Kojima <kkojima at gcc dot gnu.org> --- Created attachment 35572 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35572&action=edit reduced testcase >From rtl dumps for 5.1.0 cc1plus against the testcase, the wrong peephole transformation makes (insn 92 14 15 3 (set (reg:SI 1 r1 [orig:171 D.2078 ] [171]) (reg:SI 2 r2 [172])) 252 {movsi_ie} (expr_list:REG_DEAD (reg:SI 2 r2 [172]) (nil))) (insn 93 16 83 3 (set (reg:SI 2 r2) (const_int 66602 [0x1042a])) 252 {movsi_ie} (nil)) (insn 83 93 18 3 (set (reg:SI 147 t) (eq:SI (and:SI (reg:SI 1 r1 [orig:171 D.2078 ] [171]) (reg:SI 2 r2)) (const_int 0 [0]))) 1 {tstsi_t} (expr_list:REG_DEAD (reg:SI 2 r2) (expr_list:REG_DEAD (reg:SI 1 r1 [orig:171 D.2078 ] [171]) (nil)))) into (insn 112 14 113 3 (set (reg:SI 2 r2) (const_int 66602 [0x1042a])) -1 (nil)) (insn 113 112 114 3 (set (reg:SI 147 t) (eq:SI (and:SI (reg:SI 2 r2) (reg:SI 2 r2)) (const_int 0 [0]))) -1 (nil)) (insn 114 113 18 3 (const_int 0 [0]) -1 (nil)) This peephole transformation is done by ;; mov.w @(18,r1),r0 (r0 = HImode) ;; mov r0,r1 (r0 = r1 = HImode) mov.w @(18,r1),r0 ;; ... ..,r13 (r13 = SImode) -> ... ..,r13 ;; tst r1,r13 tst r0,r13 (define_peephole2 [(set (match_operand 0 "arith_reg_dest") (match_operand 1 "arith_reg_dest")) (set (match_operand:SI 2 "arith_reg_dest") (match_operand:SI 3)) (set (reg:SI T_REG) (eq:SI (and:SI (match_operand:SI 4 "arith_reg_operand") (match_operand:SI 5 "arith_reg_operand")) (const_int 0)))] "TARGET_SH1 && peep2_reg_dead_p (3, operands[0]) && !reg_overlap_mentioned_p (operands[0], operands[3]) && (REGNO (operands[0]) == REGNO (operands[4]) || REGNO (operands[0]) == REGNO (operands[5])) && (REGNO (operands[2]) == REGNO (operands[4]) || REGNO (operands[2]) == REGNO (operands[5]))" [(const_int 0)] { sh_check_add_incdec_notes (emit_move_insn (operands[2], operands[3])); emit_insn (gen_tstsi_t (operands[2], gen_rtx_REG (SImode, (REGNO (operands[1]))))); }) Looks that this doesn't work when the operand 1 is equal to the operand 2 which is the case for the above insns 92, 93 and 83. The peephole removed with the fix in PR65153 transformed these insns prior to the above peephole so to avoid the problem. The patch below fixes this case. It looks there are similar peephole patterns,though. Oleg, if you get the spare time, could you look into these peepholes? -- diff --git a/config/sh/sh.md b/config/sh/sh.md index 27f0074..5bc3401 100644 --- a/config/sh/sh.md +++ b/config/sh/sh.md @@ -14750,6 +14750,7 @@ label: "TARGET_SH1 && peep2_reg_dead_p (3, operands[0]) && !reg_overlap_mentioned_p (operands[0], operands[3]) + && !reg_overlap_mentioned_p (operands[1], operands[2]) && (REGNO (operands[0]) == REGNO (operands[4]) || REGNO (operands[0]) == REGNO (operands[5])) && (REGNO (operands[2]) == REGNO (operands[4])