public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix -fcompare-debug bugs during updating into loop closed ssa form (PR debug/80436)
@ 2017-04-19 14:28 Jakub Jelinek
  2017-04-19 14:51 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-04-19 14:28 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

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.

--- 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);
+    }
+}

	Jakub

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

* Re: [PATCH] Fix -fcompare-debug bugs during updating into loop closed ssa form (PR debug/80436)
  2017-04-19 14:28 [PATCH] Fix -fcompare-debug bugs during updating into loop closed ssa form (PR debug/80436) Jakub Jelinek
@ 2017-04-19 14:51 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2017-04-19 14:51 UTC (permalink / raw)
  To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches

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

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

end of thread, other threads:[~2017-04-19 14:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-19 14:28 [PATCH] Fix -fcompare-debug bugs during updating into loop closed ssa form (PR debug/80436) Jakub Jelinek
2017-04-19 14:51 ` Jeff Law

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).