Index: gcc/combine.c =================================================================== --- gcc/combine.c (revision 214413) +++ gcc/combine.c (working copy) @@ -13499,7 +13499,38 @@ distribute_notes (rtx notes, rtx_insn *from_insn, || rtx_equal_p (XEXP (note, 0), elim_i1) || rtx_equal_p (XEXP (note, 0), elim_i0)) break; - tem_insn = i3; + + /* See PR62151. + It's possible to have below situation: + i0: r1 <- const_0 + i1: r2 <- r1 op_1 const_1 + REG_DEAD r1 + i2: r1 <- r2 op_2 const_2 + REG_DEAD r2 + i3: r3 <- r1 + i4: r4 <- r1 + + It is transformed into below code before distributing + the REG_DEAD note in i1: + i0: NOTE_INSN_DELETED + i1: NOTE_INSN_DELETED + i2: r1 <- const_combined + i3: r3 <- const_combined + i4: r4 <- r1 + + We need to check if i2 immediately modifies r1 otherwise + i2 would be deleted by below code when distributing + REG_DEAD note, leaving r1 in i4 uninitialied. + + We set TEM_INSN to i2 for this case indicating that we + need to find right place for distribution from i2. + */ + if (from_insn && i2 + && from_insn != i2 && from_insn != i3 + && reg_set_p (XEXP (note, 0), PATTERN (i2))) + tem_insn = i2; + else + tem_insn = i3; } if (place == 0)