Hi,

the following input compiles OK with -O:

------------8<----------8<-------------8<-------------
# 1 "jidctint.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "jidctint.c"

volatile static unsigned long long fix_029_n089n196 = 0x098ea46e098ea46e;

__inline void domidct8x8llmW();

void
jpeg_idct_islow ()
{
  domidct8x8llmW();
}

__inline void domidct8x8llmW()
{

        __asm__ (
        "pmaddwd         fix_029_n089n196,%%mm7 \n\t"
        "emms                        \n\t"
 :
        );
}
------------8<----------8<-------------8<-------------

(/usr/local/bin/gcc -O1 -v -save-temps  -I.   -c -o jidctint.o jidctint.c
 Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/specs
 Configured with: /home/ltg/software/src/work/gcc-3.4.3/configure
 --enable-threads=posix --enable-libgcj --enable-shared --enable-__cxa_atexit
 --enable-version-specific-runtime-libs --enable-checking
 --enable-gather-detailed-mem-stats--disable-nls
 --enable-languages=c,c++,f77,objc,java --enable-libgcj-multifile --with-x
 --enable-java-awt=gtk,xlib
 Thread model: posix
 gcc version 3.4.3
  /usr/local/libexec/gcc/i686-pc-linux-gnu/3.4.3/cc1 -E -quiet -v -I. jidctint.c
 -mtune=pentiumpro -O1 -o jidctint.i
 ignoring nonexistent directory "NONE/include"
 ignoring nonexistent directory
"/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../i686-pc-linux-gnu/include"
 #include "..." search starts here:
 #include <...> search starts here:
  .
  /usr/local/include
  /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/include
  /usr/include
 End of search list.
  /usr/local/libexec/gcc/i686-pc-linux-gnu/3.4.3/cc1 -fpreprocessed jidctint.i
-quiet -dumpbase jidctint.c -mtune=pentiumpro -auxbase-strip jidctint.o -O1
-version -o jidctint.s
 GNU C version 3.4.3 (i686-pc-linux-gnu)
         compiled by GNU C version 3.4.3.
 GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
 jidctint.c:2: warning: integer constant is too large for "long" type
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../i686-pc-linux-gnu/bin/as
-V -Qy -o jidctint.o jidctint.s
 GNU assembler version 2.15 (i686-pc-linux-gnu) using BFD version 2.15)


For the above piece of code I get the following assembler code:

------------8<----------8<-------------8<-------------
        .file   "jidctint.c"
        .data
        .align 8
        .type   fix_029_n089n196, @object
        .size   fix_029_n089n196, 8
fix_029_n089n196:
        .quad   0x98ea46e098ea46e
        .text
.globl jpeg_idct_islow
        .type   jpeg_idct_islow, @function
jpeg_idct_islow:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        call    domidct8x8llmW
        leave
        ret
        .size   jpeg_idct_islow, .-jpeg_idct_islow
.globl domidct8x8llmW
        .type   domidct8x8llmW, @function
domidct8x8llmW:
        pushl   %ebp
        movl    %esp, %ebp
#APP
        pmaddwd         fix_029_n089n196,%mm7
        emms

#NO_APP
        popl    %ebp
        ret
        .size   domidct8x8llmW, .-domidct8x8llmW
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.3"
------------8<----------8<-------------8<-------------

When I compile the same piece of code with -O2 and above, I get:

------------8<----------8<-------------8<-------------
        .file   "jidctint.c"
        .text
        .p2align 4,,15
.globl domidct8x8llmW
        .type   domidct8x8llmW, @function
domidct8x8llmW:
        pushl   %ebp
        movl    %esp, %ebp
#APP
        pmaddwd         fix_029_n089n196,%mm7
        emms

#NO_APP
        popl    %ebp
        ret
        .size   domidct8x8llmW, .-domidct8x8llmW
        .p2align 4,,15
.globl jpeg_idct_islow
        .type   jpeg_idct_islow, @function
jpeg_idct_islow:
        pushl   %ebp
        movl    %esp, %ebp
#APP
        pmaddwd         fix_029_n089n196,%mm7
        emms

#NO_APP
        popl    %ebp
        ret
        .size   jpeg_idct_islow, .-jpeg_idct_islow
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.3"
------------8<----------8<-------------8<-------------

That means the optimizer eats

  fix_029_n089n196:
          .quad   0x98ea46e098ea46e
          .text

which causes an "undefined reference to 'fix_029_n089n196'" later
when linking the executable.

Can you check this?

Thanks.

Lothar

-- 
           Summary: gcc 3.4.3 optimizes volatile vars away (gcc 3.4.3 >= -
                    O2)
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ltg at zes dot uni-bremen dot de
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to