multiblock-multipath-throwing.ll
4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -basic-aa -dse -enable-dse-memoryssa -S | FileCheck %s
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
declare void @readnone_may_throw() readnone
declare void @use(i32 *)
; Tests where the pointer/object is accessible after the function returns.
; Cannot remove the store from the entry block, because the call in bb2 may throw.
define void @accessible_after_return_1(i32* noalias %P, i1 %c1) {
; CHECK-LABEL: @accessible_after_return_1(
; CHECK-NEXT: store i32 1, i32* [[P:%.*]], align 4
; CHECK-NEXT: br i1 [[C1:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: store i32 0, i32* [[P]], align 4
; CHECK-NEXT: br label [[BB5:%.*]]
; CHECK: bb2:
; CHECK-NEXT: call void @readnone_may_throw()
; CHECK-NEXT: store i32 3, i32* [[P]], align 4
; CHECK-NEXT: br label [[BB5]]
; CHECK: bb5:
; CHECK-NEXT: call void @use(i32* [[P]])
; CHECK-NEXT: ret void
;
store i32 1, i32* %P
br i1 %c1, label %bb1, label %bb2
bb1:
store i32 0, i32* %P
br label %bb5
bb2:
call void @readnone_may_throw()
store i32 3, i32* %P
br label %bb5
bb5:
call void @use(i32* %P)
ret void
}
; Cannot remove the store from the entry block, because the call in bb3 may throw.
define void @accessible_after_return6(i32* %P, i1 %c.1, i1 %c.2) {
; CHECK-LABEL: @accessible_after_return6(
; CHECK-NEXT: entry:
; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
; CHECK-NEXT: br i1 [[C_1:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: br i1 [[C_2:%.*]], label [[BB3:%.*]], label [[BB4:%.*]]
; CHECK: bb2:
; CHECK-NEXT: store i32 1, i32* [[P]], align 4
; CHECK-NEXT: ret void
; CHECK: bb3:
; CHECK-NEXT: call void @readnone_may_throw()
; CHECK-NEXT: store i32 2, i32* [[P]], align 4
; CHECK-NEXT: ret void
; CHECK: bb4:
; CHECK-NEXT: store i32 3, i32* [[P]], align 4
; CHECK-NEXT: ret void
;
entry:
store i32 0, i32* %P
br i1 %c.1, label %bb1, label %bb2
bb1:
br i1 %c.2, label %bb3, label %bb4
bb2:
store i32 1, i32* %P
ret void
bb3:
call void @readnone_may_throw()
store i32 2, i32* %P
ret void
bb4:
store i32 3, i32* %P
ret void
}
; Tests where the pointer/object is *NOT* accessible after the function returns.
; The store in the entry block can be eliminated, because it is overwritten
; on all paths to the exit. As the location is not visible to the caller, the
; call in bb2 (which may throw) can be ignored.
define void @alloca_1(i1 %c1) {
; CHECK-LABEL: @alloca_1(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[P:%.*]] = alloca i32
; CHECK-NEXT: br i1 [[C1:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: store i32 0, i32* [[P]], align 4
; CHECK-NEXT: br label [[BB5:%.*]]
; CHECK: bb2:
; CHECK-NEXT: call void @readnone_may_throw()
; CHECK-NEXT: store i32 3, i32* [[P]], align 4
; CHECK-NEXT: br label [[BB5]]
; CHECK: bb5:
; CHECK-NEXT: call void @use(i32* [[P]])
; CHECK-NEXT: ret void
;
entry:
%P = alloca i32
store i32 1, i32* %P
br i1 %c1, label %bb1, label %bb2
bb1:
store i32 0, i32* %P
br label %bb5
bb2:
call void @readnone_may_throw()
store i32 3, i32* %P
br label %bb5
bb5:
call void @use(i32* %P)
ret void
}
; The store in the entry block can be eliminated, because it is overwritten
; on all paths to the exit. As the location is not visible to the caller, the
; call in bb3 (which may throw) can be ignored.
define void @alloca_2(i1 %c.1, i1 %c.2) {
; CHECK-LABEL: @alloca_2(
; CHECK-NEXT: [[P:%.*]] = alloca i32
; CHECK-NEXT: br i1 [[C_1:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: store i32 0, i32* [[P]], align 4
; CHECK-NEXT: br label [[BB5:%.*]]
; CHECK: bb2:
; CHECK-NEXT: br i1 [[C_2:%.*]], label [[BB3:%.*]], label [[BB4:%.*]]
; CHECK: bb3:
; CHECK-NEXT: call void @readnone_may_throw()
; CHECK-NEXT: store i32 3, i32* [[P]], align 4
; CHECK-NEXT: br label [[BB5]]
; CHECK: bb4:
; CHECK-NEXT: store i32 5, i32* [[P]], align 4
; CHECK-NEXT: br label [[BB5]]
; CHECK: bb5:
; CHECK-NEXT: call void @use(i32* [[P]])
; CHECK-NEXT: ret void
;
%P = alloca i32
store i32 1, i32* %P
br i1 %c.1, label %bb1, label %bb2
bb1:
store i32 0, i32* %P
br label %bb5
bb2:
br i1 %c.2, label %bb3, label %bb4
bb3:
call void @readnone_may_throw()
store i32 3, i32* %P
br label %bb5
bb4:
store i32 5, i32* %P
br label %bb5
bb5:
call void @use(i32* %P)
ret void
}