 GENERIC: update-insn ( insn -- keep? )
 
 M: ##copy update-insn drop f ;
+
+M: ##phi update-insn
+    dup dst>> copies get key? [ drop f ] [ call-next-method ] if ;
 
 M: insn update-insn rename-insn-uses t ;
 

SYMBOL: copies

: resolve ( vreg -- vreg )
    [ copies get at ] keep or ;

: record-copy ( ##copy -- )
    [ src>> resolve ] [ dst>> ] bi copies get set-at ; inline

<PRIVATE



M: ##copy visit-insn record-copy ;

M: ##phi visit-insn
    [ dst>> ] [ inputs>> values [ resolve ] map ] bi
    dup all-equal? [ first (record-copy) ] [ 2drop ] if ;

M: insn visit-insn drop ;

