Skip to content

Commit 0b784b1

Browse files
committed
[RLE-DSE] Add more LIT tests.
1 parent 9beeb56 commit 0b784b1

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

test/SILPasses/redundantloadelimination.sil

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,22 @@ enum XYZ {
8787
case C(Int32)
8888
}
8989

90+
struct TwoField {
91+
var a: Int
92+
var b: Int
93+
init(a: Int, b: Int)
94+
init()
95+
}
96+
9097

9198
sil @use : $@convention(thin) (Builtin.Int32) -> ()
9299
sil @use_64 : $@convention(thin) (Builtin.Int64) -> ()
93100
sil @use_2_64 : $@convention(thin) (Builtin.Int64, Builtin.Int64) -> ()
94101
sil @use_a : $@convention(thin) (A) -> ()
102+
sil @use_twofield : $@convention(thin) (TwoField) -> ()
95103
sil @escaped_a_ptr : $@convention(thin) (@out A) -> ()
96104
sil @escaped_a : $@convention(thin) () -> Builtin.RawPointer
105+
sil @init_twofield : $@convention(thin) (@thin TwoField.Type) -> TwoField
97106

98107
// DISABLE this test for now. it seems DCE is not getting rid of the load in bb8 after the RLE happens.
99108
//
@@ -631,4 +640,66 @@ bb2:
631640
return %9999 : $()
632641
}
633642

643+
// CHECK-LABEL: store_and_load_to_load_branches_diamond
644+
// CHECK: bb3
645+
// CHECK-NOT: load
646+
// CHECK: return
647+
sil @store_and_load_to_load_branches_diamond : $@convention(thin) (@inout Builtin.Int32) -> () {
648+
// %0 // users: %1, %4, %9, %11, %16, %21
649+
bb0(%0 : $*Builtin.Int32):
650+
cond_br undef, bb1, bb2 // id: %3
634651

652+
bb1: // Preds: bb0
653+
%1 = load %0 : $*Builtin.Int32 // user: %2
654+
br bb3 // id: %15
655+
656+
bb2: // Preds: bb0
657+
%5 = integer_literal $Builtin.Int32, 2
658+
store %5 to %0 : $*Builtin.Int32
659+
br bb3 // id: %20
660+
661+
bb3: // Preds: bb1 bb2
662+
%21 = load %0 : $*Builtin.Int32 // user: %23
663+
// function_ref use
664+
%22 = function_ref @use : $@convention(thin) (Builtin.Int32) -> () // user: %23
665+
%23 = apply %22(%21) : $@convention(thin) (Builtin.Int32) -> ()
666+
%24 = tuple () // user: %25
667+
return %24 : $() // id: %25
668+
}
669+
670+
// CHECK-LABEL: agg_and_field_store_branches_diamond
671+
// CHECK: bb3
672+
// CHECK-NOT: load
673+
// CHECK: return
674+
sil hidden @agg_and_field_store_branches_diamond : $@convention(thin) (Bool) -> () {
675+
bb0(%0 : $Bool):
676+
%1 = alloc_stack $TwoField // var x // users: %6, %11, %16, %21, %24
677+
%7 = struct_extract %0 : $Bool, #Bool.value // user: %8
678+
cond_br %7, bb1, bb2 // id: %8
679+
680+
bb1: // Preds: bb0
681+
%9 = integer_literal $Builtin.Int64, 10 // user: %10
682+
%10 = struct $Int (%9 : $Builtin.Int64) // user: %12
683+
%11 = struct_element_addr %1#1 : $*TwoField, #TwoField.a // user: %12
684+
store %10 to %11 : $*Int // id: %12
685+
%14 = integer_literal $Builtin.Int64, 20 // user: %15
686+
%15 = struct $Int (%14 : $Builtin.Int64) // user: %17
687+
%16 = struct_element_addr %1#1 : $*TwoField, #TwoField.b // user: %17
688+
store %15 to %16 : $*Int // id: %17
689+
br bb3 // id: %13
690+
691+
bb2: // Preds: bb0
692+
%3 = function_ref @init_twofield : $@convention(thin) (@thin TwoField.Type) -> TwoField // user: %5
693+
%4 = metatype $@thin TwoField.Type // user: %5
694+
%5 = apply %3(%4) : $@convention(thin) (@thin TwoField.Type) -> TwoField // user: %6
695+
store %5 to %1#1 : $*TwoField // id: %6
696+
br bb3 // id: %18
697+
698+
bb3: // Preds: bb1 bb2
699+
%99 = load %1#1 : $*TwoField // id: %6
700+
%991 = function_ref @use_twofield : $@convention(thin) (TwoField) -> () // user: %5
701+
%55 = apply %991(%99) : $@convention(thin) (TwoField) -> () // user: %6
702+
%23 = tuple () // user: %25
703+
dealloc_stack %1#0 : $*@local_storage TwoField // id: %24
704+
return %23 : $() // id: %25
705+
}

0 commit comments

Comments
 (0)