Skip to content

Commit a8aa22e

Browse files
committed
[6.1] Look through forwarding instructions while querying ownership root
While looking for ownership reference root to determine if address uses are within it's lifetime, skip through struct_extract/tuple_extract and other forwarding operations. Fixes rdar://142507746
1 parent 202de3a commit a8aa22e

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

include/swift/SIL/MemAccessUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,13 @@ class AccessBase : public AccessRepresentation {
638638
return findOwnershipReferenceRoot(getReference());
639639
}
640640

641+
/// Return the OSSA root of the reference being accessed
642+
/// looking through struct_extract, tuple_extract, etc.
643+
/// Precondition: isReference() is true.
644+
SILValue getOwnershipReferenceAggregate() const {
645+
return findOwnershipReferenceAggregate(getReference());
646+
}
647+
641648
/// Return the storage root of the reference being accessed.
642649
///
643650
/// Precondition: isReference() is true.

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ bool AddressOwnership::areUsesWithinLifetime(
10931093
if (!base.hasLocalOwnershipLifetime())
10941094
return true;
10951095

1096-
SILValue root = base.getOwnershipReferenceRoot();
1096+
SILValue root = base.getOwnershipReferenceAggregate();
10971097
BorrowedValue borrow(root);
10981098
if (borrow)
10991099
return borrow.areUsesWithinExtendedScope(uses, &deadEndBlocks);

test/SILOptimizer/cse_ossa_nontrivial.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,3 +1010,26 @@ bb0:
10101010
return %t : $()
10111011
}
10121012

1013+
// CHECK-LABEL: sil [ossa] @test_aggreate_tail_addr :
1014+
// CHECK: ref_tail_addr
1015+
// CHECK: ref_tail_addr
1016+
// CHECK-LABEL: } // end sil function 'test_aggreate_tail_addr'
1017+
sil [ossa] @test_aggreate_tail_addr : $@convention(thin) (@owned _NativeDictionary<Int, Klass>) -> () {
1018+
bb0(%0 : @owned $_NativeDictionary<Int, Klass>):
1019+
%1 = move_value [lexical] %0 : $_NativeDictionary<Int, Klass>
1020+
%2 = begin_borrow %1 : $_NativeDictionary<Int, Klass>
1021+
%3 = struct_extract %2 : $_NativeDictionary<Int, Klass>, #_NativeDictionary._storage
1022+
%4 = copy_value %3 : $__RawDictionaryStorage
1023+
%5 = ref_tail_addr %3 : $__RawDictionaryStorage, $_UnsafeBitset.Word
1024+
%6 = load [trivial] %5 : $*_UnsafeBitset.Word
1025+
end_borrow %2 : $_NativeDictionary<Int, Klass>
1026+
%8 = begin_borrow %4 : $__RawDictionaryStorage
1027+
%9 = ref_tail_addr %8 : $__RawDictionaryStorage, $_UnsafeBitset.Word
1028+
%10 = struct_element_addr %9 : $*_UnsafeBitset.Word, #_UnsafeBitset.Word.value
1029+
%11 = struct_element_addr %10 : $*UInt, #UInt._value
1030+
%12 = load [trivial] %11 : $*Builtin.Int64
1031+
end_borrow %8 : $__RawDictionaryStorage
1032+
destroy_value %4 : $__RawDictionaryStorage
1033+
destroy_value %1 : $_NativeDictionary<Int, Klass>
1034+
unreachable
1035+
}

0 commit comments

Comments
 (0)