https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64331

Oleg Endo <olegendo at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|avr                         |avr sh*-*-*
                 CC|                            |olegendo at gcc dot gnu.org

--- Comment #10 from Oleg Endo <olegendo at gcc dot gnu.org> ---
I've got a similar case on SH.  In the file spacetab.c, when compiled with -O2
-m4 -ml there's a sequence:

        cmp/eq  r3,r4
        movt    r3
        movt    r12
        cmp/gt  r0,r2

which should be rather (after scheduling):

        cmp/eq  r3,r4
        movt    r3
        cmp/gt  r0,r2
        mov     r3,r12

The sequence can be caught with a simple peephole:

(define_peephole2
  [(set (match_operand:SI 0 "arith_reg_dest")
        (match_operand:SI 1 "t_reg_operand"))
   (set (match_operand:SI 2 "arith_reg_dest")
        (match_operand:SI 3 "t_reg_operand"))]
  "TARGET_SH1"
  [(set (match_dup 0) (reg:SI T_REG))
   (set (match_dup 2) (match_dup 0))])

which doesn't work for some reason.

So I thought maybe something like this:

(define_peephole2
  [(set (match_operand:SI 0 "arith_reg_dest")
        (match_operand:SI 1 "t_reg_operand"))
   (set (match_operand:SI 2 "arith_reg_dest")
        (match_operand:SI 3 "t_reg_operand"))]
  "TARGET_SH1"
  [(const_int 0)]
{
  emit_insn (gen_movt (operands[0], get_t_reg_rtx ()));
  emit_move_insn (operands[2], operands[0]);
  DONE;
})

which emits the insns in the peephole2 pass as intended, but regcprop changes
them again into the undesired movt-movt sequence.  So I've tried adding a
REG_DEAD note to the first insn:

(define_peephole2
  [(set (match_operand:SI 0 "arith_reg_dest")
        (match_operand:SI 1 "t_reg_operand"))
   (set (match_operand:SI 2 "arith_reg_dest")
        (match_operand:SI 3 "t_reg_operand"))]
  "TARGET_SH1"
  [(const_int 0)]
{
  add_reg_note (emit_insn (gen_movt (operands[0], get_t_reg_rtx ())),
                REG_DEAD, get_t_reg_rtx ());

  emit_move_insn (operands[2], operands[0]);
  DONE;
})

and it is still ignored.  regcprop also doesn't look at any costs, so the only
solution to "fix" this is searching and replacing insns manually in split4.

Reply via email to