<html>
    <head>
      <base href="http://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 --- - Devirtualization fails for loop, while succeeds for a scalar call of the same method"
   href="http://llvm.org/bugs/show_bug.cgi?id=20801">20801</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Devirtualization fails for loop, while succeeds for a scalar call of the same method
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>zinovy.nis@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre><span class="quote">> clang++ -v</span >

clang version 3.6.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

<span class="quote">> cat test.cpp</span >

class A { public: virtual int f() { return 123;} };
int Scalar() { A* a = new A; return a->f(); }
int Vector(int N) { A* a = new A; int sum = 0; for(int i = 0; i < N; ++i) sum
+= a->f(); return sum; }
int main(int argc, char** argv) { return Scalar() + Vector(argc); }

<span class="quote">> clang++ -march=core-avx2 -Ofast test.cpp -S -o - | c++filt | less</span >

...
Scalar():
        movl    $123, %eax # <<<----- devirtualized!
        retq

Vector(int):
        pushq   %rbp
        pushq   %r14
        pushq   %rbx
        movl    %edi, %ebx
        movl    $8, %edi
        callq   operator new(unsigned long)  # <<<<----- it's new is not needed
        movq    %rax, %r14
        movq    vtable for A+16, (%r14)
        xorl    %eax, %eax
        testl   %ebx, %ebx
        jle     .LBB1_4
# BB#1:                                 # %for.body.lr.ph
        xorl    %eax, %eax
        movl    vtable for A+16, %ecx
        jmp     .LBB1_2
        .align  16, 0x90
.LBB1_3:                                # %for.body.for.body_crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
        movq    (%r14), %rcx
.LBB1_2:                                # %for.body
                                        # =>This Inner Loop Header: Depth=1
        movl    %eax, %ebp
        movq    %r14, %rdi
        callq   *(%rcx)    # <<<<<----- virtual call!
        addl    %ebp, %eax
        decl    %ebx
        jne     .LBB1_3
.LBB1_4:                                # %for.end
        popq    %rbx
        popq    %r14
        popq    %rbp
        retq</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>