public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Dehao Chen <dehao@google.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Reset source location for instructions moved out of its original residing basic block
Date: Thu, 01 Nov 2012 05:03:00 -0000	[thread overview]
Message-ID: <CAO2gOZX755CHumZdb2NGGVhLUtkLQa0HJRfdc7vHStQgqonXAw@mail.gmail.com> (raw)

[-- 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} }

             reply	other threads:[~2012-11-01  5:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-01  5:03 Dehao Chen [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAO2gOZX755CHumZdb2NGGVhLUtkLQa0HJRfdc7vHStQgqonXAw@mail.gmail.com \
    --to=dehao@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).