https://bugs.llvm.org/show_bug.cgi?id=39657

            Bug ID: 39657
           Summary: suboptimal address calculation for aarch64
           Product: new-bugs
           Version: unspecified
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedb...@nondot.org
          Reporter: froy...@gmail.com
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org

This hackish code was extracted from some real code that was attempting to be
clever:

int f(char* p, long x)
{
  int i;
  __builtin_memcpy(&i, (int*)(p + (-x - 1)*4), sizeof(i));
  return i;
}

clang -O2 trunk generates, according to gcc.godbolt.org:

        lsl     x8, x1, #2
        eor     x8, x8, #0xfffffffffffffffc
        ldr     w0, [x0, x8]
        ret

whereas the preferred code would be (GCC 6.3.0, according to gcc.godbolt.org):

        mvn     x1, x1
        ldr     w0, [x0, x1, lsl 2]
        ret

where the shift has been folded into the load instruction.

The same phenomenon is visible on x86-64.  clang:

        shlq    $2, %rsi
        xorq    $-4, %rsi
        movl    (%rdi,%rsi), %eax
        retq

GCC:

        notq    %rsi
        movl    (%rdi,%rsi,4), %eax
        ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to