Don't convert objc_retainAutoreleasedReturnValue to objc_retain if it
is retaining the return value of an invoke that it immediately follows. llvm-svn: 153344
This commit is contained in:
parent
5c70fadc17
commit
e3ed2b0699
|
@ -2143,17 +2143,26 @@ ObjCARCOpt::OptimizeRetainCall(Function &F, Instruction *Retain) {
|
||||||
/// return true.
|
/// return true.
|
||||||
bool
|
bool
|
||||||
ObjCARCOpt::OptimizeRetainRVCall(Function &F, Instruction *RetainRV) {
|
ObjCARCOpt::OptimizeRetainRVCall(Function &F, Instruction *RetainRV) {
|
||||||
// Check for the argument being from an immediately preceding call.
|
// Check for the argument being from an immediately preceding call or invoke.
|
||||||
Value *Arg = GetObjCArg(RetainRV);
|
Value *Arg = GetObjCArg(RetainRV);
|
||||||
CallSite CS(Arg);
|
CallSite CS(Arg);
|
||||||
if (Instruction *Call = CS.getInstruction())
|
if (Instruction *Call = CS.getInstruction()) {
|
||||||
if (Call->getParent() == RetainRV->getParent()) {
|
if (Call->getParent() == RetainRV->getParent()) {
|
||||||
BasicBlock::iterator I = Call;
|
BasicBlock::iterator I = Call;
|
||||||
++I;
|
++I;
|
||||||
while (isNoopInstruction(I)) ++I;
|
while (isNoopInstruction(I)) ++I;
|
||||||
if (&*I == RetainRV)
|
if (&*I == RetainRV)
|
||||||
return false;
|
return false;
|
||||||
|
} else if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
|
||||||
|
BasicBlock *RetainRVParent = RetainRV->getParent();
|
||||||
|
if (II->getNormalDest() == RetainRVParent) {
|
||||||
|
BasicBlock::iterator I = RetainRVParent->begin();
|
||||||
|
while (isNoopInstruction(I)) ++I;
|
||||||
|
if (&*I == RetainRV)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for being preceded by an objc_autoreleaseReturnValue on the same
|
// Check for being preceded by an objc_autoreleaseReturnValue on the same
|
||||||
// pointer. In this case, we can delete the pair.
|
// pointer. In this case, we can delete the pair.
|
||||||
|
|
|
@ -6,6 +6,7 @@ declare i8* @objc_retainAutoreleasedReturnValue(i8*)
|
||||||
declare i8* @objc_msgSend(i8*, i8*, ...)
|
declare i8* @objc_msgSend(i8*, i8*, ...)
|
||||||
declare void @use_pointer(i8*)
|
declare void @use_pointer(i8*)
|
||||||
declare void @callee()
|
declare void @callee()
|
||||||
|
declare i8* @returner()
|
||||||
|
|
||||||
; ARCOpt shouldn't try to move the releases to the block containing the invoke.
|
; ARCOpt shouldn't try to move the releases to the block containing the invoke.
|
||||||
|
|
||||||
|
@ -169,6 +170,48 @@ if.end:
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; Don't turn the retainAutoreleaseReturnValue into retain, because it's
|
||||||
|
; for an invoke which we can assume codegen will put immediately prior.
|
||||||
|
|
||||||
|
; CHECK: define void @test5(
|
||||||
|
; CHECK: call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
|
||||||
|
; CHECK: }
|
||||||
|
define void @test5() {
|
||||||
|
entry:
|
||||||
|
%z = invoke i8* @returner()
|
||||||
|
to label %if.end unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
|
||||||
|
|
||||||
|
lpad:
|
||||||
|
%r13 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*)
|
||||||
|
cleanup
|
||||||
|
ret void
|
||||||
|
|
||||||
|
if.end:
|
||||||
|
call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
; Like test5, but there's intervening code.
|
||||||
|
|
||||||
|
; CHECK: define void @test6(
|
||||||
|
; CHECK: call i8* @objc_retain(i8* %z)
|
||||||
|
; CHECK: }
|
||||||
|
define void @test6() {
|
||||||
|
entry:
|
||||||
|
%z = invoke i8* @returner()
|
||||||
|
to label %if.end unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
|
||||||
|
|
||||||
|
lpad:
|
||||||
|
%r13 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*)
|
||||||
|
cleanup
|
||||||
|
ret void
|
||||||
|
|
||||||
|
if.end:
|
||||||
|
call void @callee()
|
||||||
|
call i8* @objc_retainAutoreleasedReturnValue(i8* %z)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
declare i32 @__gxx_personality_v0(...)
|
declare i32 @__gxx_personality_v0(...)
|
||||||
declare i32 @__objc_personality_v0(...)
|
declare i32 @__objc_personality_v0(...)
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ entry:
|
||||||
|
|
||||||
; CHECK: @test1(
|
; CHECK: @test1(
|
||||||
; CHECK: @objc_retain(
|
; CHECK: @objc_retain(
|
||||||
; CHECK: @objc_retain(
|
; CHECK: @objc_retainAutoreleasedReturnValue(
|
||||||
; CHECK: @objc_release(
|
; CHECK: @objc_release(
|
||||||
; CHECK: @objc_release(
|
; CHECK: @objc_release(
|
||||||
; CHECK: }
|
; CHECK: }
|
||||||
|
|
Loading…
Reference in New Issue