Skip to content

Commit 75814e9

Browse files
authored
Merge pull request #35182 from gottesmm/pr-c252916df0109f89d79567d71f8772ba7a2fdb73
[sil-combine] Enable dead alloc_ref elim for ossa.
2 parents f4722d2 + 04ffcaf commit 75814e9

File tree

3 files changed

+138
-55
lines changed

3 files changed

+138
-55
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,6 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
680680
}
681681

682682
SILInstruction *SILCombiner::visitAllocRefInst(AllocRefInst *AR) {
683-
if (AR->getFunction()->hasOwnership())
684-
return nullptr;
685-
686-
if (!AR)
687-
return nullptr;
688683
// Check if the only uses are deallocating stack or deallocating.
689684
SmallPtrSet<SILInstruction *, 16> ToDelete;
690685
bool HasNonRemovableUses = false;
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// RUN: %target-sil-opt -enable-objc-interop -enforce-exclusivity=none -enable-sil-verify-all %s -sil-combine -sil-combine-disable-alloc-stack-opts | %FileCheck %s
2+
3+
// This file tests routines in SILCombinerMiscVisitors.cpp
4+
5+
sil_stage canonical
6+
7+
import Builtin
8+
9+
class Klass {}
10+
11+
// We test both the ossa and non-ossa variants.
12+
//
13+
// CHECK-LABEL: sil [ossa] @fix_lifetime_promotion_ossa : $@convention(thin) (@owned Klass) -> () {
14+
// CHECK: bb0([[ARG:%.*]] :
15+
// CHECK: [[STACK:%.*]] = alloc_stack $Klass
16+
// CHECK: store [[ARG]] to [init] [[STACK]]
17+
// CHECK: [[BORROW:%.*]] = load_borrow [[STACK]]
18+
// CHECK: fix_lifetime [[BORROW]]
19+
// CHECK: end_borrow [[BORROW]]
20+
// CHECK: destroy_addr [[STACK]]
21+
// CHECK: dealloc_stack [[STACK]]
22+
// CHECK: } // end sil function 'fix_lifetime_promotion_ossa'
23+
sil [ossa] @fix_lifetime_promotion_ossa : $@convention(thin) (@owned Klass) -> () {
24+
bb0(%0 : @owned $Klass):
25+
%1 = alloc_stack $Klass
26+
store %0 to [init] %1 : $*Klass
27+
fix_lifetime %1 : $*Klass
28+
destroy_addr %1 : $*Klass
29+
dealloc_stack %1 : $*Klass
30+
%9999 = tuple()
31+
return %9999 : $()
32+
}
33+
34+
// CHECK-LABEL: sil @fix_lifetime_promotion : $@convention(thin) (@owned Klass) -> () {
35+
// CHECK: bb0([[ARG:%.*]] :
36+
// CHECK: [[STACK:%.*]] = alloc_stack $Klass
37+
// CHECK: store [[ARG]] to [[STACK]]
38+
// CHECK: [[BORROW:%.*]] = load [[STACK]]
39+
// CHECK: fix_lifetime [[BORROW]]
40+
// CHECK: destroy_addr [[STACK]]
41+
// CHECK: dealloc_stack [[STACK]]
42+
// CHECK: } // end sil function 'fix_lifetime_promotion'
43+
sil @fix_lifetime_promotion : $@convention(thin) (@owned Klass) -> () {
44+
bb0(%0 : $Klass):
45+
%1 = alloc_stack $Klass
46+
store %0 to %1 : $*Klass
47+
fix_lifetime %1 : $*Klass
48+
destroy_addr %1 : $*Klass
49+
dealloc_stack %1 : $*Klass
50+
%9999 = tuple()
51+
return %9999 : $()
52+
}
53+
54+
// Unused alloc-ref elim
55+
56+
// CHECK-LABEL: sil @remove_unused_alloc_ref :
57+
// CHECK-NOT: alloc_ref
58+
// CHECK-NOT: dealloc_ref
59+
// CHECK: } // end sil function 'remove_unused_alloc_ref'
60+
sil @remove_unused_alloc_ref : $@convention(thin) () -> () {
61+
bb0:
62+
%1 = alloc_ref $Klass
63+
dealloc_ref %1 : $Klass
64+
%3 = tuple ()
65+
return %3 : $()
66+
}
67+
68+
// CHECK-LABEL: sil [ossa] @remove_unused_alloc_ref_ossa :
69+
// CHECK-NOT: alloc_ref
70+
// CHECK-NOT: dealloc_ref
71+
// CHECK: } // end sil function 'remove_unused_alloc_ref_ossa'
72+
sil [ossa] @remove_unused_alloc_ref_ossa : $@convention(thin) () -> () {
73+
bb0:
74+
%1 = alloc_ref $Klass
75+
dealloc_ref %1 : $Klass
76+
%3 = tuple ()
77+
return %3 : $()
78+
}
79+
80+
// CHECK-LABEL: sil @remove_unused_alloc_ref_stack :
81+
// CHECK-NOT: alloc_ref
82+
// CHECK-NOT: set_deallocating
83+
// CHECK-NOT: dealloc_ref
84+
// CHECK: } // end sil function 'remove_unused_alloc_ref_stack'
85+
sil @remove_unused_alloc_ref_stack : $@convention(thin) () -> () {
86+
bb0:
87+
%1 = alloc_ref [stack] $Klass
88+
set_deallocating %1 : $Klass
89+
dealloc_ref [stack] %1 : $Klass
90+
%3 = tuple ()
91+
return %3 : $()
92+
}
93+
94+
// CHECK-LABEL: sil [ossa] @remove_unused_alloc_ref_stack_ossa :
95+
// CHECK-NOT: alloc_ref
96+
// CHECK-NOT: set_deallocating
97+
// CHECK-NOT: dealloc_ref
98+
// CHECK: } // end sil function 'remove_unused_alloc_ref_stack_ossa'
99+
sil [ossa] @remove_unused_alloc_ref_stack_ossa : $@convention(thin) () -> () {
100+
bb0:
101+
%1 = alloc_ref [stack] $Klass
102+
set_deallocating %1 : $Klass
103+
dealloc_ref [stack] %1 : $Klass
104+
%3 = tuple ()
105+
return %3 : $()
106+
}
107+
108+
// CHECK-LABEL: sil @remove_unused_alloc_ref_fixlifetime :
109+
// CHECK-NOT: alloc_ref
110+
// CHECK-NOT: set_deallocating
111+
// CHECK-NOT: dealloc_ref
112+
// CHECK-NOT: fix_lifetime
113+
// CHECK: } // end sil function 'remove_unused_alloc_ref_fixlifetime'
114+
sil @remove_unused_alloc_ref_fixlifetime : $@convention(thin) () -> () {
115+
bb0:
116+
%1 = alloc_ref [stack] $Klass
117+
set_deallocating %1 : $Klass
118+
fix_lifetime %1 : $Klass
119+
dealloc_ref [stack] %1 : $Klass
120+
%3 = tuple ()
121+
return %3 : $()
122+
}
123+
124+
// CHECK-LABEL: sil [ossa] @remove_unused_alloc_ref_fixlifetime_ossa :
125+
// CHECK-NOT: alloc_ref
126+
// CHECK-NOT: set_deallocating
127+
// CHECK-NOT: dealloc_ref
128+
// CHECK-NOT: fix_lifetime
129+
// CHECK: } // end sil function 'remove_unused_alloc_ref_fixlifetime_ossa'
130+
sil [ossa] @remove_unused_alloc_ref_fixlifetime_ossa : $@convention(thin) () -> () {
131+
bb0:
132+
%1 = alloc_ref [stack] $Klass
133+
set_deallocating %1 : $Klass
134+
fix_lifetime %1 : $Klass
135+
dealloc_ref [stack] %1 : $Klass
136+
%3 = tuple ()
137+
return %3 : $()
138+
}

test/SILOptimizer/sil_combine_misc_visitor_opts_ossa.sil

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)