https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108832
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |uros at gcc dot gnu.org --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- So, this is on (insn 263 304 17 2 (set (reg:DI 2 cx [98]) (reg:DI 1 dx [98])) "pr108832.c":15:9 discrim 1 82 {*movdi_internal} (expr_list:REG_DEAD (reg:DI 1 dx [98]) (nil))) (insn 17 263 261 2 (parallel [ (set (reg:CCZ 17 flags) (compare:CCZ (and:SI (reg:SI 2 cx [98]) (const_int -2 [0xfffffffffffffffe])) (const_int 0 [0]))) (set (reg:DI 2 cx) (zero_extend:DI (and:SI (reg:SI 2 cx [98]) (const_int -2 [0xfffffffffffffffe])))) ]) "pr108832.c":16:11 565 {*andsi_2_zext} (nil)) (insn 261 17 259 2 (set (reg:DI 0 ax) (const_int 1 [0x1])) 82 {*movdi_internal} (expr_list:REG_EQUIV (const_int 1 [0x1]) (nil))) (insn 259 261 4 2 (set (reg:DI 2 cx) (if_then_else:DI (ne (reg:CCZ 17 flags) (const_int 0 [0])) (reg:DI 2 cx) (reg:DI 0 ax))) 1304 {*movdicc_noc} (expr_list:REG_DEAD (reg:CCZ 17 flags) (expr_list:REG_DEAD (reg:DI 0 ax) (nil)))) on which ;; Eliminate a reg-reg mov by inverting the condition of a cmov (#1). ;; mov r0,r1; dec r0; mov r2,r3; cmov r0,r2 -> dec r1; mov r0,r3; cmov r0, r1 (define_peephole2 [(set (match_operand:SWI248 0 "general_reg_operand") (match_operand:SWI248 1 "general_reg_operand")) (parallel [(set (reg FLAGS_REG) (match_operand 5)) (set (match_dup 0) (match_operand:SWI248 6))]) (set (match_operand:SWI248 2 "general_reg_operand") (match_operand:SWI248 3 "general_gr_operand")) (set (match_dup 0) (if_then_else:SWI248 (match_operator 4 "ix86_comparison_operator" [(reg FLAGS_REG) (const_int 0)]) (match_dup 0) (match_dup 2)))] "TARGET_CMOVE && REGNO (operands[2]) != REGNO (operands[0]) && REGNO (operands[2]) != REGNO (operands[1]) && peep2_reg_dead_p (1, operands[1]) && peep2_reg_dead_p (4, operands[2]) && !reg_overlap_mentioned_p (operands[0], operands[3])" [(parallel [(set (match_dup 7) (match_dup 8)) (set (match_dup 1) (match_dup 9))]) (set (match_dup 0) (match_dup 3)) (set (match_dup 0) (if_then_else:SWI248 (match_dup 4) (match_dup 1) (match_dup 0)))] { operands[7] = SET_DEST (XVECEXP (PATTERN (peep2_next_insn (1)), 0, 0)); operands[8] = replace_rtx (operands[5], operands[0], operands[1], true); operands[9] = replace_rtx (operands[6], operands[0], operands[1], true); }) applies. replace_rtx has 2 modes, !all_regs in which it replaces just x == from with to and all_regs, in which case it does: if (all_regs && REG_P (x) && REG_P (from) && REGNO (x) == REGNO (from)) { gcc_assert (GET_MODE (x) == GET_MODE (from)); return to; } and so ICEs if we see the same REGNO as from in a different mode. I think we actually don't need most of what replace_rtx is doing, we don't need to simplify anything etc. because we are just changing one register to another and can do it in place. So, I think we need a different function for what the backend wants. It can avoid all the simplify stuff because replace_rtx was destructive, so could be implemented say using FOR_EACH_SUBRTX_PTR. When seeing *loc == from, it obviously should set *loc = to, if it sees REG_P (*loc) && REGNO (*loc) == REGNO (from), then if the mode is the same, it can also just *loc = to, but if it is a different mode, I'd say for narrower mode it should *loc = gen_rtx_REG (GET_MODE (*loc), REGNO (to)); and for wider mode (especially if say a multi-register reg) punt. Not sure if such a case can occur though, but the punting would be hard if we have made some changes already...