This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fix incorrect debug temp added by df-problems


pr43165.c -Os -g exercises a bug in df-problems WRT the introduction of
debug temps.  After pro_and_epilogue, the function was optimized to this:

push bp
mov bp,sp
# debug insn referencing bp
pop bp

I don't know why we bother to preserve and set up bp, it's not used in
nondebug insns (and even with -g0 we still emit it).  GCC 4.5 did
better, but that's a different issue I haven't addressed.

The problem I address here is that the debug insn references bp, but
df-problems sees bp is dead at the debug insn during backward scanning,
and decides we have to emit a debug temp before its last use.

However, there isn't a last use: the set is dead, but it isn't regarded
as such because bp is in artificial_uses at the end of the block.  For
this reason, df_create_unused_note refrains from emitting the note and
resetting the debug uses.

However, the decision to emit a debug temp before the last bp use
remains in effect, so when the backward scanning reaches the push bp, it
emits a debug temp bound to the *previous* value of bp, and replaces
the debug use of bp with that.  Oops.

This patch arranges for us to not decide a debug use is dead if we won't
emit a REG_DEAD or REG_UNUSED note for it, because it is
artificially-used or an ignored stack reg.  An alternative would be to
remove any pending dead_debug entry from the list when we encounter a
set, but this is cheaper and it *should* be equivalent.

With this patch, the debug insn remains using bp, and no debug temp is
introduced.

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

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

	* df-problems.c (df_note_bb_compute): Do not add take note of
	debug uses for whose REGs we won't emit DEAD or UNUSED notes.
	
Index: gcc/df-problems.c
===================================================================
--- gcc/df-problems.c.orig	2011-10-26 11:02:16.709112252 -0200
+++ gcc/df-problems.c	2011-10-26 11:22:46.130851000 -0200
@@ -3410,7 +3410,12 @@ df_note_bb_compute (unsigned int bb_inde
 		{
 		  if (debug_insn > 0)
 		    {
-		      dead_debug_add (&debug, use, uregno);
+		      /* We won't add REG_UNUSED or REG_DEAD notes for
+			 these, so we don't have to mess with them in
+			 debug insns either.  */
+		      if (!bitmap_bit_p (artificial_uses, uregno)
+			  && (!df_ignore_stack_reg (uregno)))
+			dead_debug_add (&debug, use, uregno);
 		      continue;
 		    }
 		  break;

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]