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

GENERIC: update-insn ( insn -- keep? )

M: ##copy update-insn drop f ;

M: insn update-insn rename-insn-uses t ;


SYMBOL: copies

: resolve ( vreg -- vreg )
    copies get ?at drop ;

: (record-copy) ( dst src -- )
    swap copies get set-at ; inline

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

<PRIVATE

