[llvm] f6de530 - [NFC][StackSafety] Test that StackLifetime looks through stripPointerCasts

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 16:21:12 PDT 2020


Author: Chuanqi Xu
Date: 2020-08-18T16:21:00-07:00
New Revision: f6de5306ec658fe15b65d875bba2f506558f160d

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

LOG: [NFC][StackSafety] Test that StackLifetime looks through stripPointerCasts

StackLifetime class collects lifetime marker of an `alloca` by collect
the user of `BitCast` who is the user of the `alloca`. However, either
the `alloca` itself could be used with the lifetime marker or the `BitCast`
of the `alloca` could be transformed to other instructions. (e.g.,
it may be transformed to all zero reps in `InstCombine` pass).
This patch tries to fix this process in `collectMarkers` functions.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D85399

Added: 
    

Modified: 
    llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll b/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
index 470450a3a977..d29029530b6c 100644
--- a/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
+++ b/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
@@ -699,6 +699,50 @@ l2:                                               ; preds = %l2, %entry
   br label %l2
 }
 
+%struct.char_array = type { [500 x i8] }
+
+define dso_local void @gep_test(i32 %cond)  {
+; CHECK-LABEL: define dso_local void @gep_test
+entry:
+; CHECK: entry:
+; CHECK-NEXT: Alive: <>
+  %a = alloca %struct.char_array, align 8
+  %b = alloca %struct.char_array, align 8
+  %tobool.not = icmp eq i32 %cond, 0
+  br i1 %tobool.not, label %if.else, label %if.then
+
+if.then:                                          ; preds = %entry
+; CHECK: if.then:
+; CHECK-NEXT: Alive: <>
+  %0 = getelementptr inbounds %struct.char_array, %struct.char_array* %a, i64 0, i32 0, i64 0
+  call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %0)
+; CHECK: call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %0)
+; CHECK-NEXT: Alive: <a>
+  tail call void @capture8(i8* %0)
+  call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %0)
+; CHECK: call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %0)
+; CHECK-NEXT: Alive: <>
+  br label %if.end
+
+if.else:                                          ; preds = %entry
+; CHECK: if.else:
+; CHECK-NEXT: Alive: <>
+  %1 = getelementptr inbounds %struct.char_array, %struct.char_array* %b, i64 0, i32 0, i64 0
+  call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %1)
+; CHECK: call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %1)
+; CHECK-NEXT: Alive: <b>
+  tail call void @capture8(i8* %1)
+  call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %1)
+; CHECK: call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %1)
+; CHECK-NEXT: Alive: <>
+  br label %if.end
+
+if.end:                                           ; preds = %if.else, %if.then
+; CHECK: if.end:
+; CHECK-NEXT: Alive: <>
+  ret void
+}
+
 define void @if_must(i1 %a) {
 ; CHECK-LABEL: define void @if_must
 entry:


        


More information about the llvm-commits mailing list