combine add-imm instructions into a single add
parent
2cd202d175
commit
ded1e29d2f
|
@ -1,12 +1,11 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel sequences layouts accessors combinators namespaces
|
USING: accessors combinators combinators.short-circuit
|
||||||
math fry
|
compiler.cfg.hats compiler.cfg.instructions
|
||||||
compiler.cfg.hats
|
compiler.cfg.value-numbering.expressions
|
||||||
compiler.cfg.instructions
|
|
||||||
compiler.cfg.value-numbering.graph
|
compiler.cfg.value-numbering.graph
|
||||||
compiler.cfg.value-numbering.simplify
|
compiler.cfg.value-numbering.simplify fry kernel layouts math
|
||||||
compiler.cfg.value-numbering.expressions ;
|
namespaces sequences ;
|
||||||
IN: compiler.cfg.value-numbering.rewrite
|
IN: compiler.cfg.value-numbering.rewrite
|
||||||
|
|
||||||
GENERIC: rewrite ( insn -- insn' )
|
GENERIC: rewrite ( insn -- insn' )
|
||||||
|
@ -19,8 +18,10 @@ M: ##mul-imm rewrite
|
||||||
|
|
||||||
: ##branch-t? ( insn -- ? )
|
: ##branch-t? ( insn -- ? )
|
||||||
dup ##compare-imm-branch? [
|
dup ##compare-imm-branch? [
|
||||||
[ cc>> cc/= eq? ]
|
{
|
||||||
[ src2>> \ f tag-number eq? ] bi and
|
[ cc>> cc/= eq? ]
|
||||||
|
[ src2>> \ f tag-number eq? ]
|
||||||
|
} 1&&
|
||||||
] [ drop f ] if ; inline
|
] [ drop f ] if ; inline
|
||||||
|
|
||||||
: rewrite-boolean-comparison? ( insn -- ? )
|
: rewrite-boolean-comparison? ( insn -- ? )
|
||||||
|
@ -47,9 +48,10 @@ M: ##mul-imm rewrite
|
||||||
|
|
||||||
: rewrite-tagged-comparison? ( insn -- ? )
|
: rewrite-tagged-comparison? ( insn -- ? )
|
||||||
#! Are we comparing two tagged fixnums? Then untag them.
|
#! Are we comparing two tagged fixnums? Then untag them.
|
||||||
[ src1>> vreg>expr tag-fixnum-expr? ]
|
{
|
||||||
[ src2>> tag-mask get bitand 0 = ]
|
[ src1>> vreg>expr tag-fixnum-expr? ]
|
||||||
bi and ; inline
|
[ src2>> tag-mask get bitand 0 = ]
|
||||||
|
} 1&& ; inline
|
||||||
|
|
||||||
: (rewrite-tagged-comparison) ( insn -- src1 src2 cc )
|
: (rewrite-tagged-comparison) ( insn -- src1 src2 cc )
|
||||||
[ src1>> vreg>expr in1>> vn>vreg ]
|
[ src1>> vreg>expr in1>> vn>vreg ]
|
||||||
|
@ -89,10 +91,11 @@ M: ##compare rewrite
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
: rewrite-redundant-comparison? ( insn -- ? )
|
: rewrite-redundant-comparison? ( insn -- ? )
|
||||||
[ src1>> vreg>expr compare-expr? ]
|
{
|
||||||
[ src2>> \ f tag-number = ]
|
[ src1>> vreg>expr compare-expr? ]
|
||||||
[ cc>> { cc= cc/= } memq? ]
|
[ src2>> \ f tag-number = ]
|
||||||
tri and and ; inline
|
[ cc>> { cc= cc/= } memq? ]
|
||||||
|
} 1&& ; inline
|
||||||
|
|
||||||
: rewrite-redundant-comparison ( insn -- insn' )
|
: rewrite-redundant-comparison ( insn -- insn' )
|
||||||
[ cc>> ] [ dst>> ] [ src1>> vreg>expr dup op>> ] tri {
|
[ cc>> ] [ dst>> ] [ src1>> vreg>expr dup op>> ] tri {
|
||||||
|
@ -114,4 +117,20 @@ M: ##compare-imm rewrite
|
||||||
] when
|
] when
|
||||||
] 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 ;
|
M: insn rewrite ;
|
||||||
|
|
Loading…
Reference in New Issue