@@ -114,8 +114,6 @@ SILInstruction *
114
114
SILCombiner::
115
115
visitPointerToAddressInst (PointerToAddressInst *PTAI) {
116
116
auto *F = PTAI->getFunction ();
117
- if (F->hasOwnership ())
118
- return nullptr ;
119
117
120
118
Builder.setCurrentDebugScope (PTAI->getDebugScope ());
121
119
@@ -127,11 +125,20 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
127
125
// (pointer-to-address strict (address-to-pointer %x))
128
126
// -> (unchecked_addr_cast %x)
129
127
if (PTAI->isStrict ()) {
130
- if (auto *ATPI = dyn_cast<AddressToPointerInst>(PTAI->getOperand ())) {
131
- return Builder.createUncheckedAddrCast (PTAI->getLoc (), ATPI->getOperand (),
132
- PTAI->getType ());
128
+ // We can not perform this optimization with ownership until we are able to
129
+ // handle issues around interior pointers and expanding borrow scopes.
130
+ if (!F->hasOwnership ()) {
131
+ if (auto *ATPI = dyn_cast<AddressToPointerInst>(PTAI->getOperand ())) {
132
+ return Builder.createUncheckedAddrCast (PTAI->getLoc (), ATPI->getOperand (),
133
+ PTAI->getType ());
134
+ }
133
135
}
134
136
}
137
+
138
+ // The rest of these canonicalizations optimize the code around
139
+ // pointer_to_address by leave in a pointer_to_address meaning that we do not
140
+ // need to worry about moving addresses out of interior pointer scopes.
141
+
135
142
// Turn this also into an index_addr. We generate this pattern after switching
136
143
// the Word type to an explicit Int32 or Int64 in the stdlib.
137
144
//
@@ -147,6 +154,10 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
147
154
// $Builtin.Word
148
155
// %114 = index_raw_pointer %100 : $Builtin.RawPointer, %113 : $Builtin.Word
149
156
// %115 = pointer_to_address %114 : $Builtin.RawPointer to [strict] $*Int
157
+ //
158
+ // This is safe for ownership since our final SIL still has a
159
+ // pointer_to_address meaning that we do not need to worry about interior
160
+ // pointers.
150
161
SILValue Distance;
151
162
SILValue TruncOrBitCast;
152
163
MetatypeInst *Metatype;
@@ -197,6 +208,7 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
197
208
}
198
209
}
199
210
}
211
+
200
212
// Turn:
201
213
//
202
214
// %stride = Builtin.strideof(T) * %distance
@@ -208,6 +220,9 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
208
220
// %addr = pointer_to_address %ptr, [strict] $T
209
221
// %result = index_addr %addr, %distance
210
222
//
223
+ // This is safe for ownership since our final SIL still has a
224
+ // pointer_to_address meaning that we do not need to worry about interior
225
+ // pointers.
211
226
BuiltinInst *Bytes = nullptr ;
212
227
if (match (PTAI->getOperand (),
213
228
m_IndexRawPointerInst (
0 commit comments