[llvm] 09266e4 - [ObjC][ARC] Clear the lists of basic blocks and instructions before
Akira Hatanaka via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 12 22:20:54 PST 2020
Author: Akira Hatanaka
Date: 2020-11-12T22:20:02-08:00
New Revision: 09266e4af04ec2dc3a3afc19a3f9d5658d482a44
URL: https://github.com/llvm/llvm-project/commit/09266e4af04ec2dc3a3afc19a3f9d5658d482a44
DIFF: https://github.com/llvm/llvm-project/commit/09266e4af04ec2dc3a3afc19a3f9d5658d482a44.diff
LOG: [ObjC][ARC] Clear the lists of basic blocks and instructions before
continuing the loop
This fixes a bug introduced in c6f1713c46e61bbb8ece9ac5ac329d02e7f93228.
Added:
Modified:
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/test/Transforms/ObjCARC/rv.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index a2dfd1d3d4a0..1cd79875df65 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -2358,8 +2358,11 @@ void ObjCARCOpt::OptimizeReturns(Function &F) {
if (HasSafePathToCall &&
GetBasicARCInstKind(Retain) == ARCInstKind::RetainRV &&
GetBasicARCInstKind(Autorelease) == ARCInstKind::AutoreleaseRV &&
- !cast<CallInst>(*DependingInstructions.begin())->isTailCall())
+ !cast<CallInst>(*DependingInstructions.begin())->isTailCall()) {
+ DependingInstructions.clear();
+ Visited.clear();
continue;
+ }
DependingInstructions.clear();
Visited.clear();
diff --git a/llvm/test/Transforms/ObjCARC/rv.ll b/llvm/test/Transforms/ObjCARC/rv.ll
index 0a1f4665afc6..f89e9f7e39d9 100644
--- a/llvm/test/Transforms/ObjCARC/rv.ll
+++ b/llvm/test/Transforms/ObjCARC/rv.ll
@@ -427,6 +427,31 @@ lpad:
resume { i8*, i32 } %4
}
+; The second retainRV/autoreleaseRV pair can be removed since the call to
+; @returner is a tail call.
+
+; CHECK-LABEL: define i8* @test30(
+; CHECK: %[[V0:.*]] = call i8* @returner()
+; CHECK-NEXT: call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[V0]])
+; CHECK-NEXT: call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[V0]])
+; CHECK-NEXT: ret i8* %[[V0]]
+; CHECK: %[[V3:.*]] = tail call i8* @returner()
+; CHECK-NEXT: ret i8* %[[V3]]
+
+define i8* @test30(i1 %cond) {
+ br i1 %cond, label %bb0, label %bb1
+bb0:
+ %v0 = call i8* @returner()
+ %v1 = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %v0)
+ %v2 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %v0)
+ ret i8* %v0
+bb1:
+ %v3 = tail call i8* @returner()
+ %v4 = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %v3)
+ %v5 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %v3)
+ ret i8* %v3
+}
+
!0 = !{}
; CHECK: attributes [[NUW]] = { nounwind }
More information about the llvm-commits
mailing list