diff --git a/gcc/combine.cc b/gcc/combine.cc
index 3beeb514b81..0589ddbaca7 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -14557,9 +14557,12 @@ distribute_notes (rtx notes, rtx_insn *from_insn, rtx_insn *i3, rtx_insn *i2,
 		 we're also setting or clobbering the register as
 		 scratch, we know (because the register was not
 		 referenced in i3) that it's unused, just as it was
-		 unused before, and we place the note in i2.  */
+		 unused before, and we place the note in i2.  If this
+		 register is still referenced in i3, the note can be
+		 discarded.  */
 	      if (from_insn != i3 && i2 && INSN_P (i2)
-		  && reg_referenced_p (XEXP (note, 0), PATTERN (i2)))
+		  && reg_referenced_p (XEXP (note, 0), PATTERN (i2))
+		  && !reg_referenced_p (XEXP (note, 0), PATTERN (i3)))
 		{
 		  if (!reg_set_p (XEXP (note, 0), PATTERN (i2)))
 		    PUT_REG_NOTE_KIND (note, REG_DEAD);
diff --git a/gcc/testsuite/gcc.target/i386/pr118739.c b/gcc/testsuite/gcc.target/i386/pr118739.c
new file mode 100644
index 00000000000..89bed546363
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr118739.c
@@ -0,0 +1,50 @@
+/* PR rtl-optimization/118739 */
+/* { dg-do run } */
+/* { dg-options "-O3 -fno-tree-forwprop -fno-tree-vrp" } */
+
+volatile int a;
+int b, c, d = 1, e, f, g;
+
+int h (void)
+{
+  int i = 1;
+
+ j:
+  for (b = 1; b; b--)
+    {
+      asm ("#");
+
+      g = 0;
+
+      for (; g <= 1; g++)
+	{
+	  int k = f = 0;
+
+	  for (; f <= 1; f++)
+	    k = (1 == i) >= k || ((d = 0) >= a) + k;
+	}
+    }
+
+  for (; i < 3; i++)
+    {
+      if (!c)
+	return g;
+
+      if (e)
+	goto j;
+
+      asm ("#");
+    }
+
+  return 0;
+}
+
+int main()
+{
+  h();
+
+  if (d != 1)
+    __builtin_abort();
+
+  return 0;
+}
