File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -400,10 +400,15 @@ bool TempRValueOptPass::extendAccessScopes(
400
400
if (endAccessToMove)
401
401
return false ;
402
402
// Is this the end of an access scope of the copy-source?
403
- if (!aa->isNoAlias (copySrc, endAccess->getSource ())) {
404
- assert (endAccess->getBeginAccess ()->getAccessKind () ==
405
- SILAccessKind::Read &&
406
- " a may-write end_access should not be in the copysrc lifetime" );
403
+ if (!aa->isNoAlias (copySrc, endAccess->getSource ()) &&
404
+
405
+ // There cannot be any aliasing modifying accesses within the liferange
406
+ // of the temporary, because we would have cought this in
407
+ // `getLastUseWhileSourceIsNotModified`.
408
+ // But there are cases where `AliasAnalysis::isNoAlias` is less precise
409
+ // than `AliasAnalysis::mayWriteToMemory`. Therefore, just ignore any
410
+ // non-read accesses.
411
+ endAccess->getBeginAccess ()->getAccessKind () == SILAccessKind::Read) {
407
412
408
413
// Don't move instructions beyond the block's terminator.
409
414
if (isa<TermInst>(lastUseInst))
Original file line number Diff line number Diff line change @@ -739,3 +739,23 @@ bb0(%0 : $*Klass):
739
739
%9999 = tuple()
740
740
return %9999 : $()
741
741
}
742
+
743
+ // CHECK-LABEL: sil @test_aliasing_modify_access
744
+ // CHECK: [[A:%.*]] = ref_element_addr [immutable] %0 : $Klass, #Klass.a
745
+ // CHECK-NOT: copy_addr
746
+ // CHECK: [[L:%.*]] = load [[A]]
747
+ // CHECK: return [[L]]
748
+ // CHECK: } // end sil function 'test_aliasing_modify_access'
749
+ sil @test_aliasing_modify_access : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> @owned String {
750
+ bb0(%0 : $Klass, %1 : $Klass):
751
+ %2 = ref_element_addr [immutable] %0 : $Klass, #Klass.a
752
+ %3 = alloc_stack $String
753
+ copy_addr %2 to [initialization] %3 : $*String
754
+ %4 = ref_element_addr %1 : $Klass, #Klass.a
755
+ %5 = begin_access [modify] [dynamic] [no_nested_conflict] %4 : $*String
756
+ end_access %5 : $*String
757
+ %323 = load %3 : $*String
758
+ destroy_addr %3 : $*String
759
+ dealloc_stack %3 : $*String
760
+ return %323 : $String
761
+ }
You can’t perform that action at this time.
0 commit comments