public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Reset source location for instructions moved out of its original residing basic block
@ 2012-11-01  5:03 Dehao Chen
  2012-11-01  8:56 ` Eric Botcazou
  0 siblings, 1 reply; 11+ messages in thread
From: Dehao Chen @ 2012-11-01  5:03 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1006 bytes --]

Hi,

When debugging optimized code, it is always confusing when gdb jumped
to a place that has never been executed. This is because compiler
performs some aggressive code motion that moves an instruction outside
of its original residing basic block.

This patch tries to fix this problem by resetting the source location
when moving instructions to another BB. This can greatly improve the
debuggability of optimized code. For the attached unittest. Without
the patch, the debugger will always jump into line 14 even when the
branch at line 13 is not taken. With the patch, the problem is fixed.

Bootstrapped and passed gcc regression test.

Is it okay for trunk?

Thanks,
Dehao

gcc/ChangeLog:
2012-10-31  Dehao Chen  <dehao@google.com>

        * emit-rtl.c (reorder_insns): Reset the source location for
        instructions moved out of its original residing basic block.

gcc/testsuite/ChangeLog:
2012-10-31  Dehao Chen  <dehao@google.com>

        * gcc.dg/debug/dwarf2/code-motion.c: New testcase.

[-- Attachment #2: code-motion.patch --]
[-- Type: application/octet-stream, Size: 1232 bytes --]

Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	(revision 193056)
+++ gcc/emit-rtl.c	(working copy)
@@ -4111,8 +4111,12 @@ reorder_insns (rtx from, rtx to, rtx after)
 	BB_END (bb) = to;
 
       for (x = from; x != NEXT_INSN (to); x = NEXT_INSN (x))
-	if (!BARRIER_P (x))
-	  df_insn_change_bb (x, bb);
+	{
+	  if (!BARRIER_P (x))
+	    df_insn_change_bb (x, bb);
+	  if (GET_CODE (after) == INSN && GET_CODE (x) == INSN)
+	    INSN_LOCATION (x) = INSN_LOCATION (after);
+	}
     }
 }
 
Index: gcc/testsuite/gcc.dg/debug/dwarf2/code-motion.c
===================================================================
--- gcc/testsuite/gcc.dg/debug/dwarf2/code-motion.c	(revision 0)
+++ gcc/testsuite/gcc.dg/debug/dwarf2/code-motion.c	(revision 0)
@@ -0,0 +1,20 @@
+// This test makes sure code motion will not pollute debug info.
+// { dg-do compile { target { i?86-*-* x86_64-*-* } } }
+// { dg-options "-O2 -g -dA" }
+extern int bar(int);
+
+int foo(int *a, int x)
+{
+  int y = 5;
+  int ret = 10;
+
+  a[0] = ret * y;
+
+  if (x > 5)
+    y = a[a[3]];
+  y = y * 2 + a[3];
+  ret += bar(y);
+
+  return ret;
+}
+// { dg-final { scan-assembler-times "code-motion.c:14" 1} }

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-11-26 14:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-01  5:03 [PATCH] Reset source location for instructions moved out of its original residing basic block Dehao Chen
2012-11-01  8:56 ` Eric Botcazou
2012-11-01 14:36   ` Dehao Chen
2012-11-01 15:04     ` Eric Botcazou
2012-11-01 17:00       ` Dehao Chen
2012-11-01 22:57         ` Ian Lance Taylor
2012-11-01 23:07           ` Xinliang David Li
2012-11-01 23:16             ` Dehao Chen
2012-11-01 23:36               ` Xinliang David Li
2012-11-04 22:26         ` Alexandre Oliva
2012-11-26 14:47           ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).