[llvm] r185769 - [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.

Michael Gottesman mgottesman at apple.com
Sat Jul 6 18:52:56 PDT 2013


Author: mgottesman
Date: Sat Jul  6 20:52:55 2013
New Revision: 185769

URL: http://llvm.org/viewvc/llvm-project?rev=185769&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Transforms/ObjCARC/ObjCARCAliasAnalysis.cpp
    llvm/trunk/lib/Transforms/ObjCARC/ObjCARCUtil.cpp
    llvm/trunk/test/Transforms/ObjCARC/basic.ll
    llvm/trunk/test/Transforms/ObjCARC/gvn.ll

Modified: llvm/trunk/lib/Transforms/ObjCARC/ObjCARCAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ObjCARCAliasAnalysis.cpp?rev=185769&r1=185768&r2=185769&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ObjCARCAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ObjCARCAliasAnalysis.cpp Sat Jul  6 20:52:55 2013
@@ -150,6 +150,14 @@ ObjCARCAliasAnalysis::getModRefInfo(Immu
     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);
 }
 

Modified: llvm/trunk/lib/Transforms/ObjCARC/ObjCARCUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ObjCARCUtil.cpp?rev=185769&r1=185768&r2=185769&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ObjCARCUtil.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ObjCARCUtil.cpp Sat Jul  6 20:52:55 2013
@@ -112,6 +112,8 @@ InstructionClass llvm::objcarc::GetFunct
           .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**

Modified: llvm/trunk/test/Transforms/ObjCARC/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/basic.ll?rev=185769&r1=185768&r2=185769&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/basic.ll (original)
+++ llvm/trunk/test/Transforms/ObjCARC/basic.ll Sat Jul  6 20:52:55 2013
@@ -3037,9 +3037,28 @@ end:
   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 }

Modified: llvm/trunk/test/Transforms/ObjCARC/gvn.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/gvn.ll?rev=185769&r1=185768&r2=185769&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/gvn.ll (original)
+++ llvm/trunk/test/Transforms/ObjCARC/gvn.ll Sat Jul  6 20:52:55 2013
@@ -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
 }





More information about the llvm-commits mailing list