public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59813] New: tail-call elimintation didn't fired with left-shift of char to cout
@ 2014-01-14 21:35 virkony at gmail dot com
  2014-01-14 22:05 ` [Bug c++/59813] " virkony at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: virkony at gmail dot com @ 2014-01-14 21:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59813
           Summary: tail-call elimintation didn't fired with left-shift of
                    char to cout
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: virkony at gmail dot com

#include <iostream>
using namespace std;

void foo()
{
    cout << "x" << endl; // ok
    cout << 'x' << endl; // kills tail-call elimination in gcc 4.8.2
    foo();
}

int main() { foo(); return 0; }

// core-dups by long stack while in 4.7.3 works as expected (infinite loop)


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

* [Bug c++/59813] tail-call elimintation didn't fired with left-shift of char to cout
  2014-01-14 21:35 [Bug c++/59813] New: tail-call elimintation didn't fired with left-shift of char to cout virkony at gmail dot com
@ 2014-01-14 22:05 ` virkony at gmail dot com
  2014-01-15  0:13 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: virkony at gmail dot com @ 2014-01-14 22:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Nikolay Orliuk <virkony at gmail dot com> ---
My 4.5.4 built without graphite support.
Both 4.7.3 and 4.8.2 built with cloog 0.17.0 and isl 0.11.2


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

* [Bug c++/59813] tail-call elimintation didn't fired with left-shift of char to cout
  2014-01-14 21:35 [Bug c++/59813] New: tail-call elimintation didn't fired with left-shift of char to cout virkony at gmail dot com
  2014-01-14 22:05 ` [Bug c++/59813] " virkony at gmail dot com
@ 2014-01-15  0:13 ` pinskia at gcc dot gnu.org
  2014-01-15  7:18 ` virkony at gmail dot com
  2014-01-15  7:23 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-01-15  0:13 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-01-15
     Ever confirmed|0                           |1
           Severity|major                       |normal

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The early inliner is inlining a function which contains a variable which maybe
escapes (address taken) which is causing the tail-call elimination not to
happen.  There are a few ways of fixing this:
1)  Changing the the early inlining heuristics so it will not inline functions
where local variables have their address taken.
2) Or have a tail-call optimize pass before early inlining.


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

* [Bug c++/59813] tail-call elimintation didn't fired with left-shift of char to cout
  2014-01-14 21:35 [Bug c++/59813] New: tail-call elimintation didn't fired with left-shift of char to cout virkony at gmail dot com
  2014-01-14 22:05 ` [Bug c++/59813] " virkony at gmail dot com
  2014-01-15  0:13 ` pinskia at gcc dot gnu.org
@ 2014-01-15  7:18 ` virkony at gmail dot com
  2014-01-15  7:23 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: virkony at gmail dot com @ 2014-01-15  7:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Nikolay Orliuk <virkony at gmail dot com> ---
Andrew Pinski, as long as address of variable isn't taken out of scope of
function that is being tail-call optimized there is no need to worry about it
and it is safe to optimize. Am I wrong?

If stdc++ lib contains code like:

ostream &operator<<(ostream &os, char x)
{ os.__escape = &x; }

That's probably wrong and should be fixed.

Tried to override with:

ostream &operator<<(ostream &os, char x)
{ cout.put(x); return os; } // works on all 4.5.4, 4.7.3 and 4.8.2

ostream &operator<<(ostream &os, char x)
{ cout.write(&x, 1); return os; } // fails even without "bar" for 4.7.3 and
4.8.2

Note that strange behaviour of 4.7.3. Is that means that adding "bar" fires
inlining?..


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

* [Bug c++/59813] tail-call elimintation didn't fired with left-shift of char to cout
  2014-01-14 21:35 [Bug c++/59813] New: tail-call elimintation didn't fired with left-shift of char to cout virkony at gmail dot com
                   ` (2 preceding siblings ...)
  2014-01-15  7:18 ` virkony at gmail dot com
@ 2014-01-15  7:23 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-15  7:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If you only care about tail recursion and not tail call optimization, perhaps,
but either solution would be very dumb.  We now have var ={v} {CLOBBER}; stmts,
even if those vars escape and are address taken, if there is a clobber stmt for
those vars on every path from the escape point to the tail call candidate, we
could perform tail recursion or tail call optimization, what we are really
after is that the address of no automatic variable from the current function
can escape to the tail recursion/call candidate.
As in:
void bar (char *);
void
foo (char *p)
{
  char c;
  bar (&c);
  bar (NULL); // We can't tail call optimize this
}

void
baz (char *p)
{
  {
    char c;
    bar (&c);
  }
  bar (NULL); // We could tail call optimize this
}


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

end of thread, other threads:[~2014-01-15  7:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-14 21:35 [Bug c++/59813] New: tail-call elimintation didn't fired with left-shift of char to cout virkony at gmail dot com
2014-01-14 22:05 ` [Bug c++/59813] " virkony at gmail dot com
2014-01-15  0:13 ` pinskia at gcc dot gnu.org
2014-01-15  7:18 ` virkony at gmail dot com
2014-01-15  7:23 ` 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).