 : flip-comparison ( insn -- insn' )
     [ dst>> ]
     [ src2>> ]
-    [ src1>> vreg>vn vn>constant ] tri
+    [ src1>> vreg>constant ] tri
     cc= i \ ##compare-imm new-insn ;
 
 M: ##compare rewrite

        ] when
    ] when ;

: combine-add-imm? ( insn -- ? )
    {
        [ src1>> vreg>expr op>> \ ##add-imm = ]
        [ src2>> number? ]
    } 1&& ;

: combine-add-imm ( dst src n -- insn )
    [ vreg>expr [ in1>> vn>vreg ] [ in2>> vn>constant ] bi ] dip
    + \ ##add-imm new-insn ;

M: ##add-imm rewrite
    dup combine-add-imm? [
        [ dst>> ] [ src1>> ] [ src2>> ] tri combine-add-imm
        dup number-values
    ] when ;

M: insn rewrite ;

compiler.cfg.value-numbering.expressions
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.simplify fry kernel layouts math
namespaces sequences cpu.architecture math.bitwise locals ;
IN: compiler.cfg.value-numbering.rewrite

GENERIC: rewrite ( insn -- insn' )

M: insn rewrite ;

: ##branch-t? ( insn -- ? )
    dup ##compare-imm-branch? [
