[llvm-bugs] [Bug 47690] New: missed optimization in pointer arithmetic

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 30 07:21:51 PDT 2020


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

            Bug ID: 47690
           Summary: missed optimization in pointer arithmetic
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: ian at ianhenderson.org
                CC: llvm-bugs at lists.llvm.org

godbolt.org link: https://godbolt.org/z/s3ojvE

the following two functions both compute x - a, but the second one isn't being
optimized properly.

functions:

unsigned a, *b;
unsigned f0(unsigned x) {
    return b + x - b - a;
}
unsigned f1(unsigned x) {
    return b + x - a - b;
}

compiled result at -Os:

f0:                                     # @f0
        mov     eax, edi
        sub     eax, dword ptr [rip + a]
        ret
f1:                                     # @f1
        mov     rcx, qword ptr [rip + b]
        mov     eax, edi
        xor     edx, edx
        sub     edx, dword ptr [rip + a]
        lea     rax, [rcx + 4*rax]
        lea     rax, [rax + 4*rdx]
        sub     rax, rcx
        shr     rax, 2
        ret
b:
        .quad   0
a:
        .long   0                               # 0x0

according to the versions on godbolt.org, this regressed between clang 3.6 and
3.7.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200930/fb1ade2f/attachment.html>


More information about the llvm-bugs mailing list