From a5fc4b0861b14be1a3dbdd69ee428f7173018e13 Mon Sep 17 00:00:00 2001 From: Francis Visoiu Mistrih Date: Mon, 4 Nov 2019 16:45:21 -0800 Subject: [PATCH] [NFC][ObjC][ARC] Add tests for OptimizeRetainRVCall Add tests for bitcasts + zero GEPs, and pre-commit tests for lifetime markers. --- test/Transforms/ObjCARC/post-inlining.ll | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/Transforms/ObjCARC/post-inlining.ll b/test/Transforms/ObjCARC/post-inlining.ll index 0304d59c8b9..65b1153c136 100644 --- a/test/Transforms/ObjCARC/post-inlining.ll +++ b/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 +}