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

            Bug ID: 60778
           Summary: shift not folded into shift on x86-64
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sunfish at mozilla dot com

On this C code:

double mem[4096];
double foo(long x) {
  return mem[x>>3];
}

GCC emits this x86-64 code:

        sarq    $3, %rdi
        movsd   mem(,%rdi,8), %xmm0

The following x86-64 code would be preferrable:

        andq    $-8, %rdi
        movsd   mem(%rdi), %xmm0

since it has smaller code size, and avoids using a scaled index which costs an
extra micro-op on some microarchitectures.

The same situation arrises on 32-bit x86 also.

This was observed on all GCC versions currently on the GCC Explorer website
[0], with the latest at this time being 4.9.0 20130909.

[0] http://gcc.godbolt.org/

Reply via email to