public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/48837] New: Wrong optimization of recursive function calls
@ 2011-04-30 21:26 personal@e-maxx.ru
  2011-05-01  7:29 ` [Bug tree-optimization/48837] " personal@e-maxx.ru
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: personal@e-maxx.ru @ 2011-04-30 21:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48837

           Summary: Wrong optimization of recursive function calls
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: personal@e-maxx.ru


Created attachment 24153
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24153
The example program - it should output "ans = 1", but outputs "ans = 0" in -O2

The program attached outputs "global ans = 1" if compiled without
optimizations, and "global ans = 0" with -O2 set.

Moreover, if we insert debug-output into the recursive function, it becomes
working right:
    //cout << "query = " << ans << endl;
    // ^^^^^ UNCOMMENT THIS LINE TO MAKE THE PROGRAM WORK OK
If we uncomment the line, the program outputs "global ans = 1" both with -O2
and without it.



Unfortunately, I couldn't make the test program very simple - optimizer works
OK on simple programs, but when we have a complex recursion calls - it starts
making wrong code.


To make you understand it better - there are some additional debug-outputs.

For example, the right program flow results in the following output:

call auxillary (t[9], 123):
auxillary = 1
call auxillary (t[5], 123):
auxillary = 0
global ans = 1


When we compile with -O2, the output becomes:

call auxillary (t[9], 123):
auxillary = 1
call auxillary (t[5], 123):
auxillary = 0
global ans = 0

(note that from code we can see that query() returns sum of all recursive
answers - then how can it return 0, if one auxillary() returned 1???)


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

end of thread, other threads:[~2011-05-10  9:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-30 21:26 [Bug tree-optimization/48837] New: Wrong optimization of recursive function calls personal@e-maxx.ru
2011-05-01  7:29 ` [Bug tree-optimization/48837] " personal@e-maxx.ru
2011-05-01  7:31 ` d.g.gorbachev at gmail dot com
2011-05-01 17:18 ` hjl.tools at gmail dot com
2011-05-01 19:02 ` [Bug tree-optimization/48837] [4.4/4.5/4.6/4.6 Regression] " steven at gcc dot gnu.org
2011-05-01 19:27 ` steven at gcc dot gnu.org
2011-05-01 19:58 ` steven at gcc dot gnu.org
2011-05-01 20:24 ` steven at gcc dot gnu.org
2011-05-03  5:57 ` steven at gcc dot gnu.org
2011-05-04  8:43 ` rakdver at gcc dot gnu.org
2011-05-07 19:50 ` rakdver at gcc dot gnu.org
2011-05-10  8:49 ` [Bug tree-optimization/48837] [4.4/4.5/4.6 " jakub at gcc dot gnu.org
2011-05-10  8:53 ` jakub at gcc dot gnu.org
2011-05-10  8:57 ` jakub at gcc dot gnu.org
2011-05-10  9:03 ` jakub at gcc dot gnu.org

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