diff --git a/gcc/reorg.c b/gcc/reorg.c
index ec21a3503824f31d1371319a4ff4257fb252c751..cd7d6528f24bfd1f186a3baa3f0b1041935824a0 100644
--- a/gcc/reorg.c
+++ b/gcc/reorg.c
@@ -3972,6 +3972,17 @@ relax_delay_slots (first)
 
 	      if (invert_jump (delay_insn, label))
 		{
+		  int i;
+
+		  /* Must update the INSN_FROM_TARGET_P bits now that
+		     the branch is reversed, so that mark_target_live_regs
+		     will handle the delay slot insn correctly.  */
+		  for (i = 1; i < XVECLEN (PATTERN (insn), 0); i++)
+		    {
+		      rtx slot = XVECEXP (PATTERN (insn), 0, i);
+		      INSN_FROM_TARGET_P (slot) = ! INSN_FROM_TARGET_P (slot);
+		    }
+
 		  delete_insn (next);
 		  next = insn;
 		}