Skip to content

Commit db4994b

Browse files
author
Joe Shajrawi
authored
Merge pull request swiftlang#23309 from shajrawi/licm_static
[exclusivity] teach LICM how to handle static markers
2 parents b549239 + d80f2d2 commit db4994b

File tree

2 files changed

+109
-7
lines changed

2 files changed

+109
-7
lines changed

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,6 @@ static bool analyzeBeginAccess(BeginAccessInst *BI,
554554
WriteSet &MayWrites,
555555
AccessedStorageAnalysis *ASA,
556556
DominanceInfo *DT) {
557-
if (BI->getEnforcement() != SILAccessEnforcement::Dynamic) {
558-
return false;
559-
}
560-
561557
const AccessedStorage &storage =
562558
findAccessedStorageNonNested(BI->getSource());
563559
if (!storage) {
@@ -654,9 +650,7 @@ void LoopTreeOptimization::analyzeCurrentLoop(
654650
case SILInstructionKind::BeginAccessInst: {
655651
auto *BI = dyn_cast<BeginAccessInst>(&Inst);
656652
assert(BI && "Expected a Begin Access");
657-
if (BI->getEnforcement() == SILAccessEnforcement::Dynamic) {
658-
BeginAccesses.push_back(BI);
659-
}
653+
BeginAccesses.push_back(BI);
660654
checkSideEffects(Inst, MayWrites);
661655
break;
662656
}

test/SILOptimizer/licm_exclusivity.sil

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ var globalX: X
1616

1717
sil_global hidden @globalX : $X
1818

19+
var globalY: X
20+
21+
sil_global hidden @globalY : $X
22+
1923

2024
sil hidden_external [global_init] @globalAddressor : $@convention(thin) () -> Builtin.RawPointer
2125

@@ -142,3 +146,107 @@ bb2:
142146
%10 = tuple ()
143147
return %10 : $()
144148
}
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

Comments
 (0)