[llvm] r320776 - FastISel: support no-PLT PIC calls on ELF x86_64

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 16:32:09 PST 2017


Author: compnerd
Date: Thu Dec 14 16:32:09 2017
New Revision: 320776

URL: http://llvm.org/viewvc/llvm-project?rev=320776&view=rev
Log:
FastISel: support no-PLT PIC calls on ELF x86_64

Add support for properly handling PIC code with no-PLT.  This equates to
`-fpic -fno-plt -O0` with the clang frontend.  External functions are
marked with nonlazybind, which must then be indirected through the GOT.
This allows code to be built without optimizations in PIC mode without
going through the PLT.  Addresses PR35653!

Added:
    llvm/trunk/test/CodeGen/X86/fast-isel-noplt-pic.ll
Modified:
    llvm/trunk/lib/Target/X86/X86FastISel.cpp

Modified: llvm/trunk/lib/Target/X86/X86FastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FastISel.cpp?rev=320776&r1=320775&r2=320776&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FastISel.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FastISel.cpp Thu Dec 14 16:32:09 2017
@@ -3458,13 +3458,11 @@ bool X86FastISel::fastLowerCall(CallLowe
     assert(GV && "Not a direct call");
     // See if we need any target-specific flags on the GV operand.
     unsigned char OpFlags = Subtarget->classifyGlobalFunctionReference(GV);
-    // Ignore NonLazyBind attribute in FastISel
-    if (OpFlags == X86II::MO_GOTPCREL)
-      OpFlags = 0;
 
     // This will be a direct call, or an indirect call through memory for
     // NonLazyBind calls or dllimport calls.
-    bool NeedLoad = OpFlags == X86II::MO_DLLIMPORT;
+    bool NeedLoad =
+        OpFlags == X86II::MO_DLLIMPORT || OpFlags == X86II::MO_GOTPCREL;
     unsigned CallOpc = NeedLoad
                            ? (Is64Bit ? X86::CALL64m : X86::CALL32m)
                            : (Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32);

Added: llvm/trunk/test/CodeGen/X86/fast-isel-noplt-pic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fast-isel-noplt-pic.ll?rev=320776&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fast-isel-noplt-pic.ll (added)
+++ llvm/trunk/test/CodeGen/X86/fast-isel-noplt-pic.ll Thu Dec 14 16:32:09 2017
@@ -0,0 +1,16 @@
+; RUN: llc -mtriple x86_64-unknown-linux-gnu -O0 -fast-isel=true -relocation-model=pic -filetype asm -o - %s | FileCheck %s
+
+declare void @f() local_unnamed_addr #0
+
+define void @g() local_unnamed_addr {
+entry:
+  call void @f()
+  ret void
+}
+
+attributes #0 = { nonlazybind }
+
+; CHECK-LABEL: g:
+; CHECK-LABEL: callq *f at GOTPCREL(%rip)
+; CHECK-LABEL: retq
+




More information about the llvm-commits mailing list