AArch64: be more careful resorting to inefficient addressing for weak vars.
[oota-llvm.git] / lib / Target / AArch64 / AArch64ISelLowering.cpp
index fa9dcbfc21f9b3f52b2b1b8a20bdda31794bbdd8..34cc0e3b3b84385f2e565e254a9fb1905fa445a1 100644 (file)
@@ -1852,11 +1852,10 @@ AArch64TargetLowering::LowerGlobalAddressELF(SDValue Op,
   const GlobalValue *GV = GN->getGlobal();
   unsigned Alignment = GV->getAlignment();
   Reloc::Model RelocM = getTargetMachine().getRelocationModel();
-
-  if (GV->isWeakForLinker() && RelocM == Reloc::Static) {
-    // Weak symbols can't use ADRP/ADD pair since they should evaluate to
-    // zero when undefined. In PIC mode the GOT can take care of this, but in
-    // absolute mode we use a constant pool load.
+  if (GV->isWeakForLinker() && GV->isDeclaration() && RelocM == Reloc::Static) {
+    // Weak undefined symbols can't use ADRP/ADD pair since they should evaluate
+    // to zero when they remain undefined. In PIC mode the GOT can take care of
+    // this, but in absolute mode we use a constant pool load.
     SDValue PoolAddr;
     PoolAddr = DAG.getNode(AArch64ISD::WrapperSmall, dl, PtrVT,
                            DAG.getTargetConstantPool(GV, PtrVT, 0, 0,