objc-arc: set nonlazybind attribute on objc_retain/
objc_release for performance for these most often
called APIs. // rdar://12040837


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161448 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index d5f3ecc..4ac172d 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -1696,9 +1696,13 @@
   // If the target runtime doesn't naturally support ARC, emit weak
   // references to the runtime support library.  We don't really
   // permit this to fail, but we need a particular relocation style.
-  if (!CGM.getLangOpts().ObjCRuntime.hasARC())
-    if (llvm::Function *f = dyn_cast<llvm::Function>(fn))
+  if (llvm::Function *f = dyn_cast<llvm::Function>(fn)) {
+    if (!CGM.getLangOpts().ObjCRuntime.hasARC())
       f->setLinkage(llvm::Function::ExternalWeakLinkage);
+    // set nonlazybind attribute for these APIs for performance.
+    if (fnName == "objc_retain" || fnName  == "objc_release")
+      f->addFnAttr(llvm::Attribute::NonLazyBind);
+  }
 
   return fn;
 }
diff --git a/test/CodeGenObjC/arc.m b/test/CodeGenObjC/arc.m
index 2a98b10..66a6a2f 100644
--- a/test/CodeGenObjC/arc.m
+++ b/test/CodeGenObjC/arc.m
@@ -9,6 +9,9 @@
   // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]]
   // CHECK-NEXT: call void @objc_release(i8* [[TMP]])
   // CHECK-NEXT: ret void
+// rdar://12040837
+  // CHECK: declare extern_weak i8* @objc_retain(i8*) nonlazybind
+  // CHECK: declare extern_weak void @objc_release(i8*) nonlazybind
 }
 
 // CHECK: define i8* @test1(i8*