[clang] 656296b - Reapply [CaptureTracking] Do not check domination

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Sun May 16 06:48:57 PDT 2021


Author: Nikita Popov
Date: 2021-05-16T15:46:31+02:00
New Revision: 656296b1c2eca127cb48612227fa5f381c81b53b

URL: https://github.com/llvm/llvm-project/commit/656296b1c2eca127cb48612227fa5f381c81b53b
DIFF: https://github.com/llvm/llvm-project/commit/656296b1c2eca127cb48612227fa5f381c81b53b.diff

LOG: Reapply [CaptureTracking] Do not check domination

Reapply after adjusting the synchronized.m test case, where the
TODO is now resolved. The pointer is only captured on the exception
handling path.

-----

For the CapturesBefore tracker, it is sufficient to check that
I can not reach BeforeHere. This does not necessarily require
that BeforeHere dominates I, it can also occur if the capture
happens on an entirely disjoint path.

This change was previously accepted in D90688, but had to be
reverted due to large compile-time impact in some cases: It
increases the number of reachability queries that are performed.

After recent changes, the compile-time impact is largely mitigated,
so I'm reapplying this patch. The remaining compile-time impact
is largely proportional to changes in code-size.

Added: 
    

Modified: 
    clang/test/CodeGenObjC/synchronized.m
    llvm/lib/Analysis/CaptureTracking.cpp
    llvm/test/Transforms/MemCpyOpt/callslot.ll

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGenObjC/synchronized.m b/clang/test/CodeGenObjC/synchronized.m
index 6d37e6fc06ca..44f4826d19dc 100644
--- a/clang/test/CodeGenObjC/synchronized.m
+++ b/clang/test/CodeGenObjC/synchronized.m
@@ -39,7 +39,6 @@ void foo(id a) {
     // CHECK: unreachable
 
     // CHECK:      call void @objc_exception_try_exit
-    // CHECK:      [[T:%.*]] = load i8*, i8** [[SYNC]]
     // CHECK-NEXT: call i32 @objc_sync_exit
     // CHECK: ret void
     return;
@@ -49,9 +48,8 @@ void foo(id a) {
 
 // CHECK-LABEL: define{{.*}} i32 @f0(
 int f0(id a) {
-  // TODO: we can optimize the ret to a constant if we can figure out
-  // either that x isn't stored to within the synchronized block or
-  // that the synchronized block can't longjmp.
+  // We can optimize the ret to a constant as we can figure out
+  // that x isn't stored to within the synchronized block.
 
   // CHECK: [[X:%.*]] = alloca i32
   // CHECK: store i32 1, i32* [[X]]
@@ -59,8 +57,7 @@ int f0(id a) {
   @synchronized((x++, a)) {    
   }
 
-  // CHECK: [[T:%.*]] = load i32, i32* [[X]]
-  // CHECK: ret i32 [[T]]
+  // CHECK: ret i32 1
   return x;
 }
 

diff  --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index e14f6f25dc18..25815fc57463 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -143,14 +143,8 @@ namespace {
         return !isPotentiallyReachableFromMany(Worklist, BB, nullptr, DT);
       }
 
-      // If the value is defined in the same basic block as use and BeforeHere,
-      // there is no need to explore the use if BeforeHere dominates use.
       // Check whether there is a path from I to BeforeHere.
-      if (DT->dominates(BeforeHere, I) &&
-          !isPotentiallyReachable(I, BeforeHere, nullptr, DT))
-        return true;
-
-      return false;
+      return !isPotentiallyReachable(I, BeforeHere, nullptr, DT);
     }
 
     bool captured(const Use *U) override {

diff  --git a/llvm/test/Transforms/MemCpyOpt/callslot.ll b/llvm/test/Transforms/MemCpyOpt/callslot.ll
index 037a95ec5176..b9eab2ef8778 100644
--- a/llvm/test/Transforms/MemCpyOpt/callslot.ll
+++ b/llvm/test/Transforms/MemCpyOpt/callslot.ll
@@ -252,8 +252,8 @@ define void @capture_nopath_call(i1 %cond) {
 ; CHECK-NEXT:    call void @accept_ptr(i8* [[DEST_I8]])
 ; CHECK-NEXT:    ret void
 ; CHECK:       nocaptures:
-; CHECK-NEXT:    call void @accept_ptr(i8* [[SRC_I8]]) #[[ATTR3]]
-; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DEST_I8]], i8* [[SRC_I8]], i64 16, i1 false)
+; CHECK-NEXT:    [[DEST1:%.*]] = bitcast [16 x i8]* [[DEST]] to i8*
+; CHECK-NEXT:    call void @accept_ptr(i8* [[DEST1]]) #[[ATTR3]]
 ; CHECK-NEXT:    ret void
 ;
   %dest = alloca [16 x i8]


        


More information about the cfe-commits mailing list