Skip to content

Commit abea2ab

Browse files
committed
Refactor dead_store_elim.sil
Get rid of some CHECK-NEXTs. CHECK-NEXT can sometimes be fragile. Rename a few functions to make sure the naming in the file is more consistent
1 parent f25bf9e commit abea2ab

File tree

1 file changed

+39
-65
lines changed

1 file changed

+39
-65
lines changed

test/SILOptimizer/dead_store_elim.sil

Lines changed: 39 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,13 @@ sil @S7_init : $@convention(thin) (@thin S7.Type) -> S7
125125
sil @S8_init : $@convention(thin) (@thin S8.Type) -> @owned S8
126126
sil @escaped_a : $@convention(thin) () -> Builtin.RawPointer
127127

128-
//////////////////////////////////////////////////////////////
129-
// Tests for LoadStoreOpts.cpp from globalloadstoreopts.sil //
130-
//////////////////////////////////////////////////////////////
131-
132128
// We should be able to remove the local store that is not read.
133129
//
134-
// CHECK-LABEL: DeadLocalStoreSimpleStruct
130+
// CHECK-LABEL: trivial_local_dead_store
135131
// CHECK: bb0
136132
// CHECK-NOT: store
137133
// CHECK: return
138-
sil hidden @DeadLocalStoreSimpleStruct : $@convention(thin) () -> () {
134+
sil hidden @trivial_local_dead_store : $@convention(thin) () -> () {
139135
bb0:
140136
%0 = alloc_stack $Int, var, name "a" // users: %3, %5
141137
%1 = integer_literal $Builtin.Int64, 1 // user: %2
@@ -148,11 +144,11 @@ bb0:
148144

149145
// We can not remove the local store that is read.
150146
//
151-
// CHECK-LABEL: NoDeadLocalStoreSimpleStruct
147+
// CHECK-LABEL: blocking_read_on_local_store
152148
// CHECK: bb0
153149
// CHECK: store
154150
// CHECK: return
155-
sil hidden @NoDeadLocalStoreSimpleStruct : $@convention(thin) () -> () {
151+
sil hidden @blocking_read_on_local_store : $@convention(thin) () -> () {
156152
bb0:
157153
%0 = alloc_stack $Int, var, name "a" // users: %3, %5
158154
%1 = integer_literal $Builtin.Int64, 1 // user: %2
@@ -164,34 +160,10 @@ bb0:
164160
return %4 : $() // id: %6
165161
}
166162

167-
// TEST CASE CURRENTLY DISABLED.
168-
// There is currently a outstand radar in the swift type/aa system, will
169-
// take this flag off once thats fixed.
170-
//
171-
// We can not remove the local store as the debug_value_addr could
172-
// be turned to a debug_value and thus act as a read on the memory
173-
// location..
174-
//
175-
// DISABLECHECK-LABEL: NoDeadStoreDebugValueAddr
176-
// DISABLECHECK: bb0
177-
// DISABLECHECK: store
178-
// DISABLECHECK: debug_value_addr
179-
sil hidden @NoDeadStoreDebugValueAddr : $@convention(thin) () -> () {
180-
bb0:
181-
%0 = alloc_stack $Int, var, name "a" // users: %3, %5
182-
%1 = integer_literal $Builtin.Int64, 1 // user: %2
183-
%2 = struct $Int (%1 : $Builtin.Int64) // user: %3
184-
store %2 to %0#1 : $*Int // id: %3
185-
debug_value_addr %0#1 : $*Int
186-
%4 = tuple () // user: %6
187-
dealloc_stack %0#0 : $*@local_storage Int // id: %5
188-
return %4 : $() // id: %6
189-
}
190-
191163
// CHECK-LABEL: sil @store_after_store
192164
// CHECK: alloc_box
193-
// CHECK-NEXT: store
194-
// CHECK-NEXT: tuple
165+
// CHECK: store
166+
// CHECK-NOT: store
195167
// CHECK: return
196168
sil @store_after_store : $@convention(thin) (@owned B) -> () {
197169
bb0(%0 : $B):
@@ -299,6 +271,26 @@ bb2:
299271
return %9999 : $()
300272
}
301273

274+
// We can not remove the local store as the debug_value_addr could
275+
// be turned to a debug_value and thus act as a read on the memory
276+
// location..
277+
//
278+
// CHECK-LABEL: blocking_debug_value_addr_on_dead_store
279+
// CHECK: bb0
280+
// CHECK: store
281+
// CHECK: debug_value_addr
282+
sil hidden @blocking_debug_value_addr_on_dead_store : $@convention(thin) () -> () {
283+
bb0:
284+
%0 = alloc_stack $Int, var, name "a" // users: %3, %5
285+
%1 = integer_literal $Builtin.Int64, 1 // user: %2
286+
%2 = struct $Int (%1 : $Builtin.Int64) // user: %3
287+
store %2 to %0#1 : $*Int // id: %3
288+
debug_value_addr %0#1 : $*Int
289+
%4 = tuple () // user: %6
290+
dealloc_stack %0#0 : $*@local_storage Int // id: %5
291+
return %4 : $() // id: %6
292+
}
293+
302294
// CHECK-LABEL: sil @test_read_dependence_allows_forwarding : $@convention(thin) (@inout A, A) -> A {
303295
// CHECK: bb0
304296
// CHECK-NEXT: store
@@ -382,25 +374,14 @@ bb3:
382374
return %9999 : $()
383375
}
384376

385-
//////////////////////////////////////////////
386-
// Tests for GlobalDeadStoreElimination.cpp //
387-
//////////////////////////////////////////////
388-
389377
// We should be able to remove the store in bb0, but we currently
390378
// cant due to deficiency in alias analysis.
391379
//
392380
// CHECK-LABEL: DeadStoreWithAliasingBasesSimpleClass
393381
// CHECK: bb0([[RET0:%.+]] : $Bool):
394-
// CHECK-NEXT: [[RET1:%.+]] = alloc_ref
395-
// CHECK-NEXT: [[RET2:%.+]] = alloc_stack
396-
// CHECK-NEXT: store [[RET1:%.+]] to [[RET2:%.+]]
397-
// CHECK-NEXT: [[RET2:%.+]] = load
398-
// CHECK-NEXT: [[RET3:%.+]] = integer_literal
399-
// CHECK-NEXT: [[RET4:%.+]] = struct $Int
400-
// CHECK-NEXT: [[RET5:%.+]] = ref_element_addr
401-
// CHECK-NEXT: store [[RET4:%.+]] to [[RET5:%.+]]
402-
// CHECK-NEXT: [[RET6:%.+]] = ref_element_addr
403-
// CHECK-NEXT: store [[RET4:%.+]] to [[RET6:%.+]]
382+
// CHECK: store
383+
// CHECK: store
384+
// CHECK: store
404385
sil hidden @DeadStoreWithAliasingBasesSimpleClass : $@convention(thin) (Bool) -> () {
405386
bb0(%0 : $Bool):
406387
%1 = alloc_ref $foo // users: %3, %6
@@ -413,9 +394,6 @@ bb0(%0 : $Bool):
413394
store %5 to %6 : $*Int // id: %7
414395
%9 = ref_element_addr %8 : $foo, #foo.a // user: %12
415396
store %5 to %9 : $*Int // id: %12
416-
br bb1 // id: %13
417-
418-
bb1: // Preds: bb0
419397
%14 = tuple () // user: %16
420398
dealloc_stack %2#0 : $*@local_storage foo // id: %15
421399
return %14 : $() // id: %16
@@ -424,14 +402,14 @@ bb1: // Preds: bb0
424402
// Remove dead stores in if-else block on a simple struct as there are stores
425403
// in the joint block.
426404
//
427-
// CHECK-LABEL: DeadStoreInIfElseBlockSimpleStruct
405+
// CHECK-LABEL: diamond_control_flow_dead_store
428406
// CHECK: bb1:
429407
// CHECK-NOT: store
430408
// CHECK: br
431409
// CHECK: bb2:
432410
// CHECK-NOT: store
433411
// CHECK: br
434-
sil hidden @DeadStoreInIfElseBlockSimpleStruct : $@convention(thin) (Bool, Int) -> () {
412+
sil hidden @diamond_control_flow_dead_store : $@convention(thin) (Bool, Int) -> () {
435413
bb0(%0 : $Bool, %1 : $Int):
436414
%2 = alloc_stack $S1 // users: %6, %11, %16, %21, %24
437415
// function_ref S1_init
@@ -965,13 +943,11 @@ bb4: // Preds: bb2 bb3
965943

966944
// Can not remove partially dead store in split block for simple class.
967945
//
968-
// CHECK-LABEL: PartialDeadStoreInSplitSimpleClass
946+
// CHECK-LABEL: partial_dead_store_simple_class
969947
// CHECK: bb1:
970-
// CHECK-NEXT: [[RET0:%.+]] = integer_literal $Builtin.Int64, 10
971-
// CHECK-NEXT: [[RET1:%.+]] = struct $Int ([[RET0:%.+]] : $Builtin.Int64)
972-
// CHECK-NEXT: [[RET2:%.+]] = ref_element_addr
973-
// CHECK-NEXT: store [[RET1:%.+]] to [[RET2:%.+]]
974-
sil hidden @PartialDeadStoreInSplitSimpleClass : $@convention(thin) (Bool) -> () {
948+
// CHECK: store
949+
// CHECK: cond_br
950+
sil hidden @partial_dead_store_simple_class : $@convention(thin) (Bool) -> () {
975951
bb0(%0 : $Bool):
976952
%1 = alloc_stack $foo // users: %3, %20
977953
%2 = alloc_ref $foo // users: %3, %7, %14, %18
@@ -1006,13 +982,11 @@ bb4: // Preds: bb2 bb3
1006982

1007983
// Can not remove partially dead store in split block for simple class.
1008984
//
1009-
// CHECK-LABEL: PartialDeadStoreInSplitWithFunctionCallSimpleClass
985+
// CHECK-LABEL: partial_dead_store_with_function_call
1010986
// CHECK: bb1:
1011-
// CHECK-NEXT: [[RET0:%.+]] = integer_literal $Builtin.Int64, 10
1012-
// CHECK-NEXT: [[RET1:%.+]] = struct $Int ([[RET0:%.+]] : $Builtin.Int64)
1013-
// CHECK-NEXT: [[RET2:%.+]] = ref_element_addr
1014-
// CHECK-NEXT: store [[RET1:%.+]] to [[RET2:%.+]]
1015-
sil hidden @PartialDeadStoreInSplitWithFunctionCallSimpleClass : $@convention(thin) (Bool) -> () {
987+
// CHECK: store
988+
// CHECK: cond_br
989+
sil hidden @partial_dead_store_with_function_call : $@convention(thin) (Bool) -> () {
1016990
bb0(%0 : $Bool):
1017991
%1 = alloc_stack $foo // users: %8, %36
1018992
%3 = alloc_ref $foo // users: %6, %8, %11, %14, %17, %19, %22, %25, %27, %30, %33, %34

0 commit comments

Comments
 (0)