Re: G++ could optimize ASM code more

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 05/09/2012 07:29 AM, Daniel Marschall wrote:

> As I was optimizing my program, I found a few things which looked odd
> to me in the assembler code.
>
> I am on an AMD x64_32 box running Debian Squeeze, GCC: (Debian 4.4.5-8)
> 4.4.5.
>
> I am using "-O3 -mtune=native" for optimization.

>
> (2)
>
> Compiling following program:
>
> #include <stdio.h>
> #include <strings.h>
> int main(void) {
>          volatile unsigned char a = 4;
>          volatile unsigned char b = 6;
>          volatile unsigned long long int c = a * b;
>          return c;
> }
>
> produces:
>
>          .file   "main.c"
>          .text
>          .p2align 4,,15
> .globl main
>          .type   main, @function
> main:
> .LFB16:
>          .cfi_startproc
>          .cfi_personality 0x3,__gxx_personality_v0
>          movb    $4, -1(%rsp)
>          movb    $6, -2(%rsp)
>          movzbl  -1(%rsp), %edx
>          movzbl  -2(%rsp), %eax
>          movzbl  %dl, %edx
>          movzbl  %al, %eax
>          imull   %edx, %eax
>          cltq
>          movq    %rax, -16(%rsp)     # REDUNDANT??
>          movq    -16(%rsp), %rax     # REDUNDANT??
>          ret
>          .cfi_endproc
> .LFE16:
>          .size   main, .-main
>          .ident  "GCC: (Debian 4.4.5-8) 4.4.5"
>          .section        .note.GNU-stack,"",@progbits
>
> AFAIK, the two movq statements are redundant. What do they do? The just
> do rax=rsp[-16] and rsp[-16]=rax . Or am I wrong?

They are the expansion of

   c = ...
   return c;

The compiler must generate code for these expressions because c is
volatile.  The compiler is not allowed to elide any volatile ops.

Andrew.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux