https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117699
--- Comment #4 from Georg-Johann Lay <gjl at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #2) > I think the problem is in peep2_find_free_register: > /* Don't use registers set or clobbered by the insn. */ > FOR_EACH_INSN_DEF (def, peep2_insn_data[from].insn) > SET_HARD_REG_BIT (live, DF_REF_REGNO (def)); > > This only sets the live info based on the regno here. > > > But it should be instead (with fixed formating): > ``` > /* Don't use registers set or clobbered by the insn. */ > FOR_EACH_INSN_DEF (def, peep2_insn_data[from].insn) > add_to_hard_reg_set (&live, GET_MODE (DF_REF_REAL_REG (def)), DF_REF_REGNO > (def)); > ``` > > This is similar to what is done in compute_regs_asm_clobbered (ira.cc). I must admit that I don't completely understand the fix / bug. peep2_find_free_register() currently reads: from = peep2_buf_position (peep2_current + from); to = peep2_buf_position (peep2_current + to); gcc_assert (peep2_insn_data[from].insn != NULL_RTX); REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before); while (from != to) { gcc_assert (peep2_insn_data[from].insn != NULL_RTX); /* Don't use registers set or clobbered by the insn. */ FOR_EACH_INSN_DEF (def, peep2_insn_data[from].insn) SET_HARD_REG_BIT (live, DF_REF_REGNO (def)); from = peep2_buf_position (from + 1); } For the test case we have from = to = 3, so that while loop isn't even executed. I also tested the patch. The patch has no effect on the test case.