[llvm-bugs] [Bug 30638] New: missing optimization (alias analysis issue?)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 7 10:39:15 PDT 2016


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

            Bug ID: 30638
           Summary: missing optimization (alias analysis issue?)
           Product: new-bugs
           Version: 3.9
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: vanyacpp at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

The following code:

#include <vector>
#include <memory>

struct base
{
    virtual ~base()
    {}
};

void f(std::vector<std::unique_ptr<base> >& v)
{
    v.back().release();
    v.pop_back();
}

GCC 6.2 is able to optimize to just two instructions:

        sub     QWORD PTR [rdi+8], 8
        ret

The code generated by clang 3.9.0 is less efficient:

        push    rbx
        mov     rax, qword ptr [rdi + 8]

        mov     qword ptr [rax - 8], 0

        mov     rax, qword ptr [rdi + 8]
        lea     rbx, [rax - 8]
        mov     qword ptr [rdi + 8], rbx

        mov     rdi, qword ptr [rax - 8]
        test    rdi, rdi
        je      .LBB0_2
        mov     rax, qword ptr [rdi]
        call    qword ptr [rax + 8]
.LBB0_2:
        mov     qword ptr [rbx], 0
        pop     rbx
        ret

As [rax - 8] is reloaded after subtraction I tend believe it is an alias
analysis issue.

-- 
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/20161007/7a9af9a0/attachment.html>


More information about the llvm-bugs mailing list