@@ -16,6 +16,10 @@ var globalX: X
16
16
17
17
sil_global hidden @globalX : $X
18
18
19
+ var globalY: X
20
+
21
+ sil_global hidden @globalY : $X
22
+
19
23
20
24
sil hidden_external [global_init] @globalAddressor : $@convention(thin) () -> Builtin.RawPointer
21
25
@@ -142,3 +146,107 @@ bb2:
142
146
%10 = tuple ()
143
147
return %10 : $()
144
148
}
149
+
150
+ // public func hoist_access_static() {
151
+ // Tests Hoisting of begin/end access when there's a static access
152
+ //
153
+ // CHECK-LABEL: sil @hoist_access_static : $@convention(thin) () -> () {
154
+ // CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
155
+ // CHECK: [[BEGIN:%.*]] = begin_access [read] [static] [[GLOBAL]] : $*X
156
+ // CHECK-NEXT: br bb1
157
+ // CHECK: apply
158
+ // CHECK: load
159
+ // CHECK: cond_br
160
+ // CHECK: bb2
161
+ // CHECK: end_access [[BEGIN]]
162
+ // CHECK-LABEL: } // end sil function 'hoist_access_static'
163
+ sil @hoist_access_static : $@convention(thin) () -> () {
164
+ bb0:
165
+ %0 = global_addr @globalX: $*X
166
+ %u0 = function_ref @globalAddressor : $@convention(thin) () -> Builtin.RawPointer
167
+ br bb1
168
+
169
+ bb1:
170
+ %u3 = begin_access [read] [static] %0 : $*X
171
+ %u1 = apply %u0() : $@convention(thin) () -> Builtin.RawPointer
172
+ %u4 = load %u3 : $*X
173
+ end_access %u3 : $*X
174
+ cond_br undef, bb1, bb2
175
+
176
+ bb2:
177
+ %10 = tuple ()
178
+ return %10 : $()
179
+ }
180
+
181
+ // public func hoist_access_static_and_dynamic() {
182
+ // Tests Hoisting of begin/end access when there's a static and distinct dynamic access
183
+ //
184
+ // CHECK-LABEL: sil @hoist_access_static_and_dynamic : $@convention(thin) () -> () {
185
+ // CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
186
+ // CHECK: [[GLOBALY:%.*]] = global_addr @globalY : $*X
187
+ // CHECK: [[BEGIN:%.*]] = begin_access [read] [static] [[GLOBAL]] : $*X
188
+ // CHECK: [[BEGINY:%.*]] = begin_access [read] [dynamic] [[GLOBALY]] : $*X
189
+ // CHECK-NEXT: br bb1
190
+ // CHECK: load
191
+ // CHECK: load
192
+ // CHECK: cond_br
193
+ // CHECK: bb2
194
+ // CHECK: end_access [[BEGINY]]
195
+ // CHECK: end_access [[BEGIN]]
196
+ // CHECK-LABEL: } // end sil function 'hoist_access_static_and_dynamic'
197
+ sil @hoist_access_static_and_dynamic : $@convention(thin) () -> () {
198
+ bb0:
199
+ %0 = global_addr @globalX: $*X
200
+ %1 = global_addr @globalY: $*X
201
+ br bb1
202
+
203
+ bb1:
204
+ %x3 = begin_access [read] [static] %0 : $*X
205
+ %x4 = load %x3 : $*X
206
+ end_access %x3 : $*X
207
+ %y3 = begin_access [read] [dynamic] %1 : $*X
208
+ %y4 = load %y3 : $*X
209
+ end_access %y3 : $*X
210
+ cond_br undef, bb1, bb2
211
+
212
+ bb2:
213
+ %10 = tuple ()
214
+ return %10 : $()
215
+ }
216
+
217
+ // public func dont_hoist_access_static_and_dynamic() {
218
+ // Tests bailing out when there's a static and non-distinct dynamic access
219
+ //
220
+ // CHECK-LABEL: sil @dont_hoist_access_static_and_dynamic : $@convention(thin) () -> () {
221
+ // CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
222
+ // CHECK: [[GLOBALX:%.*]] = global_addr @globalX : $*X
223
+ // CHECK-NEXT: br bb1
224
+ // CHECK: [[BEGIN:%.*]] = begin_access [read] [static] [[GLOBAL]] : $*X
225
+ // CHECK-NEXT: load
226
+ // CHECK: end_access [[BEGIN]]
227
+ // CHECK: [[BEGINX:%.*]] = begin_access [read] [dynamic] [[GLOBALX]] : $*X
228
+ // CHECK-NEXT: load
229
+ // CHECK: end_access [[BEGINX]]
230
+ // CHECK: cond_br
231
+ // CHECK: bb2
232
+ // CHECK: return %{{.*}} : $()
233
+ // CHECK-LABEL: } // end sil function 'dont_hoist_access_static_and_dynamic'
234
+ sil @dont_hoist_access_static_and_dynamic : $@convention(thin) () -> () {
235
+ bb0:
236
+ %0 = global_addr @globalX: $*X
237
+ %1 = global_addr @globalX: $*X
238
+ br bb1
239
+
240
+ bb1:
241
+ %x3 = begin_access [read] [static] %0 : $*X
242
+ %x4 = load %x3 : $*X
243
+ end_access %x3 : $*X
244
+ %y3 = begin_access [read] [dynamic] %1 : $*X
245
+ %y4 = load %y3 : $*X
246
+ end_access %y3 : $*X
247
+ cond_br undef, bb1, bb2
248
+
249
+ bb2:
250
+ %10 = tuple ()
251
+ return %10 : $()
252
+ }
0 commit comments