@@ -216,10 +216,7 @@ private extension FullApplySite {
216
216
/// destroy_addr %source
217
217
/// ```
218
218
private func combineWithDestroy( copy: CopyAddrInst , _ context: FunctionPassContext ) {
219
- guard !copy. isTakeOfSource,
220
- let destroy = copy. source. uses. users ( ofType: DestroyAddrInst . self) . first,
221
- destroy. parentBlock == copy. parentBlock
222
- else {
219
+ guard !copy. isTakeOfSource else {
223
220
return
224
221
}
225
222
@@ -228,20 +225,21 @@ private func combineWithDestroy(copy: CopyAddrInst, _ context: FunctionPassConte
228
225
defer { debugInsts. deinitialize ( ) }
229
226
230
227
for inst in InstructionList ( first: copy. next) {
231
- if inst == destroy {
232
- break
233
- }
234
- if let debugInst = inst as? DebugValueInst , debugInst. operand. value == copy. source {
235
- debugInsts. append ( debugInst)
236
- }
237
- if inst. mayReadOrWriteMemory {
228
+ switch inst {
229
+ case let destroy as DestroyAddrInst where destroy. destroyedAddress == copy. source:
230
+ copy. set ( isTakeOfSource: true , context)
231
+ context. erase ( instruction: destroy)
232
+ // Don't let debug info think that the value is still valid after the `copy [take]`.
233
+ context. erase ( instructions: debugInsts)
238
234
return
235
+ case let debugInst as DebugValueInst where debugInst. operand. value == copy. source:
236
+ debugInsts. append ( debugInst)
237
+ default :
238
+ if inst. mayReadOrWriteMemory {
239
+ return
240
+ }
239
241
}
240
242
}
241
- copy. set ( isTakeOfSource: true , context)
242
- context. erase ( instruction: destroy)
243
- // Don't let debug info think that the value is still valid after the `copy [take]`.
244
- context. erase ( instructions: debugInsts)
245
243
}
246
244
247
245
private extension Value {
0 commit comments