[llvm] 68f39de - [NFC][ObjC][ARC] Add tests for OptimizeRetainRVCall

Francis Visoiu Mistrih via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 07:29:24 PST 2019


Author: Francis Visoiu Mistrih
Date: 2019-11-05T06:39:22-08:00
New Revision: 68f39de042ef34ef17d93c18e80d42f2e1a970ab

URL: https://github.com/llvm/llvm-project/commit/68f39de042ef34ef17d93c18e80d42f2e1a970ab
DIFF: https://github.com/llvm/llvm-project/commit/68f39de042ef34ef17d93c18e80d42f2e1a970ab.diff

LOG: [NFC][ObjC][ARC] Add tests for OptimizeRetainRVCall

Add tests for bitcasts + zero GEPs, and pre-commit tests for lifetime
markers.

Added: 
    

Modified: 
    llvm/test/Transforms/ObjCARC/post-inlining.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/ObjCARC/post-inlining.ll b/llvm/test/Transforms/ObjCARC/post-inlining.ll
index 0304d59c8b99..65b1153c1367 100644
--- a/llvm/test/Transforms/ObjCARC/post-inlining.ll
+++ b/llvm/test/Transforms/ObjCARC/post-inlining.ll
@@ -46,3 +46,71 @@ entry:
   call void @use_pointer(i8* %p)
   ret void
 }
+
+; Check that we can delete the autoreleaseRV+retainAutoreleasedRV pair even in
+; presence of instructions added by the inliner as part of the return sequence.
+
+; 1) Noop instructions: bitcasts and zero-indices GEPs.
+
+; CHECK-LABEL: define i8* @testNoop(
+; CHECK: entry:
+; CHECK-NEXT: %noop0 = bitcast i8* %call.i to i64*
+; CHECK-NEXT: %noop1 = getelementptr i8, i8* %call.i, i32 0
+; CHECK-NEXT: ret i8* %call.i
+; CHECK-NEXT: }
+define i8* @testNoop(i8* %call.i) {
+entry:
+  %0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call.i) nounwind
+  %noop0 = bitcast i8* %call.i to i64*
+  %noop1 = getelementptr i8, i8* %call.i, i32 0
+  %1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %call.i) nounwind
+  ret i8* %call.i
+}
+
+; 2) Lifetime markers.
+
+declare void @llvm.lifetime.start.p0i8(i64, i8*)
+declare void @llvm.lifetime.end.p0i8(i64, i8*)
+
+; CHECK-LABEL: define i8* @testLifetime(
+; CHECK: entry:
+; CHECK-NEXT: %obj = alloca i8
+; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* %obj)
+; CHECK-NEXT: %0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call.i)
+; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 8, i8* %obj)
+; CHECK-NEXT: %1 = tail call i8* @llvm.objc.retain(i8* %call.i)
+; CHECK-NEXT: ret i8* %call.i
+; CHECK-NEXT: }
+define i8* @testLifetime(i8* %call.i) {
+entry:
+  %obj = alloca i8
+  call void @llvm.lifetime.start.p0i8(i64 8, i8* %obj)
+  %0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call.i) nounwind
+  call void @llvm.lifetime.end.p0i8(i64 8, i8* %obj)
+  %1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %call.i) nounwind
+  ret i8* %call.i
+}
+
+; 3) Dynamic alloca markers.
+
+declare i8* @llvm.stacksave()
+declare void @llvm.stackrestore(i8*)
+
+; CHECK-LABEL: define i8* @testStack(
+; CHECK: entry:
+; CHECK-NEXT: %save = tail call i8* @llvm.stacksave()
+; CHECK-NEXT: %obj = alloca i8, i8 %arg
+; CHECK-NEXT: %0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call.i)
+; CHECK-NEXT: call void @llvm.stackrestore(i8* %save)
+; CHECK-NEXT: %1 = tail call i8* @llvm.objc.retain(i8* %call.i)
+; CHECK-NEXT: ret i8* %call.i
+; CHECK-NEXT: }
+define i8* @testStack(i8* %call.i, i8 %arg) {
+entry:
+  %save = tail call i8* @llvm.stacksave()
+  %obj = alloca i8, i8 %arg
+  %0 = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %call.i) nounwind
+  call void @llvm.stackrestore(i8* %save)
+  %1 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %call.i) nounwind
+  ret i8* %call.i
+}


        


More information about the llvm-commits mailing list