[llvm] r329765 - GOTPCREL references must always use RIP.

Sriraman Tallam via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 10 15:50:05 PDT 2018


Author: tmsriram
Date: Tue Apr 10 15:50:05 2018
New Revision: 329765

URL: http://llvm.org/viewvc/llvm-project?rev=329765&view=rev
Log:
GOTPCREL references must always use RIP.

With -fno-plt, global value references can use GOTPCREL and RIP must be used.

Differential Revision: https://reviews.llvm.org/D45460

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/lib/Target/X86/X86ISelLowering.h
    llvm/trunk/test/CodeGen/X86/no-plt.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=329765&r1=329764&r2=329765&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue Apr 10 15:50:05 2018
@@ -15502,7 +15502,8 @@ static SDValue LowerEXTRACT_SUBVECTOR(SD
 }
 
 // Returns the appropriate wrapper opcode for a global reference.
-unsigned X86TargetLowering::getGlobalWrapperKind(const GlobalValue *GV) const {
+unsigned X86TargetLowering::getGlobalWrapperKind(
+    const GlobalValue *GV, const unsigned char OpFlags) const {
   // References to absolute symbols are never PC-relative.
   if (GV && GV->isAbsoluteSymbolRef())
     return X86ISD::Wrapper;
@@ -15512,6 +15513,10 @@ unsigned X86TargetLowering::getGlobalWra
       (M == CodeModel::Small || M == CodeModel::Kernel))
     return X86ISD::WrapperRIP;
 
+  // GOTPCREL references must always use RIP.
+  if (OpFlags == X86II::MO_GOTPCREL)
+    return X86ISD::WrapperRIP;
+
   return X86ISD::Wrapper;
 }
 
@@ -15635,7 +15640,7 @@ SDValue X86TargetLowering::LowerGlobalAd
     Result = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, OpFlags);
   }
 
-  Result = DAG.getNode(getGlobalWrapperKind(GV), dl, PtrVT, Result);
+  Result = DAG.getNode(getGlobalWrapperKind(GV, OpFlags), dl, PtrVT, Result);
 
   // With PIC, the address is actually $g + Offset.
   if (isGlobalRelativeToPICBase(OpFlags)) {

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.h?rev=329765&r1=329764&r2=329765&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.h (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.h Tue Apr 10 15:50:05 2018
@@ -1199,7 +1199,8 @@ namespace llvm {
     SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
     SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
 
-    unsigned getGlobalWrapperKind(const GlobalValue *GV = nullptr) const;
+    unsigned getGlobalWrapperKind(const GlobalValue *GV = nullptr,
+                                  const unsigned char OpFlags = 0) const;
     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
     SDValue LowerGlobalAddress(const GlobalValue *GV, const SDLoc &dl,

Modified: llvm/trunk/test/CodeGen/X86/no-plt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/no-plt.ll?rev=329765&r1=329764&r2=329765&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/no-plt.ll (original)
+++ llvm/trunk/test/CodeGen/X86/no-plt.ll Tue Apr 10 15:50:05 2018
@@ -3,6 +3,12 @@
 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu \
 ; RUN:   | FileCheck -check-prefix=X64 --check-prefix=STATIC %s
 
+define i32 @fp_weakfunc() {
+; X64: weakfunc at GOTPCREL(%rip)
+  ret i32 select (i1 icmp ne (i32 ()* @weakfunc, i32 ()* null), i32 1, i32 0)
+}
+declare extern_weak i32 @weakfunc() nonlazybind
+
 define void @memset_call(i8* nocapture %a, i8 %c, i32 %n) {
 ; X64: callq *memset at GOTPCREL(%rip)
   call void @llvm.memset.p0i8.i32(i8* %a, i8 %c, i32 %n, i1 false)




More information about the llvm-commits mailing list