<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - missing optimization (alias analysis issue?)"
   href="https://llvm.org/bugs/show_bug.cgi?id=30638">30638</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>missing optimization (alias analysis issue?)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.9
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vanyacpp@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>