diff mbox

Fix hoisting -fcompare-debug failures (PR debug/45105)

Message ID 20100728154547.GZ18378@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek July 28, 2010, 3:45 p.m. UTC
Hi!

If a bb ends with a DEBUG_INSN, bb_size between -g and -g0
compilation might differ.
The problem is that hoist_code forgets to count BB_END (bb)
instruction (and doesn't even set to_bb_head for it, so it is left at 0).
If in -g0 the block ends with a real insn and with -g with
DEBUG_INSN, in the latter case the last real insn will be counted.
As discussed with Maxim on IRC, we should count even the last insn.

Fixed by using FOR_BB_INSNS macro, bootstrapped/regtested on x86_64-linux
and i686-linux.  Ok for trunk?

2010-07-28  Jakub Jelinek  <jakub@redhat.com>

	PR debug/45105
	* gcse.c (hoist_code): Use FOR_BB_INSNS macro.

	* gcc.dg/pr45105.c: New test.


	Jakub

Comments

Jeff Law July 28, 2010, 4:39 p.m. UTC | #1
On 07/28/10 09:45, Jakub Jelinek wrote:
> Hi!
>
> If a bb ends with a DEBUG_INSN, bb_size between -g and -g0
> compilation might differ.
> The problem is that hoist_code forgets to count BB_END (bb)
> instruction (and doesn't even set to_bb_head for it, so it is left at 0).
> If in -g0 the block ends with a real insn and with -g with
> DEBUG_INSN, in the latter case the last real insn will be counted.
> As discussed with Maxim on IRC, we should count even the last insn.
>
> Fixed by using FOR_BB_INSNS macro, bootstrapped/regtested on x86_64-linux
> and i686-linux.  Ok for trunk?
>
> 2010-07-28  Jakub Jelinek<jakub@redhat.com>
>
> 	PR debug/45105
> 	* gcse.c (hoist_code): Use FOR_BB_INSNS macro.
>
> 	* gcc.dg/pr45105.c: New test.
OK.
Jeff
diff mbox

Patch

--- gcc/gcse.c.jj	2010-07-28 10:36:00.000000000 +0200
+++ gcc/gcse.c	2010-07-28 15:27:56.000000000 +0200
@@ -4389,21 +4389,15 @@  hoist_code (void)
   FOR_EACH_BB (bb)
     {
       rtx insn;
-      rtx bb_end;
       int to_head;
 
-      insn = BB_HEAD (bb);
-      bb_end = BB_END (bb);
       to_head = 0;
-
-      while (insn != bb_end)
+      FOR_BB_INSNS (bb, insn)
 	{
 	  /* Don't count debug instructions to avoid them affecting
 	     decision choices.  */
 	  if (NONDEBUG_INSN_P (insn))
 	    to_bb_head[INSN_UID (insn)] = to_head++;
-
-	  insn = NEXT_INSN (insn);
 	}
 
       bb_size[bb->index] = to_head;
--- gcc/testsuite/gcc.dg/pr45105.c.jj	2010-07-28 15:29:00.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr45105.c	2010-07-28 15:28:42.000000000 +0200
@@ -0,0 +1,27 @@ 
+/* PR debug/45105 */
+/* { dg-do compile } */
+/* { dg-options "-Os -fcompare-debug" } */
+
+extern int *baz (int *, int *);
+
+void
+bar (int *p1, int *p2)
+{
+  int n = *baz (0, 0);
+  p1[n] = p2[n];
+}
+
+void
+foo (int *p, int l)
+{
+  int a1[32];
+  int a2[32];
+  baz (a1, a2);
+  while (l)
+    {
+      if (l & 1)
+	p = baz (a2, p);
+      l--;
+      bar (a1, a2);
+    }
+}