Skip to content

Commit 658ce47

Browse files
committed
[sil-combine] Allow for storage casts to be cloned when rebasing an address def-use chain onto a new interior pointer
1 parent 8ae1b76 commit 658ce47

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,8 @@ class InteriorPointerAddressRebaseUseDefChainCloner
848848
}
849849

850850
SILValue visitStorageCast(SingleValueInstruction *cast, Operand *sourceOper) {
851-
assert(false && "unexpected storage cast on access path");
852-
return SILValue();
851+
// We are ok with cloning storage casts.
852+
return cloneProjection(cast, sourceOper);
853853
}
854854

855855
SILValue visitAccessProjection(SingleValueInstruction *projectedAddr,

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4953,3 +4953,35 @@ bb0(%0 : $*Klass, %1 : @owned $Klass):
49534953
return %9999 : $()
49544954
}
49554955

4956+
class KlassWithTailAllocatedElems {
4957+
var x : Builtin.NativeObject
4958+
init()
4959+
}
4960+
4961+
// CHECK-LABEL: sil [ossa] @unchecked_addr_cast_formation_handling_interior_pointer_rebase_of_cast : $@convention(thin) () -> Builtin.Word {
4962+
// CHECK-NOT: pointer_to_address
4963+
// CHECK-NOT: address_to_pointer
4964+
// CHECK: [[TAIL_ADDR:%.*]] = ref_tail_addr
4965+
// CHECK-NOT: pointer_to_address
4966+
// CHECK-NOT: address_to_pointer
4967+
// CHECK: [[CAST_RESULT:%.*]] = unchecked_addr_cast [[TAIL_ADDR]]
4968+
// CHECK-NOT: pointer_to_address
4969+
// CHECK-NOT: address_to_pointer
4970+
// CHECK: load [trivial] [[CAST_RESULT]]
4971+
// CHECK-NOT: pointer_to_address
4972+
// CHECK-NOT: address_to_pointer
4973+
// CHECK: } // end sil function 'unchecked_addr_cast_formation_handling_interior_pointer_rebase_of_cast'
4974+
sil [ossa] @unchecked_addr_cast_formation_handling_interior_pointer_rebase_of_cast : $@convention(thin) () -> Builtin.Word {
4975+
bb0:
4976+
%7 = integer_literal $Builtin.Word, 1
4977+
%8 = alloc_ref [tail_elems $(Builtin.NativeObject) * %7 : $Builtin.Word] $KlassWithTailAllocatedElems
4978+
%borrow = begin_borrow %8 : $KlassWithTailAllocatedElems
4979+
%addr = ref_tail_addr %borrow : $KlassWithTailAllocatedElems, $Builtin.NativeObject
4980+
%1 = address_to_pointer %addr : $*Builtin.NativeObject to $Builtin.RawPointer
4981+
end_borrow %borrow : $KlassWithTailAllocatedElems
4982+
%2 = pointer_to_address %1 : $Builtin.RawPointer to [strict] $*Builtin.Word
4983+
%3 = load [trivial] %2 : $*Builtin.Word
4984+
destroy_value %8 : $KlassWithTailAllocatedElems
4985+
return %3 : $Builtin.Word
4986+
}
4987+

0 commit comments

Comments
 (0)