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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to