public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21964] New: broken tail call at -O2 or more
@ 2005-06-08 17:11 ben at 0x539 dot de
  2005-06-08 18:05 ` [Bug middle-end/21964] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: ben at 0x539 dot de @ 2005-06-08 17:11 UTC (permalink / raw)
  To: gcc-bugs

Optimisations seem to cause the post increment in the recursive function call to
foo() to pass the increased value to the function.

Expected output, and output when compiled without -O2:
0
0
0
0
...

Actual output with -O2 or -O3 or...:
0
1
2
3
...

#include <stdio.h>
 
void foo(int n);
 
int main(void) {
    foo(0);
 
    return 0;
}
 
void foo(int n) {
    printf("%d\n", n);
    foo(n++);
}

-- 
           Summary: broken tail call at -O2 or more
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ben at 0x539 dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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


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

* [Bug middle-end/21964] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
@ 2005-06-08 18:05 ` pinskia at gcc dot gnu dot org
  2005-06-08 18:13 ` [Bug middle-end/21964] [3.4 Regression] " pinskia at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-08 18:05 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Keywords|                            |wrong-code


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
  2005-06-08 18:05 ` [Bug middle-end/21964] " pinskia at gcc dot gnu dot org
@ 2005-06-08 18:13 ` pinskia at gcc dot gnu dot org
  2005-06-09  9:20 ` steven at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-08 18:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-08 18:13 -------
Confirmed, only a regression in 3.4.x.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|                            |3.0.4 3.4.0
      Known to work|                            |4.0.0 4.1.0 2.95.3
   Last reconfirmed|0000-00-00 00:00:00         |2005-06-08 18:13:50
               date|                            |
            Summary|broken tail call at -O2 or  |[3.4 Regression] broken tail
                   |more                        |call at -O2 or more
   Target Milestone|---                         |3.4.5


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
  2005-06-08 18:05 ` [Bug middle-end/21964] " pinskia at gcc dot gnu dot org
  2005-06-08 18:13 ` [Bug middle-end/21964] [3.4 Regression] " pinskia at gcc dot gnu dot org
@ 2005-06-09  9:20 ` steven at gcc dot gnu dot org
  2005-06-09  9:22 ` steven at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-06-09  9:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-06-09 09:20 -------
Here is the initial RTL for the call to foo: 
 
(call_insn 44 20 45 (call_placeholder 40 31 22 27 (cond [ 
  (const_string "normal") (sequence [ 
    (insn 40 0 39 (set (reg:SI 63) 
                (reg/v:SI 58 [ n ])) -1 (nil) 
            (nil)) 
    (insn 39 40 41 (parallel [ 
                    (set (reg/v:SI 58 [ n ]) 
                        (plus:SI (reg/v:SI 58 [ n ]) 
                            (const_int 1 [0x1]))) 
                    (clobber (reg:CC 17 flags)) 
                ]) -1 (nil) 
            (nil)) 
    (insn 41 39 42 (set (reg:SI 62) 
                (reg:SI 63)) -1 (nil) 
            (nil)) 
    (insn 42 41 43 (set (reg:SI 5 di) 
                (reg:SI 62)) -1 (nil) 
            (nil)) 
    (call_insn 43 42 0 (call (mem:QI (symbol_ref:DI ("foo") [flags 0x3] 
<function_decl 0x2a9592b9c0 foo>) [0 S1 A8]) 
                (const_int 0 [0x0])) -1 (nil) 
            (nil) 
            (expr_list (use (reg:SI 5 di)) 
                (nil))) 
    ]) 
  (const_string "tail_call") (sequence [ 
    (note 31 0 32 NOTE_INSN_DELETED) 
    (note 32 31 34 NOTE_INSN_DELETED) 
    (insn 34 32 33 (set (reg:SI 61) 
                (reg/v:SI 58 [ n ])) -1 (nil) 
            (nil)) 
    (insn 33 34 35 (parallel [ 
                    (set (reg/v:SI 58 [ n ]) 
                        (plus:SI (reg/v:SI 58 [ n ]) 
                            (const_int 1 [0x1]))) 
                    (clobber (reg:CC 17 flags)) 
                ]) -1 (nil) 
            (nil)) 
    (insn 35 33 36 (set (reg:SI 60) 
                (reg:SI 61)) -1 (nil) 
            (nil)) 
    (insn 36 35 37 (set (reg:SI 5 di) 
                (reg:SI 60)) -1 (nil) 
            (nil)) 
    (call_insn/j 37 36 38 (call (mem:QI (symbol_ref:DI ("foo") [flags 0x3] 
<function_decl 0x2a9592b9c0 foo>) [0 S1 A8]) 
                (const_int 0 [0x0])) -1 (nil) 
            (nil) 
            (expr_list (use (reg:SI 5 di)) 
                (nil))) 
    (barrier 38 37 0) 
    ]) 
  (const_string "tail_recursion") (sequence [ 
    (note 22 0 23 NOTE_INSN_DELETED) 
    (note 23 22 25 NOTE_INSN_DELETED) 
    (insn 25 23 26 (set (reg:SI 59) 
                (reg/v:SI 58 [ n ])) -1 (nil) 
            (nil)) 
    (insn 26 25 24 (set (reg/v:SI 58 [ n ]) 
                (reg:SI 59)) -1 (nil) 
            (nil)) 
    (insn 24 26 28 (parallel [ 
                    (set (reg/v:SI 58 [ n ]) 
                        (plus:SI (reg/v:SI 58 [ n ]) 
                            (const_int 1 [0x1]))) 
                    (clobber (reg:CC 17 flags)) 
                ]) -1 (nil) 
            (nil)) 
    (jump_insn 28 24 29 (set (pc) 
                (label_ref 27)) -1 (nil) 
            (nil)) 
    (barrier 29 28 30) 
    (barrier 30 29 0) 
    ]) 
  ])) -1 (nil) 
    (nil) 
    (nil)) 
 
 
You have to set debug_call_placeholder_verbose = 1 in print-rtl.c to 
see what is going on. 

-- 


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (2 preceding siblings ...)
  2005-06-09  9:20 ` steven at gcc dot gnu dot org
@ 2005-06-09  9:22 ` steven at gcc dot gnu dot org
  2005-06-09 10:33 ` giovannibajo at libero dot it
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-06-09  9:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-06-09 09:22 -------
In this case we obviously take the "tail_recursion" sequence, which is 
already wrong: 
 
  (const_string "tail_recursion") (sequence [ 
    (note 22 0 23 NOTE_INSN_DELETED) 
    (note 23 22 25 NOTE_INSN_DELETED) 
    (insn 25 23 26 (set (reg:SI 59) 
                (reg/v:SI 58 [ n ])) -1 (nil) 
            (nil)) 
    (insn 26 25 24 (set (reg/v:SI 58 [ n ]) 
                (reg:SI 59)) -1 (nil) 
            (nil)) 
    (insn 24 26 28 (parallel [ 
                    (set (reg/v:SI 58 [ n ]) 
                        (plus:SI (reg/v:SI 58 [ n ]) 
                            (const_int 1 [0x1]))) 
                    (clobber (reg:CC 17 flags)) 
                ]) -1 (nil) 
            (nil)) 
    (jump_insn 28 24 29 (set (pc) 
                (label_ref 27)) -1 (nil) 
            (nil)) 
    (barrier 29 28 30) 
    (barrier 30 29 0) 
    ]) 
 
Note that the "n++" (insn 24) is before the jump to the tail recursion 
label at the head of the function (jump_insn 28). 
 
So the initial RTL generation is wrong. 
 
 

-- 


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (3 preceding siblings ...)
  2005-06-09  9:22 ` steven at gcc dot gnu dot org
@ 2005-06-09 10:33 ` giovannibajo at libero dot it
  2005-06-09 11:25 ` steven at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: giovannibajo at libero dot it @ 2005-06-09 10:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-06-09 10:33 -------
can you binsearch this on the 3.4 branch?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |janis at gcc dot gnu dot org


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (4 preceding siblings ...)
  2005-06-09 10:33 ` giovannibajo at libero dot it
@ 2005-06-09 11:25 ` steven at gcc dot gnu dot org
  2005-06-09 11:52 ` giovannibajo at libero dot it
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-06-09 11:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-06-09 11:25 -------
Why would you want to binsearch this?  GCC 3.0.4 was already broken,
according to the "Known to fail" list, while 2.95.3 is "Known to work".
And because the sibcall pass was new in GCC 3.0, the odds are that
this was broken from the beginning.


-- 


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (5 preceding siblings ...)
  2005-06-09 11:25 ` steven at gcc dot gnu dot org
@ 2005-06-09 11:52 ` giovannibajo at libero dot it
  2005-08-01  8:55 ` rsandifo at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: giovannibajo at libero dot it @ 2005-06-09 11:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-06-09 11:52 -------
Ah sorry, for some reason I misread the bug and believed it worked in 3.3.

-- 


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (6 preceding siblings ...)
  2005-06-09 11:52 ` giovannibajo at libero dot it
@ 2005-08-01  8:55 ` rsandifo at gcc dot gnu dot org
  2005-08-08  7:45 ` cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rsandifo at gcc dot gnu dot org @ 2005-08-01  8:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rsandifo at gcc dot gnu dot org  2005-08-01 08:55 -------
Testing a patch

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rsandifo at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-06-08 18:13:50         |2005-08-01 08:55:27
               date|                            |


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (7 preceding siblings ...)
  2005-08-01  8:55 ` rsandifo at gcc dot gnu dot org
@ 2005-08-08  7:45 ` cvs-commit at gcc dot gnu dot org
  2005-08-08  7:46 ` cvs-commit at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-08-08  7:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-08-08 07:45 -------
Subject: Bug 21964

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rsandifo@gcc.gnu.org	2005-08-08 07:45:22

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr21964-1.c 

Log message:
	PR middle-end/21964
	* gcc.c-torture/execute/pr21964-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5891&r2=1.5892
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr21964-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (8 preceding siblings ...)
  2005-08-08  7:45 ` cvs-commit at gcc dot gnu dot org
@ 2005-08-08  7:46 ` cvs-commit at gcc dot gnu dot org
  2005-08-08  7:49 ` cvs-commit at gcc dot gnu dot org
  2005-08-08  7:50 ` rsandifo at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-08-08  7:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-08-08 07:46 -------
Subject: Bug 21964

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	rsandifo@gcc.gnu.org	2005-08-08 07:46:18

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr21964-1.c 

Log message:
	PR middle-end/21964
	* gcc.c-torture/execute/pr21964-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.321&r2=1.5084.2.322
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr21964-1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1



-- 


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (9 preceding siblings ...)
  2005-08-08  7:46 ` cvs-commit at gcc dot gnu dot org
@ 2005-08-08  7:49 ` cvs-commit at gcc dot gnu dot org
  2005-08-08  7:50 ` rsandifo at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-08-08  7:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-08-08 07:49 -------
Subject: Bug 21964

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	rsandifo@gcc.gnu.org	2005-08-08 07:49:09

Modified files:
	gcc            : ChangeLog stmt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr21964-1.c 

Log message:
	PR middle-end/21964
	* stmt.c (tail_recursion_args): Insert a call to emit_queue.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.904&r2=2.2326.2.905
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.342.2.3&r2=1.342.2.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.419&r2=1.3389.2.420
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr21964-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1



-- 


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


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

* [Bug middle-end/21964] [3.4 Regression] broken tail call at -O2 or more
  2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
                   ` (10 preceding siblings ...)
  2005-08-08  7:49 ` cvs-commit at gcc dot gnu dot org
@ 2005-08-08  7:50 ` rsandifo at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: rsandifo at gcc dot gnu dot org @ 2005-08-08  7:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rsandifo at gcc dot gnu dot org  2005-08-08 07:50 -------
Patch applied to 3.4.  Testcase also applied to mainline and 4.0.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2005-08-08  7:50 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-08 17:11 [Bug c/21964] New: broken tail call at -O2 or more ben at 0x539 dot de
2005-06-08 18:05 ` [Bug middle-end/21964] " pinskia at gcc dot gnu dot org
2005-06-08 18:13 ` [Bug middle-end/21964] [3.4 Regression] " pinskia at gcc dot gnu dot org
2005-06-09  9:20 ` steven at gcc dot gnu dot org
2005-06-09  9:22 ` steven at gcc dot gnu dot org
2005-06-09 10:33 ` giovannibajo at libero dot it
2005-06-09 11:25 ` steven at gcc dot gnu dot org
2005-06-09 11:52 ` giovannibajo at libero dot it
2005-08-01  8:55 ` rsandifo at gcc dot gnu dot org
2005-08-08  7:45 ` cvs-commit at gcc dot gnu dot org
2005-08-08  7:46 ` cvs-commit at gcc dot gnu dot org
2005-08-08  7:49 ` cvs-commit at gcc dot gnu dot org
2005-08-08  7:50 ` rsandifo at gcc dot gnu dot 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).