Skip to content

Commit 0ff2cae

Browse files
committed
SimplifyInstructions: don't remove empty access scopes
Empty access scopes can be a result of e.g. redundant-load-elimination. It's still important to keep those access scopes to detect access violations. Even if the load is physically not done anymore, in case of a conflicting access a propagated load is still wrong and must be detected. rdar://164571252
1 parent d1227fb commit 0ff2cae

File tree

3 files changed

+8
-52
lines changed

3 files changed

+8
-52
lines changed

lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ namespace {
6464
SILValue
6565
visitUncheckedTrivialBitCastInst(UncheckedTrivialBitCastInst *UTBCI);
6666
SILValue visitEndCOWMutationInst(EndCOWMutationInst *ECM);
67-
SILValue visitBeginAccessInst(BeginAccessInst *BAI);
6867
SILValue visitMetatypeInst(MetatypeInst *MTI);
6968
SILValue visitConvertFunctionInst(ConvertFunctionInst *cfi);
7069

@@ -419,16 +418,6 @@ visitUncheckedBitwiseCastInst(UncheckedBitwiseCastInst *UBCI) {
419418
return SILValue();
420419
}
421420

422-
SILValue InstSimplifier::visitBeginAccessInst(BeginAccessInst *BAI) {
423-
// Remove "dead" begin_access.
424-
if (llvm::all_of(BAI->getUses(), [](Operand *operand) -> bool {
425-
return isIncidentalUse(operand->getUser());
426-
})) {
427-
return BAI->getOperand();
428-
}
429-
return SILValue();
430-
}
431-
432421
SILValue InstSimplifier::visitConvertFunctionInst(ConvertFunctionInst *cfi) {
433422
// Eliminate round trip convert_function. Non round-trip is performed in
434423
// SILCombine.

test/SILOptimizer/sil_simplify_instrs.sil

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -325,34 +325,18 @@ public class B {
325325
deinit
326326
}
327327

328-
// simplify access markers
329-
sil @simplify_accesssil : $@convention(method) (@guaranteed A) -> () {
328+
// CHECK-LABEL: sil @dont_remove_empty_access_scopes : $@convention(method) (@guaranteed A) -> () {
329+
// CHECK: begin_access
330+
// CHECK-LABEL: } // end sil function 'dont_remove_empty_access_scopes'
331+
sil @dont_remove_empty_access_scopes : $@convention(method) (@guaranteed A) -> () {
330332
bb0(%0 : $A):
331333
%badr = ref_element_addr %0 : $A, #A.b
332334
%ba1 = begin_access [read] [dynamic] %badr : $*B
333335
end_access %ba1 : $*B
334-
%ba2 = begin_access [read] [dynamic] %badr : $*B
335-
fix_lifetime %ba2 : $*B
336-
end_access %ba2 : $*B
337-
%ba3 = begin_access [read] [dynamic] %badr : $*B
338-
%b = load %ba3 : $*B
339-
end_access %ba3 : $*B
340-
%xadr = ref_element_addr %b : $B, #B.x
341-
%xaccess = begin_access [read] [dynamic] %xadr : $*Int
342-
end_access %xaccess : $*Int
343-
344336
%r = tuple ()
345337
return %r : $()
346338
}
347339

348-
// CHECK-LABEL: sil @simplify_accesssil : $@convention(method) (@guaranteed A) -> () {
349-
// CHECK: bb0(%0 : $A):
350-
// CHECK-NEXT: [[ADR:%.*]] = ref_element_addr %0 : $A, #A.b
351-
// CHECK-NEXT: fix_lifetime [[ADR]] : $*B
352-
// CHECK-NEXT: %{{.*}} = tuple ()
353-
// CHECK-NEXT: return %{{.*}} : $()
354-
// CHECK-LABEL: } // end sil function 'simplify_accesssil'
355-
356340
// Test replacement of metatype instructions with metatype arguments.
357341
protocol SomeP {}
358342

test/SILOptimizer/sil_simplify_instrs_ossa.sil

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -370,31 +370,14 @@ public class B {
370370

371371
// simplify access markers
372372

373-
// CHECK-LABEL: sil [ossa] @simplify_accesssil : $@convention(method) (@guaranteed A) -> () {
374-
// CHECK: bb0(%0 : @guaranteed $A):
375-
// CHECK-NEXT: [[ADR:%.*]] = ref_element_addr %0 : $A, #A.b
376-
// CHECK-NEXT: fix_lifetime [[ADR]] : $*B
377-
// CHECK-NEXT: %{{.*}} = tuple ()
378-
// CHECK-NEXT: return %{{.*}} : $()
379-
// CHECK: } // end sil function 'simplify_accesssil'
380-
sil [ossa] @simplify_accesssil : $@convention(method) (@guaranteed A) -> () {
373+
// CHECK-LABEL: sil [ossa] @dont_remove_empty_access_scopes : $@convention(method) (@guaranteed A) -> () {
374+
// CHECK: begin_access
375+
// CHECK: } // end sil function 'dont_remove_empty_access_scopes'
376+
sil [ossa] @dont_remove_empty_access_scopes : $@convention(method) (@guaranteed A) -> () {
381377
bb0(%0 : @guaranteed $A):
382378
%badr = ref_element_addr %0 : $A, #A.b
383379
%ba1 = begin_access [read] [dynamic] %badr : $*B
384380
end_access %ba1 : $*B
385-
%ba2 = begin_access [read] [dynamic] %badr : $*B
386-
fix_lifetime %ba2 : $*B
387-
end_access %ba2 : $*B
388-
%ba3 = begin_access [read] [dynamic] %badr : $*B
389-
%b = load [copy] %ba3 : $*B
390-
end_access %ba3 : $*B
391-
%bb = begin_borrow %b : $B
392-
%xadr = ref_element_addr %bb : $B, #B.x
393-
%xaccess = begin_access [read] [dynamic] %xadr : $*Int
394-
end_access %xaccess : $*Int
395-
end_borrow %bb : $B
396-
destroy_value %b : $B
397-
398381
%r = tuple ()
399382
return %r : $()
400383
}

0 commit comments

Comments
 (0)