d68e9c0f51c7bc36c514ac90f853cd27982219cf
[oota-llvm.git] / test / Transforms / DeadStoreElimination / lifetime.ll
1 ; RUN: opt -S -basicaa -dse < %s | FileCheck %s
2
3 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
4
5 declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind
6 declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind
7 declare void @llvm.memset.p0i8.i8(i8* nocapture, i8, i8, i32, i1) nounwind
8 declare void @callee(i8*)
9
10 define void @test1() {
11 ; CHECK-LABEL: @test1(
12   %A = alloca i8
13
14   store i8 0, i8* %A  ;; Written to by memset
15 ; CHECK-NOT: store
16   call void @llvm.lifetime.end(i64 1, i8* %A)
17 ; CHECK-NOT: lifetime.end
18
19   call void @llvm.memset.p0i8.i8(i8* %A, i8 0, i8 -1, i32 0, i1 false)
20 ; CHECK-NOT: memset
21
22   ret void
23 ; CHECK: ret void
24 }
25
26 define void @test2(i32* %P) {
27 ; CHECK-LABEL: test2
28   %Q = getelementptr i32, i32* %P, i32 1
29   %R = bitcast i32* %Q to i8*
30   call void @llvm.lifetime.start(i64 4, i8* %R)
31 ; CHECK: lifetime.start
32   store i32 0, i32* %Q  ;; This store is dead.
33 ; CHECK-NOT: store
34   call void @llvm.lifetime.end(i64 4, i8* %R)
35 ; CHECK: lifetime.end
36   ret void
37 }
38
39 define void @test3(i8*) {
40 ; CHECK-LABEL: test3
41   %a = alloca i8
42   call void @llvm.lifetime.start(i64 1, i8* %a)
43 ; CHECK-NOT: lifetime.start
44   call void @llvm.lifetime.end(i64 1, i8* %a)
45 ; CHECK-NOT: lifetime.end
46   call void @llvm.lifetime.start(i64 1, i8* undef)
47 ; CHECK-NOT: lifetime.start
48   call void @llvm.lifetime.end(i64 1, i8* undef)
49 ; CHECK-NOT: lifetime.end
50   ret void
51 }
52
53 define void @test4(i8*) {
54 ; CHECK-LABEL: test4
55   %a = alloca i8
56   call void @llvm.lifetime.start(i64 1, i8* %a)
57 ; CHECK: lifetime.start
58   call void @llvm.lifetime.end(i64 1, i8* %a)
59 ; CHECK: lifetime.end
60   call void @llvm.lifetime.start(i64 1, i8* %0)
61 ; CHECK: lifetime.start
62   call void @llvm.lifetime.end(i64 1, i8* %0)
63 ; CHECK: lifetime.end
64   call void @llvm.lifetime.start(i64 1, i8* %a)
65 ; CHECK-NOT: lifetime.start
66   call void @llvm.lifetime.end(i64 1, i8* %a)
67 ; CHECK-NOT: lifetime.end
68   ret void
69 }
70
71 define void @test5() {
72 ; CHECK-LABEL: test5
73   %a = alloca i8
74   %b = alloca i8
75   call void @llvm.lifetime.start(i64 1, i8* %a)
76 ; CHECK: lifetime.start
77   call void @llvm.lifetime.end(i64 1, i8* %a)
78 ; CHECK: lifetime.end
79   call void @llvm.lifetime.start(i64 1, i8* %b)
80 ; CHECK: lifetime.start
81   call void @callee(i8* %b)
82 ; CHECK: call void @callee
83   call void @llvm.lifetime.end(i64 1, i8* %b)
84 ; CHECK-NOT: lifetime.end
85   ret void
86 }