Fix -fcompare-debug bugs during updating into loop closed ssa form (PR debug/80436)

Message ID 20170419135519.GG1809@tucnak
State New
Headers show

Commit Message

Jakub Jelinek April 19, 2017, 1:55 p.m.
Hi!

-fcompare-debug fails on the following testcase, because during loop
splitting we attempt to switch into loop closed SSA form and use
also debug stmt uses in those decisions, which is wrong.
Looking at the rest of tree-ssa-loop-manip.c, both find_uses_to_rename_stmt
and check_loop_closed_ssa_stmt ignore debug stmts, this patch just adds
that to another spot.  Without it a new SSA_NAME is created (only with -g)
and then soon (in the next pass) removed again because DCE sees it as
dead (it has no non-debug uses) and is replaced by the definition from the
loop again.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-04-19  Jakub Jelinek  <jakub@redhat.com>

	PR debug/80436
	* tree-ssa-loop-manip.c (find_uses_to_rename_def): Ignore debug uses.

	* g++.dg/opt/pr80436.C: New test.


	Jakub

Comments

Jeff Law April 19, 2017, 2:45 p.m. | #1
On 04/19/2017 07:55 AM, Jakub Jelinek wrote:
> Hi!
> 
> -fcompare-debug fails on the following testcase, because during loop
> splitting we attempt to switch into loop closed SSA form and use
> also debug stmt uses in those decisions, which is wrong.
> Looking at the rest of tree-ssa-loop-manip.c, both find_uses_to_rename_stmt
> and check_loop_closed_ssa_stmt ignore debug stmts, this patch just adds
> that to another spot.  Without it a new SSA_NAME is created (only with -g)
> and then soon (in the next pass) removed again because DCE sees it as
> dead (it has no non-debug uses) and is replaced by the definition from the
> loop again.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2017-04-19  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR debug/80436
> 	* tree-ssa-loop-manip.c (find_uses_to_rename_def): Ignore debug uses.
> 
> 	* g++.dg/opt/pr80436.C: New test.
OK.
jeff

Patch

--- gcc/tree-ssa-loop-manip.c.jj	2017-02-27 15:19:12.000000000 +0100
+++ gcc/tree-ssa-loop-manip.c	2017-04-19 09:47:30.768610273 +0200
@@ -494,6 +494,9 @@  find_uses_to_rename_def (tree def, bitma
 
   FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
     {
+      if (is_gimple_debug (use_stmt))
+	continue;
+
       basic_block use_bb = gimple_bb (use_stmt);
 
       use_operand_p use_p;
--- gcc/testsuite/g++.dg/opt/pr80436.C.jj	2017-04-19 09:54:59.370714079 +0200
+++ gcc/testsuite/g++.dg/opt/pr80436.C	2017-04-19 09:56:28.003549930 +0200
@@ -0,0 +1,42 @@ 
+// PR debug/80436
+// { dg-do compile { target c++11 } }
+// { dg-options "-O3 -fcompare-debug" }
+
+void fn (...);
+void foo (int, int, int);
+struct { int elt1; int bits; } *a;
+int b, d;
+
+int
+bar (unsigned *x)
+{
+  if (0)
+  next_bit:
+    return 1;
+  while (1)
+    {
+      if (b)
+	if (a->bits)
+	  goto next_bit;
+      *x = b;
+      if (a->elt1)
+	return 0;
+      a = 0;
+    }
+}
+
+enum { C0, C1 } *c;
+
+void
+baz ()
+{
+  int e, m = d;
+  for (; e < m; e++)
+    {
+      if (e < 0)
+	foo (0, 0, c[e]);
+      unsigned f;
+      for (; bar (&f);)
+	fn (f);
+    }
+}