Skip to content

Commit c516a1c

Browse files
committed
Retain the [no_nested_conflict] flag when merging.
The optimization already proves that there are no potential conflicts between the two merged scopes, so merging them can't introduce a new nested conflict.
1 parent 4887d17 commit c516a1c

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

lib/SILOptimizer/Transforms/AccessEnforcementOpts.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,10 @@ static bool mergeAccesses(
10891089
LLVM_DEBUG(llvm::dbgs()
10901090
<< "Merging: " << *childIns << " into " << *parentIns << "\n");
10911091

1092-
// Change the no nested conflict of parent:
1093-
// should be the worst case scenario: we might merge to non-conflicting
1094-
// scopes to a conflicting one. f the new result does not conflict,
1095-
// a later on pass will remove the flag
1096-
parentIns->setNoNestedConflict(false);
1092+
// Change the no nested conflict of parent if the child has a nested
1093+
// conflict.
1094+
if (!childIns->hasNoNestedConflict())
1095+
parentIns->setNoNestedConflict(false);
10971096

10981097
// remove end accesses and create new ones that cover bigger scope:
10991098
mergeEndAccesses(parentIns, childIns);

test/SILOptimizer/access_enforcement_opts.sil

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ bb0(%0 : $*Int64):
382382
// CHECK-LABEL: sil @testInoutReadEscapeRead : $@convention(thin) () -> () {
383383
// CHECK: [[BOX:%.*]] = alloc_box ${ var Int64 }, var, name "x"
384384
// CHECK: [[BOXADR:%.*]] = project_box [[BOX]] : ${ var Int64 }, 0
385-
// CHECK: begin_access [read] [static] [[BOXADR]] : $*Int64
385+
// CHECK: begin_access [read] [static] [no_nested_conflict] [[BOXADR]] : $*Int64
386386
// CHECK-NOT: begin_access
387387
// CHECK-LABEL: } // end sil function 'testInoutReadEscapeRead'
388388
sil @testInoutReadEscapeRead : $@convention(thin) () -> () {
@@ -951,7 +951,7 @@ bb0(%0 : $*Int64, %1 : $@callee_guaranteed () -> ()):
951951
//
952952
// CHECK-LABEL: sil @testOldToNewMapRead : $@convention(thin) () -> () {
953953
// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
954-
// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [read] [dynamic] [[GLOBAL]] : $*X
954+
// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [read] [dynamic] [no_nested_conflict] [[GLOBAL]] : $*X
955955
// CHECK-NEXT: load [[BEGIN]] : $*X
956956
// CHECK-NEXT: load [[BEGIN]] : $*X
957957
// CHECK-NEXT: load [[BEGIN]] : $*X
@@ -981,7 +981,7 @@ bb0:
981981
//
982982
// CHECK-LABEL: sil @testOldToNewMapReadMayRelease : $@convention(thin) () -> () {
983983
// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
984-
// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [read] [dynamic] [[GLOBAL]] : $*X
984+
// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [read] [dynamic] [no_nested_conflict] [[GLOBAL]] : $*X
985985
// CHECK-NEXT: load [[BEGIN]] : $*X
986986
// CHECK-NEXT: load [[BEGIN]] : $*X
987987
// CHECK-NEXT: end_access [[BEGIN]] : $*X
@@ -1293,7 +1293,7 @@ bb4:
12931293
// CHECK-NEXT: load [[BEGIN2]] : $*X
12941294
// CHECK-NEXT: end_access [[BEGIN2]] : $*X
12951295
// CHECK-NEXT: br bb3
1296-
// CHECK: [[BEGIN3:%.*]] = begin_access [read] [dynamic] [[GLOBAL]] : $*X
1296+
// CHECK: [[BEGIN3:%.*]] = begin_access [read] [dynamic] [no_nested_conflict] [[GLOBAL]] : $*X
12971297
// CHECK-NEXT: load [[BEGIN3]] : $*X
12981298
// CHECK: br bb4
12991299
// CHECK: load [[BEGIN3]] : $*X
@@ -1439,7 +1439,7 @@ bb0(%0 : $RefElemNoConflictClass):
14391439
// CHECK-NEXT: load [[BEGIN2]] : $*X
14401440
// CHECK-NEXT: end_access [[BEGIN2]] : $*X
14411441
// CHECK-NEXT: br bb3
1442-
// CHECK: [[BEGIN3:%.*]] = begin_access [read] [dynamic] [[GLOBAL]] : $*X
1442+
// CHECK: [[BEGIN3:%.*]] = begin_access [read] [dynamic] [no_nested_conflict] [[GLOBAL]] : $*X
14431443
// CHECK-NEXT: load [[BEGIN3]] : $*X
14441444
// CHECK: br bb4
14451445
// CHECK: load [[BEGIN3]] : $*X
@@ -1563,7 +1563,7 @@ bb0:
15631563
// CHECK: bb2
15641564
// CHECK: br bb3([[GLOBAL]] : $*X)
15651565
// CHECK: bb3([[GLOBALPHI:%.*]] : $*X):
1566-
// CHECK: [[BEGIN:%.*]] = begin_access [read] [dynamic] [[GLOBALPHI]] : $*X
1566+
// CHECK: [[BEGIN:%.*]] = begin_access [read] [dynamic] [no_nested_conflict] [[GLOBALPHI]] : $*X
15671567
// CHECK-NEXT: load
15681568
// CHECK-NEXT: load
15691569
// CHECK-NEXT: end_access [[BEGIN]] : $*X
@@ -1655,7 +1655,7 @@ bb0(%0 : $TestClass):
16551655
//
16561656
// CHECK-LABEL: sil @testNestedReadMerging : $@convention(thin) () -> () {
16571657
// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
1658-
// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [read] [dynamic] [[GLOBAL]] : $*X
1658+
// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [read] [dynamic] [no_nested_conflict] [[GLOBAL]] : $*X
16591659
// CHECK-NEXT: load [[BEGIN]] : $*X
16601660
// CHECK-NEXT: load [[BEGIN]] : $*X
16611661
// CHECK-NEXT: [[BEGIN2:%.*]] = begin_access [read] [dynamic] [no_nested_conflict] [[GLOBAL]] : $*X

0 commit comments

Comments
 (0)