diff mbox

fwprop: fix REG_DEAD notes rendered incorrect

Message ID orr51y3744.fsf@livre.localdomain
State New
Headers show

Commit Message

Alexandre Oliva Oct. 27, 2011, 1:18 p.m. UTC
fwprop may propagate a SET_SRC that contains the last use of a REG to a
later point, but it will leave the REG_DEAD note in place, even though
it is no longer correct.  I noticed this while investigating PR50826:
the initialization of the internal_arg_pointer has a REG_DEAD note for
%r29, but even after it is fwpropped, the note remains there.  This
patch fixes this bug.

It also reduces the risk of code divergence in VTA-enabled compilations,
by enabling the simpler test in all_uses_available_at when there are
debug insns between the def and the use.

Regstrapped on x86_64-linux-gnu and i686-linux-gnu.  Ok to install?

Comments

Eric Botcazou Oct. 27, 2011, 1:32 p.m. UTC | #1
> fwprop may propagate a SET_SRC that contains the last use of a REG to a
> later point, but it will leave the REG_DEAD note in place, even though
> it is no longer correct.  I noticed this while investigating PR50826:
> the initialization of the internal_arg_pointer has a REG_DEAD note for
> %r29, but even after it is fwpropped, the note remains there.  This
> patch fixes this bug.

This isn't necessarily a bug, i.e. passes aren't required to maintain REG_DEAD 
and REG_UNUSED notes up-to-date (another example is PR rtl-opt/48773).  Instead 
passes consuming these notes have to invoke df_note_add_problem on entry.
Alexandre Oliva Oct. 27, 2011, 4:06 p.m. UTC | #2
On Oct 27, 2011, Eric Botcazou <ebotcazou@adacore.com> wrote:

>> fwprop may propagate a SET_SRC that contains the last use of a REG to a
>> later point, but it will leave the REG_DEAD note in place, even though
>> it is no longer correct.  I noticed this while investigating PR50826:
>> the initialization of the internal_arg_pointer has a REG_DEAD note for
>> %r29, but even after it is fwpropped, the note remains there.  This
>> patch fixes this bug.

> This isn't necessarily a bug, i.e. passes aren't required to maintain
> REG_DEAD and REG_UNUSED notes up-to-date (another example is PR
> rtl-opt/48773).  Instead passes consuming these notes have to invoke
> df_note_add_problem on entry.

It looked confusing, and it wasn't hard to fix, but, ok, patch
withdrawn.
diff mbox

Patch

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* fwprop.c (all_uses_available_at): Skip debug insns.
	(try_fwprop_subst): Drop outdated REG_DEAD notes.
	
Index: gcc/fwprop.c
===================================================================
--- gcc/fwprop.c.orig	2011-10-26 06:37:08.154321512 -0200
+++ gcc/fwprop.c	2011-10-26 06:52:44.163150398 -0200
@@ -801,7 +801,7 @@  all_uses_available_at (rtx def_insn, rtx
 
   /* If target_insn comes right after def_insn, which is very common
      for addresses, we can use a quicker test.  */
-  if (NEXT_INSN (def_insn) == target_insn
+  if (next_nondebug_insn (def_insn) == target_insn
       && REG_P (SET_DEST (def_set)))
     {
       rtx def_reg = SET_DEST (def_set);
@@ -1019,6 +1019,22 @@  try_fwprop_subst (df_ref use, rtx *loc, 
 	}
     }
 
+  if (ok)
+    {
+      rtx *link = &REG_NOTES (def_insn);
+
+      while (*link)
+	if (REG_NOTE_KIND (*link) == REG_DEAD
+	    && reg_mentioned_p (XEXP (*link, 0), new_rtx))
+	  /* We could propagate the REG_DEAD note if we knew we're
+	     propagating into what will become a death point.
+	     Considering multiple uses in different BBs, some of which
+	     may be debug uses requiring debug stmts to be introduced,
+	     how about we just let DF take care of it?  */
+	  *link = XEXP (*link, 1);
+	else
+	  link = &XEXP (*link, 1);
+    }
   if ((ok || note) && !CONSTANT_P (new_rtx))
     update_df (insn, note);