optimization/6585: useless memory store instructions on x86

Bruno Haible bruno@clisp.org
Wed Apr 23 12:54:00 GMT 2003

>     Bruno, I can verify your problem with 3.2, but I get
>     significantly better code with 3.2.2. Can you say a word
>     whether the new code satisfies you?

No, the new code is somewhat better, but still exhibits three problems:
- The dead store is still there.
- The prologue still saves and restores an unused register.
- The final reshuffling of registers before return is suboptimal.

=========================== mul.c ===============================
long long mul (long long a, long long b) {
  return a * b;

$ gcc -v
Reading specs from /packages/gnu-inst-gcc/3.2.2/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/specs
Configured with: ../configure --prefix=/packages/gnu-inst-gcc/3.2.2 --enable-shared --enable-version-specific-runtime-libs --enable-nls --enable-threads=posix --enable-__cxa_atexit
Thread model: posix
gcc version 3.2.2

$ gcc -O6 -fomit-frame-pointer -S mul.c
$ cat mul.s
        .file   "mul.c"
        .p2align 4,,15
.globl mul
        .type   mul,@function
        subl    $20, %esp
        movl    24(%esp), %eax		a0
        movl    %ebx, 8(%esp)				save %ebx
        movl    32(%esp), %ebx		b0
        movl    %esi, 12(%esp)				save %esi
        movl    36(%esp), %ecx		b1
        movl    %edi, 16(%esp)				save %edi USELESS!
        movl    16(%esp), %edi				restore %edi USELESS!
        mull    %ebx			%edx:%eax := a0*b0
        movl    %edx, %esi
        movl    %eax, (%esp)
        movl    24(%esp), %eax		a0
        movl    %edx, 4(%esp)				USELESS!
        imull   %ecx, %eax		a0*b1
        addl    %eax, %esi
        movl    28(%esp), %eax		a1
        imull   %eax, %ebx		a1*b0
        leal    (%ebx,%esi), %eax
        movl    12(%esp), %esi
        movl    8(%esp), %ebx
        movl    %eax, 4(%esp)		! Could be simplified to 2 instructions:
        movl    (%esp), %eax		! movl    %eax, %edx
        movl    4(%esp), %edx		! movl    (%esp), %eax
        addl    $20, %esp
        .size   mul,.Lfe1-mul
        .ident  "GCC: (GNU) 3.2.2"

More information about the Gcc-bugs mailing list