[llvm-bugs] [Bug 28554] New: LLD fails to devirtualize the code that Gold plugin does

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 14 12:20:01 PDT 2016


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

            Bug ID: 28554
           Summary: LLD fails to devirtualize the code that Gold plugin
                    does
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: krasin at google.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 16742
  --> https://llvm.org/bugs/attachment.cgi?id=16742&action=edit
devirt.cc

Consider the attached program, devirt.cc. With Gold and LLVM Gold plugin we
get:

$ clang++ -O2 -fuse-ld=gold -o lala -fvisibility=hidden devirt.cc -std=c++11
-flto -fwhole-program-vtables  -Wl,-plugin-opt,-pass-remarks=wholeprogramdevirt
-Wl,-plugin-opt,O1 -Wl,-plugin-opt,-function-sections
-Wl,-plugin-opt,save-temps
LLVM gold plugin: <unknown>:0:0: devirtualized call
LLVM gold plugin: <unknown>:0:0: devirtualized call
LLVM gold plugin: <unknown>:0:0: devirtualized call
$

In the bitcode (lala.opt.bc) we see the call was devirtualized:
  %vfn = getelementptr inbounds i1 (%class.Base*, i32)*, i1 (%class.Base*,
i32)** %vtable, i64 2
  %10 = load i1 (%class.Base*, i32)*, i1 (%class.Base*, i32)** %vfn, align 8
  %11 = icmp ne i8* %9, getelementptr (i8, i8* bitcast ([6 x i8*]* @_ZTV1A to
i8*), i64 16)
  %conv = zext i1 %11 to i32
  %call19 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x
i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %conv)

If we link with lld, nothing happens:
$ clang++ -fuse-ld=lld -o lala devirt.cc -std=c++11 -flto -fvisibility=hidden
-fwhole-program-vtables  -Wl,-mllvm,-pass-remarks=wholeprogramdevirt
-Wl,--lto-O1  -Wl,-save-temps  
$

And the bitcode shows that we still have a virtual call:

  %vfn = getelementptr inbounds i1 (%class.Base*, i32)*, i1 (%class.Base*,
i32)** %vtable, i64 2
  %19 = load i1 (%class.Base*, i32)*, i1 (%class.Base*, i32)** %vfn, align 8
  %call17 = invoke zeroext i1 %19(%class.Base* %call15, i32 1)
          to label %invoke.cont16 unwind label %lpad

invoke.cont16:                                    ; preds = %sw.epilog
  %conv = zext i1 %call17 to i32
  %call19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8],
[4 x i8]* @.str.1, i32 0, i32 0), i32 %conv)

This prevents lld from being deployed in Chromium as the default linker on
Linux.

-- 
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/20160714/faefc727/attachment.html>


More information about the llvm-bugs mailing list