1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=dse -S | FileCheck %s
4 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
5 declare void @unknown_func()
6 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
7 declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i32, i1) nounwind
9 ; Tests where the pointer/object is accessible after the function returns.
11 ; Overwriting store along one path to the exit.
12 define void @accessible_after_return_1(ptr noalias %P, i1 %c) {
13 ; CHECK-LABEL: @accessible_after_return_1(
15 ; CHECK-NEXT: [[ARRAYIDX0:%.*]] = getelementptr inbounds i32, ptr [[P:%.*]], i64 1
16 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[ARRAYIDX0]], i8 0, i64 28, i1 false)
17 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
19 ; CHECK-NEXT: br label [[BB3:%.*]]
21 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 1
22 ; CHECK-NEXT: store i32 1, ptr [[ARRAYIDX1]], align 4
23 ; CHECK-NEXT: br label [[BB3]]
25 ; CHECK-NEXT: ret void
28 %arrayidx0 = getelementptr inbounds i32, ptr %P, i64 1
29 call void @llvm.memset.p0.i64(ptr %arrayidx0, i8 0, i64 28, i32 4, i1 false)
30 br i1 %c, label %bb1, label %bb2
36 %arrayidx1 = getelementptr inbounds i32, ptr %P, i64 1
37 store i32 1, ptr %arrayidx1, align 4
44 ; Post-dominating store.
45 ; TODO: The memset can be shortened.
46 define void @accessible_after_return_2(ptr noalias %P, i1 %c) {
47 ; CHECK-LABEL: @accessible_after_return_2(
49 ; CHECK-NEXT: [[ARRAYIDX0:%.*]] = getelementptr inbounds i32, ptr [[P:%.*]], i64 1
50 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[ARRAYIDX0]], i8 0, i64 28, i1 false)
51 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
53 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 1
54 ; CHECK-NEXT: store i32 1, ptr [[ARRAYIDX1]], align 4
55 ; CHECK-NEXT: br label [[BB3:%.*]]
57 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 1
58 ; CHECK-NEXT: store i32 1, ptr [[ARRAYIDX2]], align 4
59 ; CHECK-NEXT: br label [[BB3]]
61 ; CHECK-NEXT: ret void
64 %arrayidx0 = getelementptr inbounds i32, ptr %P, i64 1
65 call void @llvm.memset.p0.i64(ptr %arrayidx0, i8 0, i64 28, i32 4, i1 false)
66 br i1 %c, label %bb1, label %bb2
69 %arrayidx1 = getelementptr inbounds i32, ptr %P, i64 1
70 store i32 1, ptr %arrayidx1, align 4
74 %arrayidx2 = getelementptr inbounds i32, ptr %P, i64 1
75 store i32 1, ptr %arrayidx2, align 4
82 ; Stores along both exit paths.
83 define void @accessible_after_return_3(ptr noalias %P, i1 %c) {
84 ; CHECK-LABEL: @accessible_after_return_3(
86 ; CHECK-NEXT: [[ARRAYIDX0:%.*]] = getelementptr inbounds i32, ptr [[P:%.*]], i64 1
87 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i8, ptr [[ARRAYIDX0]], i64 4
88 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[TMP0]], i8 0, i64 24, i1 false)
89 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
91 ; CHECK-NEXT: br label [[BB3:%.*]]
93 ; CHECK-NEXT: br label [[BB3]]
95 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 1
96 ; CHECK-NEXT: store i32 1, ptr [[ARRAYIDX1]], align 4
97 ; CHECK-NEXT: ret void
100 %arrayidx0 = getelementptr inbounds i32, ptr %P, i64 1
101 call void @llvm.memset.p0.i64(ptr %arrayidx0, i8 0, i64 28, i32 4, i1 false)
102 br i1 %c, label %bb1, label %bb2
111 %arrayidx1 = getelementptr inbounds i32, ptr %P, i64 1
112 store i32 1, ptr %arrayidx1, align 4
117 declare void @readonly_use(ptr nocapture) readonly
119 ; Tests where the pointer/object is *NOT* accessible after the function returns.
121 ; Overwriting store along one path to the exit.
122 define void @alloca_1(i1 %c) {
123 ; CHECK-LABEL: @alloca_1(
125 ; CHECK-NEXT: [[P_ALLOCA:%.*]] = alloca [32 x i32], align 4
126 ; CHECK-NEXT: [[ARRAYIDX0:%.*]] = getelementptr inbounds i32, ptr [[P_ALLOCA]], i64 1
127 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[ARRAYIDX0]], i8 0, i64 28, i1 false)
128 ; CHECK-NEXT: call void @readonly_use(ptr [[P_ALLOCA]])
129 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
131 ; CHECK-NEXT: br label [[BB3:%.*]]
133 ; CHECK-NEXT: br label [[BB3]]
135 ; CHECK-NEXT: ret void
138 %P.alloca = alloca [32 x i32]
139 %arrayidx0 = getelementptr inbounds i32, ptr %P.alloca, i64 1
140 call void @llvm.memset.p0.i64(ptr %arrayidx0, i8 0, i64 28, i32 4, i1 false)
141 call void @readonly_use(ptr %P.alloca)
142 br i1 %c, label %bb1, label %bb2
148 %arrayidx1 = getelementptr inbounds i32, ptr %P.alloca, i64 1
149 store i32 1, ptr %arrayidx1, align 4
156 ; Post-dominating store.
157 define void @alloca_2(i1 %c) {
158 ; CHECK-LABEL: @alloca_2(
160 ; CHECK-NEXT: [[P_ALLOCA:%.*]] = alloca [32 x i32], align 4
161 ; CHECK-NEXT: [[ARRAYIDX0:%.*]] = getelementptr inbounds i32, ptr [[P_ALLOCA]], i64 1
162 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[ARRAYIDX0]], i8 0, i64 28, i1 false)
163 ; CHECK-NEXT: call void @readonly_use(ptr [[P_ALLOCA]])
164 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
166 ; CHECK-NEXT: br label [[BB3:%.*]]
168 ; CHECK-NEXT: br label [[BB3]]
170 ; CHECK-NEXT: ret void
173 %P.alloca = alloca [32 x i32]
174 %arrayidx0 = getelementptr inbounds i32, ptr %P.alloca, i64 1
175 call void @llvm.memset.p0.i64(ptr %arrayidx0, i8 0, i64 28, i32 4, i1 false)
176 call void @readonly_use(ptr %P.alloca)
177 br i1 %c, label %bb1, label %bb2
180 %arrayidx1 = getelementptr inbounds i32, ptr %P.alloca, i64 1
181 store i32 1, ptr %arrayidx1, align 4
185 %arrayidx2 = getelementptr inbounds i32, ptr %P.alloca, i64 1
186 store i32 1, ptr %arrayidx2, align 4
193 ; Stores along both exit paths.
194 define void @alloca_3(i1 %c) {
195 ; CHECK-LABEL: @alloca_3(
197 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
199 ; CHECK-NEXT: br label [[BB3:%.*]]
201 ; CHECK-NEXT: br label [[BB3]]
203 ; CHECK-NEXT: ret void
206 %P.alloca = alloca [32 x i32]
207 %arrayidx0 = getelementptr inbounds i32, ptr %P.alloca, i64 1
208 call void @llvm.memset.p0.i64(ptr %arrayidx0, i8 0, i64 28, i32 4, i1 false)
209 br i1 %c, label %bb1, label %bb2
218 %arrayidx1 = getelementptr inbounds i32, ptr %P.alloca, i64 1
219 store i32 1, ptr %arrayidx1, align 4