[ObjC][ARC] Fix a bug where the inline-asm retain/claim RV marker wasn't
authorAkira Hatanaka <ahatanaka@apple.com>
Sat, 19 Dec 2020 00:59:06 +0000 (16:59 -0800)
committerAkira Hatanaka <ahatanaka@apple.com>
Sat, 19 Dec 2020 00:59:06 +0000 (16:59 -0800)
inserted when the original call had a 'returned' argument

The code is testing whether the instruction BBI points to is the call
that is paired up with the retainRV/claimRV call, but it doesn't work
when the call has a 'returned' argument since GetArgRCIdentityRoot looks
through 'returned' arguments.

rdar://72485383

llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/test/Transforms/ObjCARC/contract-marker.ll

index e190c46..c2499fc 100644 (file)
@@ -476,7 +476,7 @@ bool ObjCARCContract::tryToPeepholeInstruction(
       --BBI;
     } while (IsNoopInstruction(&*BBI));
 
-    if (&*BBI == GetArgRCIdentityRoot(Inst)) {
+    if (GetRCIdentityRoot(&*BBI) == GetArgRCIdentityRoot(Inst)) {
       LLVM_DEBUG(dbgs() << "Adding inline asm marker for the return value "
                            "optimization.\n");
       Changed = true;
index a93bbe3..e221706 100644 (file)
@@ -32,11 +32,31 @@ entry:
   ret void
 }
 
+; CHECK-LABEL: define i8* @foo3(
+; CHECK: call i8* @returnsArg(
+; CHECK-NEXT: call void asm sideeffect
+
+define i8* @foo3(i8* %a) {
+  %call = call i8* @returnsArg(i8* %a)
+  call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %call)
+  ret i8* %call
+}
+
+; CHECK-LABEL: define i8* @foo4(
+; CHECK: call i8* @returnsArg(
+; CHECK-NEXT: call void asm sideeffect
+
+define i8* @foo4(i8* %a) {
+  %call = call i8* @returnsArg(i8* %a)
+  call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %a)
+  ret i8* %call
+}
 
 declare i32* @qux()
 declare i8* @llvm.objc.retainAutoreleasedReturnValue(i8*)
 declare i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8*)
 declare void @bar(i8*)
+declare i8* @returnsArg(i8* returned)
 
 !llvm.module.flags = !{!0}