]> granicus.if.org Git - llvm/commitdiff
Don't add a tail keyword to calls to ObjC runtime functions if the calls
authorAkira Hatanaka <ahatanaka@apple.com>
Thu, 21 Mar 2019 20:16:09 +0000 (20:16 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Thu, 21 Mar 2019 20:16:09 +0000 (20:16 +0000)
are annotated with notail.

r356705 annotated calls to objc_retainAutoreleasedReturnValue with
notail on x86-64. This commit teaches ARC optimizer to check the notail
marker on the call before turning it into a tail call.

rdar://problem/38675807

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356707 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/ObjCARC/ObjCARCOpts.cpp
test/Transforms/ObjCARC/tail-call-invariant-enforcement.ll

index 9572674f7581af8417279b8db2e7d186729cbd0c..34de66f05fbe813292e82657ae4f9def2a1dd9bf 100644 (file)
@@ -848,7 +848,7 @@ void ObjCARCOpt::OptimizeIndividualCalls(Function &F) {
 
     // For functions which can never be passed stack arguments, add
     // a tail keyword.
-    if (IsAlwaysTail(Class)) {
+    if (IsAlwaysTail(Class) && !cast<CallInst>(Inst)->isNoTailCall()) {
       Changed = true;
       LLVM_DEBUG(
           dbgs() << "Adding tail keyword to function since it can never be "
index fcb28dd169cbb05da8c024e340b8097678c89ffa..b05a16d10c6d3031549f6fed62999467dea6b08c 100644 (file)
@@ -48,10 +48,12 @@ entry:
   ret i8* %x
 }
 
-; Always tail call objc_retainAutoreleasedReturnValue.
+; Always tail call objc_retainAutoreleasedReturnValue unless it's annotated with
+; notail.
 ; CHECK: define i8* @test3(i8* %x) [[NUW]] {
 ; CHECK: %tmp0 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %y) [[NUW]]
 ; CHECK: %tmp1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z) [[NUW]]
+; CHECK: %tmp2 = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z2) [[NUW]]
 ; CHECK: }
 define i8* @test3(i8* %x) nounwind {
 entry:
@@ -59,6 +61,8 @@ entry:
   %tmp0 = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %y)
   %z = call i8* @tmp(i8* %x)
   %tmp1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z)
+  %z2 = call i8* @tmp(i8* %x)
+  %tmp2 = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %z2)
   ret i8* %x
 }