[LLVMbugs] [Bug 20801] New: Devirtualization fails for loop, while succeeds for a scalar call of the same method

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Aug 29 07:28:07 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20801

            Bug ID: 20801
           Summary: Devirtualization fails for loop, while succeeds for a
                    scalar call of the same method
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: zinovy.nis at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

> clang++ -v

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

> cat test.cpp

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); }

> clang++ -march=core-avx2 -Ofast test.cpp -S -o - | c++filt | less

...
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

-- 
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/20140829/6be968ad/attachment.html>


More information about the llvm-bugs mailing list