@@ -216,10 +216,7 @@ private extension FullApplySite {
216216/// destroy_addr %source
217217/// ```
218218private 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 {
223220 return
224221 }
225222
@@ -228,20 +225,21 @@ private func combineWithDestroy(copy: CopyAddrInst, _ context: FunctionPassConte
228225 defer { debugInsts. deinitialize ( ) }
229226
230227 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)
238234 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+ }
239241 }
240242 }
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)
245243}
246244
247245private extension Value {
0 commit comments