[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-04-01 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #13 from Richard Biener  ---
*** Bug 89791 has been marked as a duplicate of this bug. ***

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-27 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #11 from Richard Biener  ---
Author: rguenth
Date: Wed Mar 27 09:31:53 2019
New Revision: 269961

URL: https://gcc.gnu.org/viewcvs?rev=269961=gcc=rev
Log:
2019-03-27  Richard Biener  

PR tree-optimization/89463
* tree-ssa-dce.c (remove_dead_stmt): Take output vector to
queue edges to remove.
(eliminate_unnecessary_stmts): Remove dead PHIs alongside
dead stmts.  Delay edge removal until PHIs are removed to
make debug-stmt creation not confused by seemingly degenerate
PHIs.

* gcc.dg/guality/pr89463.c: New testcase.

Added:
trunk/gcc/testsuite/gcc.dg/guality/pr89463.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-dce.c

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-27 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

Richard Biener  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
  Known to work||9.0
 Resolution|--- |FIXED
  Known to fail||8.3.0

--- Comment #12 from Richard Biener  ---
Fixed for GCC 9.

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-25 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #9 from Qirun Zhang  ---
(In reply to Richard Biener from comment #8)
> Patch posted here: https://gcc.gnu.org/ml/gcc-patches/2019-03/msg01192.html
> 
> Some of your bugs might turn out as duplicates if they are fixed by that
> patch.

Thanks, Richard. When will the patch be landed? It helps a lot to reduce
duplicates.

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-25 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #10 from rguenther at suse dot de  ---
On Mon, 25 Mar 2019, qrzhang at gatech dot edu wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463
> 
> --- Comment #9 from Qirun Zhang  ---
> (In reply to Richard Biener from comment #8)
> > Patch posted here: https://gcc.gnu.org/ml/gcc-patches/2019-03/msg01192.html
> > 
> > Some of your bugs might turn out as duplicates if they are fixed by that
> > patch.
> 
> Thanks, Richard. When will the patch be landed? It helps a lot to reduce
> duplicates.

I'm waiting for testing/ACK.

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-25 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #8 from Richard Biener  ---
Patch posted here: https://gcc.gnu.org/ml/gcc-patches/2019-03/msg01192.html

Some of your bugs might turn out as duplicates if they are fixed by that patch.

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-25 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

Richard Biener  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org

--- Comment #7 from Richard Biener  ---
 :
# i_5 = PHI <_11(5), 0(8)>
# DEBUG i => i_5
if (i_5 != 6)
  goto ; [INV]
else
  goto ; [100.00%]

 :
# DEBUG BEGIN_STMT
# DEBUG i => i_5 + 1

So it goes like so the following.  First we remove the iterator update in
BB5 (unrelated).  Then we remove the control stmt, removing the edge 6 -> 5.

This leaves us with

# i_5 = PHI <0(8)>
# DEBUG i => i_5

then we remove the PHI node which inserts the bogus debug stmt.

Stmt and control-flow removal in DCE is somewhat a twisted maze but the fix
has to be there, avoiding the above situation.

For simple IVs we could compute the final value and insert a debug stmt
after the loop.  But for IVs we cannot analyze a similar situation will
arise and thus we have to somehow compute a # DEBUG i => NULL stmt from
the above.

But that means we have to queue edges we want to remove (plus eventually
blocks we can avoid looking at for stmt removal) and perform CFG pruning
only afterwards (like leave it to CFG cleanup by changing conditionals
to if (true/false)).  Doing that (just for conditions) gives us the
expected

@@ -24,22 +52,10 @@
   if (a.1_3 <= 9)
 goto ; [INV]
   else
-goto ; [INV]
-
-   :
-  # DEBUG BEGIN_STMT
-  i_11 = i_5 + 1;
-  # DEBUG i => i_11
-
-   :
-  # i_5 = PHI 
-  # DEBUG i => i_5
-  if (i_5 != 6)
 goto ; [INV]
-  else
-goto ; [INV]

-   :
+   :
+  # DEBUG i => NULL
   # DEBUG BEGIN_STMT
   optimize_me_not ();
   return 0;

but that's not because of CFG cleanup but because we do not remove the
edge so at PHI removal time we still have both values.

A non-loopy testcase may also go wrong I guess but it's usually optimized
earlier and not by DCE.

I have a patch.

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #6 from Qirun Zhang  ---
As mentioned in my earlier comment, the revision should be between gcc-5 and
gcc-6.

Bisect points to r239357.


commit ec969ce4161538b561592a032eca6dcfaf513596
Author: rguenth 
Date:   Thu Aug 11 09:02:04 2016 +

2016-08-11  Richard Biener  

PR tree-optimization/72772
* cfgloopmanip.c (create_preheader): Use split_edge if there
is a single loop entry, avoiding degenerate PHIs.

* gcc.dg/graphite/pr35356-1.c: Adjust.
* gcc.dg/tree-ssa/pr59597.c: Likewise.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239357
138bc75d-0d04-0410-961f-82ee72b054a4

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #5 from Qirun Zhang  ---
(In reply to Qirun Zhang from comment #4)
> Bisect points to r151362.
> 
> commit ff79704e04af919c4fe501c7dceca8b21cced614
> Author: aoliva 
> Date:   Thu Sep 3 05:24:57 2009 +
> 
> * toplev.c (process_options): Enable var-tracking-assignments
> by default if var-tracking is enabled.
> 
> 
> git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151362
> 138bc75d-0d04-0410-961f-82ee72b054a4

Sorry... Please discard this comment. This was meant for another bug. Let me
post the bisect result in the following comment..

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #4 from Qirun Zhang  ---
Bisect points to r151362.

commit ff79704e04af919c4fe501c7dceca8b21cced614
Author: aoliva 
Date:   Thu Sep 3 05:24:57 2009 +

* toplev.c (process_options): Enable var-tracking-assignments
by default if var-tracking is enabled.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151362
138bc75d-0d04-0410-961f-82ee72b054a4

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-02-26 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

Richard Biener  changed:

   What|Removed |Added

   Keywords||wrong-debug
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-02-26
Version|unknown |9.0
 Ever confirmed|0   |1
   Severity|enhancement |normal

--- Comment #3 from Richard Biener  ---
stmt removal should generate a # DEBUG i = NULL note but eventually removal
inside a CFG cycle is awkward enough that this doesn't work reliably.  In
fact we seem to get an extra = 0 note, likely from the attempt to generate
a i => i_5 one.

--- t.i.036t.dse1   2019-02-26 09:46:03.325257454 +0100
+++ t.i.037t.cddce1 2019-02-26 09:46:03.329257503 +0100
...
@@ -24,22 +52,10 @@
   if (a.1_3 <= 9)
 goto ; [INV]
   else
-goto ; [INV]
-
-   :
-  # DEBUG BEGIN_STMT
-  i_11 = i_5 + 1;
-  # DEBUG i => i_11
-
-   :
-  # i_5 = PHI 
-  # DEBUG i => i_5
-  if (i_5 != 6)
 goto ; [INV]
-  else
-goto ; [INV]

-   :
+   :
+  # DEBUG i => 0
   # DEBUG BEGIN_STMT
   optimize_me_not ();
   return 0;

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-02-22 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #2 from Qirun Zhang  ---
(In reply to Andrew Pinski from comment #1)
> What is happening is the empty loop is being removed and not replaced with a
> debug statement say i is 6 afterwards.  I don't know if this is a good idea
> to put a debug statement here or not.

Agreed.
Nevertheless, it should not print a wrong value.
The expected behavior is "" like  what gcc-6.5.0 does as
follows:


$ gcc-6 -O3 out.c abc.c -g
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x547: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8 optimize_me_not();
$1 = 
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 17644) killed]

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-02-22 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

Andrew Pinski  changed:

   What|Removed |Added

Summary|gcc generates wrong debug   |debug information for
   |information at -O3  |iteractor of an empty loop
   ||is gone (at -O3)
   Severity|normal  |enhancement

--- Comment #1 from Andrew Pinski  ---
What is happening is the empty loop is being removed and not replaced with a
debug statement say i is 6 afterwards.  I don't know if this is a good idea to
put a debug statement here or not.