Gcc generates poor codes for this:

[...@gnu-6 tmp]$ cat x.i
typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
extern fpu_control_t __fpu_control;
struct rtld_global_ro
{
  fpu_control_t _dl_fpu_control;
};
extern const struct rtld_global_ro _rtld_global_ro;
extern void __setfpucw (fpu_control_t);
int __libc_multiple_libcs __attribute__ ((visibility ("hidden"))) = 1;
int __libc_argc __attribute__ ((visibility ("hidden")));
char **__libc_argv __attribute__ ((visibility ("hidden")));
extern char **__environ;
extern void __init_misc (int, char **, char **);
extern void __libc_global_ctors (void);
extern int _dl_starting_up;
#pragma weak _dl_starting_up
void
__attribute__ ((visibility ("hidden")))
_init (int argc, char **argv, char **envp)
{
  __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
  if (!__libc_multiple_libcs
      && __fpu_control != _rtld_global_ro._dl_fpu_control)
    __setfpucw (__fpu_control);
  __libc_argc = argc;
  __libc_argv = argv;
  __environ = envp;
  __init_misc (argc, argv, envp);
  __libc_global_ctors ();
}
[...@gnu-6 tmp]$ /usr/gcc-4.5/bin/gcc -m32   -march=i686 -fPIC  -O2 x.i -c
-fomit-frame-pointer
[...@gnu-6 tmp]$ objdump -dw x.o

x.o:     file format elf32-i386


Disassembly of section .text:

00000000 <_init>:
   0:   83 ec 2c                sub    $0x2c,%esp
   3:   89 5c 24 1c             mov    %ebx,0x1c(%esp)
   7:   e8 fc ff ff ff          call   8 <_init+0x8>
   c:   81 c3 02 00 00 00       add    $0x2,%ebx
  12:   89 74 24 20             mov    %esi,0x20(%esp)
  16:   8b 74 24 30             mov    0x30(%esp),%esi
  1a:   89 7c 24 24             mov    %edi,0x24(%esp)
  1e:   8b 7c 24 34             mov    0x34(%esp),%edi
  22:   89 6c 24 28             mov    %ebp,0x28(%esp)
  26:   8b 6c 24 38             mov    0x38(%esp),%ebp
  2a:   8b 83 00 00 00 00       mov    0x0(%ebx),%eax
  30:   85 c0                   test   %eax,%eax
  32:   74 54                   je     88 <_init+0x88>
  34:   8b 00                   mov    (%eax),%eax
  36:   85 c0                   test   %eax,%eax
  38:   75 4e                   jne    88 <_init+0x88>
  3a:   c7 83 00 00 00 00 01 00 00 00   movl   $0x1,0x0(%ebx)
  44:   8b 83 00 00 00 00       mov    0x0(%ebx),%eax
  4a:   89 b3 00 00 00 00       mov    %esi,0x0(%ebx)
  50:   89 bb 00 00 00 00       mov    %edi,0x0(%ebx)
  56:   89 28                   mov    %ebp,(%eax)
  58:   89 6c 24 08             mov    %ebp,0x8(%esp)
  5c:   89 7c 24 04             mov    %edi,0x4(%esp)
  60:   89 34 24                mov    %esi,(%esp)
  63:   e8 fc ff ff ff          call   64 <_init+0x64>
  68:   e8 fc ff ff ff          call   69 <_init+0x69>
  6d:   8b 5c 24 1c             mov    0x1c(%esp),%ebx
  71:   8b 74 24 20             mov    0x20(%esp),%esi
  75:   8b 7c 24 24             mov    0x24(%esp),%edi
  79:   8b 6c 24 28             mov    0x28(%esp),%ebp
  7d:   83 c4 2c                add    $0x2c,%esp
  80:   c3                      ret    
  81:   8d b4 26 00 00 00 00    lea    0x0(%esi,%eiz,1),%esi
  88:   8b 83 00 00 00 00       mov    0x0(%ebx),%eax
  8e:   8b 93 00 00 00 00       mov    0x0(%ebx),%edx
  94:   c7 83 00 00 00 00 00 00 00 00   movl   $0x0,0x0(%ebx)
  9e:   0f b7 00                movzwl (%eax),%eax
  a1:   66 39 02                cmp    %ax,(%edx)
  a4:   74 9e                   je     44 <_init+0x44>
  a6:   0f b7 c0                movzwl %ax,%eax
  a9:   89 04 24                mov    %eax,(%esp)
  ac:   e8 fc ff ff ff          call   ad <_init+0xad>
  b1:   eb 91                   jmp    44 <_init+0x44>

Why does gcc choose EBP over ECX/EDX?


-- 
           Summary: Poor register choice on x86
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hjl dot tools at gmail dot com


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

Reply via email to