public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/20359] New: Incorrect code with global register variables
@ 2005-03-07 11:45 simonmar at microsoft dot com
  2005-03-07 15:02 ` [Bug rtl-optimization/20359] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: simonmar at microsoft dot com @ 2005-03-07 11:45 UTC (permalink / raw)
  To: gcc-bugs

Global register variables rear their ugly head again.  Here's a simple test case
that generates incorrect code on x86_64 with gcc 3.4.2:

$ cat bug.c
register void * R1 __asm__("%r13");

extern void g(void);
static void f(void) {
 R1 = g;
 goto *R1;
}
$ gcc -v  
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
$ gcc -O -S bug.c

The generated code for function f is:

f:
.LFB2:
        movl    $g, %eax
        jmp     *%rax

Note the assignment to the global register variable R1 has been lost.

This is breaking the Glasgow Haskell Compiler (http://www.haskell.org/ghc/) on
the x86_64 platform.  It might be related to the (closed) bug #7871.

-- 
           Summary: Incorrect code with global register variables
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: simonmar at microsoft dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: x86_64-*-linux
  GCC host triplet: x86_64-*-linux
GCC target triplet: x86_64-*-linux


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


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

* [Bug rtl-optimization/20359] Incorrect code with global register variables
  2005-03-07 11:45 [Bug c/20359] New: Incorrect code with global register variables simonmar at microsoft dot com
@ 2005-03-07 15:02 ` pinskia at gcc dot gnu dot org
  2005-03-07 15:05 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-07 15:02 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |rtl-optimization
           Keywords|                            |wrong-code


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


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

* [Bug rtl-optimization/20359] Incorrect code with global register variables
  2005-03-07 11:45 [Bug c/20359] New: Incorrect code with global register variables simonmar at microsoft dot com
  2005-03-07 15:02 ` [Bug rtl-optimization/20359] " pinskia at gcc dot gnu dot org
@ 2005-03-07 15:05 ` pinskia at gcc dot gnu dot org
  2005-03-07 15:11 ` simonmar at microsoft dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-07 15:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-07 15:05 -------
Looking at the version which you quoted, it is only 3.2.2:
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

and not 3.4.2, can you try again with 3.4.2 or later?

-- 


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


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

* [Bug rtl-optimization/20359] Incorrect code with global register variables
  2005-03-07 11:45 [Bug c/20359] New: Incorrect code with global register variables simonmar at microsoft dot com
  2005-03-07 15:02 ` [Bug rtl-optimization/20359] " pinskia at gcc dot gnu dot org
  2005-03-07 15:05 ` pinskia at gcc dot gnu dot org
@ 2005-03-07 15:11 ` simonmar at microsoft dot com
  2005-03-07 15:13 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: simonmar at microsoft dot com @ 2005-03-07 15:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From simonmar at microsoft dot com  2005-03-07 15:11 -------
Sorry, cut & pasted that gcc -v output from the wrong window.  The bug really 
does occur with 3.4.2, here's the correct -v output:

$ gcc -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-
checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-
exceptions --enable-languages=c,c++,objc,java,f77 --enable-java-awt=gtk --
host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)


-- 


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


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

* [Bug rtl-optimization/20359] Incorrect code with global register variables
  2005-03-07 11:45 [Bug c/20359] New: Incorrect code with global register variables simonmar at microsoft dot com
                   ` (2 preceding siblings ...)
  2005-03-07 15:11 ` simonmar at microsoft dot com
@ 2005-03-07 15:13 ` pinskia at gcc dot gnu dot org
  2005-03-07 17:28 ` [Bug rtl-optimization/20359] [3.3/3.4 regression] " belyshev at depni dot sinp dot msu dot ru
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-07 15:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-07 15:13 -------
Works on the mainline.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.0.0


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


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

* [Bug rtl-optimization/20359] [3.3/3.4 regression] Incorrect code with global register variables
  2005-03-07 11:45 [Bug c/20359] New: Incorrect code with global register variables simonmar at microsoft dot com
                   ` (3 preceding siblings ...)
  2005-03-07 15:13 ` pinskia at gcc dot gnu dot org
@ 2005-03-07 17:28 ` belyshev at depni dot sinp dot msu dot ru
  2005-03-08 14:01 ` jakub at gcc dot gnu dot org
  2005-05-19 17:40 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: belyshev at depni dot sinp dot msu dot ru @ 2005-03-07 17:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From belyshev at depni dot sinp dot msu dot ru  2005-03-07 17:28 -------
Confirmed.

-------------------------------------------------------------------------------
/* { dg-do run { targets i?86-*-* || x86_64-*-* || powerpc*-*-* } } */
/* { dg-options "-O1" } */

void abort (void);
void exit (int);

#if defined __x86_64__ || defined __powerpc__
register void (*r)(void) asm("%r13");
#elif defined __i386__
register void (*r)(void) asm("%esi");
#endif

void g ()
{
  if (r != g)
    abort ();
  else
    exit (0);
}

int main ()
{
  r = g;
  goto *r;
}
-------------------------------------------------------------------------------

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
  GCC build triplet|x86_64-*-linux              |
   GCC host triplet|x86_64-*-linux              |
 GCC target triplet|x86_64-*-linux              |
      Known to fail|                            |3.3.5 3.4.4
      Known to work|4.0.0                       |4.0.0 3.2.3
   Last reconfirmed|0000-00-00 00:00:00         |2005-03-07 17:28:46
               date|                            |
            Summary|Incorrect code with global  |[3.3/3.4 regression]
                   |register variables          |Incorrect code with global
                   |                            |register variables
   Target Milestone|---                         |3.4.4


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


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

* [Bug rtl-optimization/20359] [3.3/3.4 regression] Incorrect code with global register variables
  2005-03-07 11:45 [Bug c/20359] New: Incorrect code with global register variables simonmar at microsoft dot com
                   ` (4 preceding siblings ...)
  2005-03-07 17:28 ` [Bug rtl-optimization/20359] [3.3/3.4 regression] " belyshev at depni dot sinp dot msu dot ru
@ 2005-03-08 14:01 ` jakub at gcc dot gnu dot org
  2005-05-19 17:40 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-03-08 14:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jakub at gcc dot gnu dot org  2005-03-08 14:01 -------
Seems to be the combiner, that combines:
(insn 8 22 10 0 (set (reg/v:DI 42 r13 [ r ])
        (symbol_ref:DI ("g") [flags 0x3] <function_decl 0x2a97cde410 g>)) 84
{*movdi_1_rex64_nointerunit} (nil)
    (nil))

(insn 10 8 12 0 (set (reg:DI 59 [ r ])
        (reg/v:DI 42 r13 [ r ])) 84 {*movdi_1_rex64_nointerunit} (insn_list 8
(nil))
    (expr_list:REG_DEAD (reg/v:DI 42 r13 [ r ])
        (nil)))

into:

(insn 10 8 12 0 (set (reg:DI 59 [ r ])
        (symbol_ref:DI ("g") [flags 0x3] <function_decl 0x2a97cde410 g>)) 84
{*movdi_1_rex64_nointerunit} (nil)
    (nil))

without taking into account that there is a hard reg assignment.
This means it is not certain that the problem is not present in 4.0/4.1 as well,
just that combiner is not presented the same *.life RTLs and therefore makes
different decisions.
In 4.0, *.life looks like:
(insn 8 6 9 0 (set (reg/v:DI 42 r13 [ r ])
        (symbol_ref:DI ("g") [flags 0x3] <function_decl 0x2a97d09820 g>)) 81
{*movdi_1_rex64} (nil)
    (expr_list:REG_UNUSED (reg/v:DI 42 r13 [ r ])
        (nil)))

(insn 9 8 10 0 (set (reg/f:DI 59)
        (symbol_ref:DI ("g") [flags 0x3] <function_decl 0x2a97d09820 g>)) 81
{*movdi_1_rex64} (nil)
    (nil))


-- 


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


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

* [Bug rtl-optimization/20359] [3.3/3.4 regression] Incorrect code with global register variables
  2005-03-07 11:45 [Bug c/20359] New: Incorrect code with global register variables simonmar at microsoft dot com
                   ` (5 preceding siblings ...)
  2005-03-08 14:01 ` jakub at gcc dot gnu dot org
@ 2005-05-19 17:40 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-05-19 17:40 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.4.4                       |3.4.5


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


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

end of thread, other threads:[~2005-05-19 17:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-07 11:45 [Bug c/20359] New: Incorrect code with global register variables simonmar at microsoft dot com
2005-03-07 15:02 ` [Bug rtl-optimization/20359] " pinskia at gcc dot gnu dot org
2005-03-07 15:05 ` pinskia at gcc dot gnu dot org
2005-03-07 15:11 ` simonmar at microsoft dot com
2005-03-07 15:13 ` pinskia at gcc dot gnu dot org
2005-03-07 17:28 ` [Bug rtl-optimization/20359] [3.3/3.4 regression] " belyshev at depni dot sinp dot msu dot ru
2005-03-08 14:01 ` jakub at gcc dot gnu dot org
2005-05-19 17:40 ` mmitchel 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).