[objc-arc] Teach the ARC optimizer that objc_sync_enter/objc_sync_exit do not modify the ref count of an objc object and additionally are inert for modref purposes.

llvm-svn: 185769
This commit is contained in:
Michael Gottesman 2013-07-07 01:52:55 +00:00
parent 6d715e8699
commit a72630d453
4 changed files with 52 additions and 5 deletions

View File

@ -150,6 +150,14 @@ ObjCARCAliasAnalysis::getModRefInfo(ImmutableCallSite CS, const Location &Loc) {
break;
}
// Handle special objective c calls defaulting to chaining.
const Function *F = CS.getCalledFunction();
if (F)
return StringSwitch<AliasAnalysis::ModRefResult>(F->getName())
.Case("objc_sync_start", NoModRef)
.Case("objc_sync_stop", NoModRef)
.Default(AliasAnalysis::getModRefInfo(CS, Loc));
return AliasAnalysis::getModRefInfo(CS, Loc);
}

View File

@ -112,6 +112,8 @@ InstructionClass llvm::objcarc::GetFunctionClass(const Function *F) {
.Case("objc_retain_autorelease", IC_FusedRetainAutorelease)
.Case("objc_retainAutorelease", IC_FusedRetainAutorelease)
.Case("objc_retainAutoreleaseReturnValue",IC_FusedRetainAutoreleaseRV)
.Case("objc_sync_enter", IC_User)
.Case("objc_sync_exit", IC_User)
.Default(IC_CallOrUser);
// Argument is i8**

View File

@ -3037,9 +3037,28 @@ end: ; preds = %if.end125, %if.end1
ret void
}
!0 = metadata !{}
declare i32 @__gxx_personality_v0(...)
declare i32 @objc_sync_enter(i8*)
declare i32 @objc_sync_exit(i8*)
; Make sure that we understand that objc_sync_{enter,exit} are IC_User not
; IC_Call/IC_CallOrUser.
; CHECK: define void @test67
; CHECK-NEXT: call i32 @objc_sync_enter(i8* %x)
; CHECK-NEXT: call i32 @objc_sync_exit(i8* %x)
; CHECK-NEXT: ret void
; CHECK-NEXT: }
define void @test67(i8* %x) {
call i8* @objc_retain(i8* %x)
call i32 @objc_sync_enter(i8* %x)
call i32 @objc_sync_exit(i8* %x)
call void @objc_release(i8* %x), !clang.imprecise_release !0
ret void
}
!0 = metadata !{}
; CHECK: attributes #0 = { nounwind readnone }
; CHECK: attributes [[NUW]] = { nounwind }

View File

@ -3,20 +3,38 @@
@x = common global i8* null, align 8
declare i8* @objc_retain(i8*)
declare i32 @objc_sync_start(i8*)
declare i32 @objc_sync_stop(i8*)
; GVN should be able to eliminate this redundant load, with ARC-specific
; alias analysis.
; CHECK: define i8* @foo(i32 %n)
; CHECK: define i8* @test0(i32 %n)
; CHECK-NEXT: entry:
; CHECK-NEXT: %s = load i8** @x
; CHECK-NOT: load
; CHECK: ret i8* %s
; CHECK-NEXT: }
define i8* @foo(i32 %n) nounwind {
define i8* @test0(i32 %n) nounwind {
entry:
%s = load i8** @x
%0 = tail call i8* @objc_retain(i8* %s) nounwind
%t = load i8** @x
ret i8* %s
ret i8* %t
}
; CHECK: define i8* @test1(i32 %n)
; CHECK-NEXT: entry:
; CHECK-NEXT: %s = load i8** @x
; CHECK-NEXT: call i32 @objc_sync_start
; CHECK-NEXT: call i32 @objc_sync_stop
; CHECK-NEXT: ret i8* %s
; CHECK-NEXT: }
define i8* @test1(i32 %n) nounwind {
entry:
%s = load i8** @x
%0 = call i32 @objc_sync_start(i8* %s)
%t = load i8** @x
%1 = call i32 @objc_sync_stop(i8* %s)
ret i8* %t
}