Skip to content

Commit b548a6e

Browse files
committed
Enable RLE tests for TBAA and add rebind_memory test.
1 parent 90c0c8b commit b548a6e

File tree

2 files changed

+86
-71
lines changed

2 files changed

+86
-71
lines changed

test/SILOptimizer/redundant_load_elim_ossa.sil

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct A {
3737
var i : Builtin.Int32
3838
}
3939

40+
struct A2 {
41+
var i : Builtin.Int32
42+
}
43+
4044
struct AA {
4145
var a : A
4246
var i : Builtin.Int32
@@ -1348,3 +1352,85 @@ bb0:
13481352
return %5 : $Int32
13491353
}
13501354

1355+
// CHECK: sil @tbaa_class_alias_nonclass
1356+
// CHECK: strong_retain [[RET:%[0-9]+]]
1357+
// CHECK: strong_retain [[RET]]
1358+
// CHECK: return
1359+
sil @tbaa_class_alias_nonclass : $@convention(thin) (@owned B, @inout Agg1) -> () {
1360+
bb0(%0 : $B, %1 : $*Agg1):
1361+
%2 = alloc_box $<τ_0_0> { var τ_0_0 } <B>
1362+
%2a = project_box %2 : $<τ_0_0> { var τ_0_0 } <B>, 0
1363+
%3 = load %1 : $*Agg1
1364+
store %3 to %1 : $*Agg1
1365+
%5 = load %2a : $*B
1366+
store %3 to %1 : $*Agg1
1367+
%7 = load %2a : $*B
1368+
strong_retain %5 : $B //%7 and %5 should really be one load.
1369+
strong_retain %7 : $B
1370+
%10 = tuple()
1371+
return %10 : $()
1372+
}
1373+
1374+
// TODO: When RLE uses TBAA it should remove the second load.
1375+
//
1376+
// CHECK: sil @tbaa_struct
1377+
// CHECK: load
1378+
// CHECK: store
1379+
// CHECK: load
1380+
// CHECK: return
1381+
sil @tbaa_struct : $@convention(thin) (Builtin.RawPointer, A2) -> (A, A) {
1382+
bb0(%0 : $Builtin.RawPointer, %1 : $A2):
1383+
%2 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A
1384+
%3 = load %2 : $*A
1385+
%5 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A2
1386+
store %1 to %5 : $*A2
1387+
%20 = load %2 : $*A
1388+
%30 = tuple(%3 : $A, %20 : $A)
1389+
return %30 : $(A, A)
1390+
}
1391+
1392+
// TODO: Even with TBAA, RLE should not remove the second load.
1393+
//
1394+
// CHECK: sil @tbaa_bind_memory
1395+
// CHECK: load
1396+
// CHECK: bind_memory
1397+
// CHECK: store
1398+
// CHECK: bind_memory
1399+
// CHECK: load
1400+
// CHECK: return
1401+
sil @tbaa_bind_memory : $@convention(thin) (Builtin.RawPointer, A2) -> (A, A) {
1402+
bb0(%0 : $Builtin.RawPointer, %1 : $A2):
1403+
%2 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A
1404+
%3 = load %2 : $*A
1405+
%4 = integer_literal $Builtin.Word, 1
1406+
%5 = bind_memory %0 : $Builtin.RawPointer, %4 : $Builtin.Word to $A2
1407+
%6 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A2
1408+
store %1 to %6 : $*A2
1409+
%8 = bind_memory %0 : $Builtin.RawPointer, %4 : $Builtin.Word to $A
1410+
%20 = load %2 : $*A
1411+
%30 = tuple(%3 : $A, %20 : $A)
1412+
return %30 : $(A, A)
1413+
}
1414+
1415+
// TODO: Even with TBAA, RLE should not remove the second load.
1416+
//
1417+
// CHECK: sil @tbaa_rebind_memory
1418+
// CHECK: load
1419+
// CHECK: bind_memory
1420+
// CHECK: store
1421+
// CHECK: bind_memory
1422+
// CHECK: load
1423+
// CHECK: return
1424+
sil @tbaa_rebind_memory : $@convention(thin) (Builtin.RawPointer, A2) -> (A, A) {
1425+
bb0(%0 : $Builtin.RawPointer, %1 : $A2):
1426+
%2 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A
1427+
%3 = load %2 : $*A
1428+
%4 = integer_literal $Builtin.Word, 1
1429+
%5 = bind_memory %0 : $Builtin.RawPointer, %4 : $Builtin.Word to $A2
1430+
%6 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A2
1431+
store %1 to %6 : $*A2
1432+
%8 = rebind_memory %0 : $Builtin.RawPointer to %5 : $Builtin.Word
1433+
%20 = load %2 : $*A
1434+
%30 = tuple(%3 : $A, %20 : $A)
1435+
return %30 : $(A, A)
1436+
}

test/SILOptimizer/redundant_load_elim_with_casts.sil

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -53,77 +53,6 @@ sil @use_a : $@convention(thin) (@in A) -> ()
5353
sil @escaped_a_ptr : $@convention(thin) () -> @out A
5454
sil @escaped_a : $@convention(thin) () -> Builtin.RawPointer
5555

56-
57-
struct Agg2 {
58-
var t : (Builtin.Int64, Builtin.Int32)
59-
}
60-
61-
struct Agg1 {
62-
var a : Agg2
63-
}
64-
65-
struct Wrapper {
66-
var value : Builtin.Int32
67-
}
68-
69-
// CHECK-FUTURE: sil @tbaa_class_alias_nonclass
70-
// CHECK: strong_retain [[RET:%[0-9]+]]
71-
// CHECK: strong_retain [[RET]]
72-
// CHECK: return
73-
sil @tbaa_class_alias_nonclass : $@convention(thin) (@owned B, @inout Agg1) -> () {
74-
bb0(%0 : $B, %1 : $*Agg1):
75-
%2 = alloc_box $<τ_0_0> { var τ_0_0 } <B>
76-
%2a = project_box %2 : $<τ_0_0> { var τ_0_0 } <B>, 0
77-
%3 = load %1 : $*Agg1
78-
store %3 to %1 : $*Agg1
79-
%5 = load %2a : $*B
80-
store %3 to %1 : $*Agg1
81-
%7 = load %2a : $*B
82-
strong_retain %5 : $B //%7 and %5 should really be one load.
83-
strong_retain %7 : $B
84-
%10 = tuple()
85-
return %10 : $()
86-
}
87-
88-
// FIXME: When RLE uses TBAA it should remove the second load.
89-
// CHECK-FUTURE: sil @tbaa_struct
90-
// CHECK: load
91-
// CHECK: store
92-
// CHECK: load
93-
// CHECK: return
94-
sil @tbaa_struct : $@convention(thin) (Builtin.RawPointer, A2) -> (A, A) {
95-
bb0(%0 : $Builtin.RawPointer, %1 : $A2):
96-
%2 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A
97-
%3 = load %2 : $*A
98-
%5 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A2
99-
store %1 to %5 : $*A2
100-
%20 = load %2 : $*A
101-
%30 = tuple(%3 : $A, %20 : $A)
102-
return %30 : $(A, A)
103-
}
104-
105-
// Even with TBAA, RLE should not remove the second load.
106-
// CHECK-FUTURE: sil @tbaa_bind_memory
107-
// CHECK: load
108-
// CHECK: bind_memory
109-
// CHECK: store
110-
// CHECK: bind_memory
111-
// CHECK: load
112-
// CHECK: return
113-
sil @tbaa_bind_memory : $@convention(thin) (Builtin.RawPointer, A2) -> (A, A) {
114-
bb0(%0 : $Builtin.RawPointer, %1 : $A2):
115-
%2 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A
116-
%3 = load %2 : $*A
117-
%4 = integer_literal $Builtin.Word, 1
118-
%5 = bind_memory %0 : $Builtin.RawPointer, %4 : $Builtin.Word to $A2
119-
%6 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*A2
120-
store %1 to %6 : $*A2
121-
%8 = bind_memory %0 : $Builtin.RawPointer, %4 : $Builtin.Word to $A
122-
%20 = load %2 : $*A
123-
%30 = tuple(%3 : $A, %20 : $A)
124-
return %30 : $(A, A)
125-
}
126-
12756
// *NOTE* This does not handle raw pointer since raw pointer is only layout compatible with heap references.
12857
// CHECK-FUTURE: sil @store_to_load_forward_unchecked_addr_cast_struct : $@convention(thin) (Optional<A>) -> () {
12958
// CHECK: bb0([[INPUT:%[0-9]+]]

0 commit comments

Comments
 (0)