public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/57723] New: Missed optimization: recursion around empty function
@ 2013-06-26 10:44 petschy at gmail dot com
  2013-06-26 10:44 ` [Bug tree-optimization/57723] " petschy at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: petschy at gmail dot com @ 2013-06-26 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57723
           Summary: Missed optimization: recursion around empty function
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: petschy at gmail dot com

Background: freeing nodes of a tree allocated with custom allocators. One of
the allocators can't free individual pointers, so free() is NOP in that case
(the whole pool will be freed at once when the allocator is destroyed). With
this allocator, the whole recursive traversal can be eliminated in theory.

Examining the disasm of the generated code revealed that gcc unfolds the
recursion many levels, just to do the unneeded node traversal; the actual call
to the empty free() fn is eliminated.

In the test case, loop() does a simple linear traversal of the linked nodes.
The pointers are not volatile, and are only read, so there should not be any
side effects. Why can't the compiler optimize away the whole loop?

Clang does a somewhat better job, the recursion is optimized away, and one
function is completely reduced to NOP (free_all2()), but the others still have
the node traversal loop.

Tried with gcc 4.6, 4.7.3, 4.9.0 with the same results.

g++-4.9.0 -v:
Using built-in specs.
COLLECT_GCC=g++-4.9.0
COLLECT_LTO_WRAPPER=/home/usr-local/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --enable-languages=c,c++ --program-suffix=-4.9.0
Thread model: posix
gcc version 4.9.0 20130626 (experimental) (GCC) 
commit 944f42fc29289812416f34d7b0c497ee79065396

command line:
g++-4.9.0 -std=c++11 -O3 -Wall 20130626-free_node.cpp

Regards, Peter


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

end of thread, other threads:[~2013-06-27 20:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-26 10:44 [Bug tree-optimization/57723] New: Missed optimization: recursion around empty function petschy at gmail dot com
2013-06-26 10:44 ` [Bug tree-optimization/57723] " petschy at gmail dot com
2013-06-26 10:45 ` petschy at gmail dot com
2013-06-26 10:45 ` petschy at gmail dot com
2013-06-26 11:13 ` petschy at gmail dot com
2013-06-26 13:44 ` matz at gcc dot gnu.org
2013-06-27 13:34 ` mikpe at it dot uu.se
2013-06-27 20:30 ` petschy at gmail dot com

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