compiler.cfg.branch-folding: fold away branches where both inputs are the same register. This results in 'push' being compiled slightly better
parent
fc595a7075
commit
3385e50c43
|
@ -0,0 +1,30 @@
|
||||||
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: accessors combinators.short-circuit kernel sequences vectors
|
||||||
|
compiler.cfg.instructions compiler.cfg.rpo ;
|
||||||
|
IN: compiler.cfg.branch-folding
|
||||||
|
|
||||||
|
! Fold comparisons where both inputs are the same. Predecessors must be
|
||||||
|
! recomputed after this
|
||||||
|
|
||||||
|
: fold-branch? ( bb -- ? )
|
||||||
|
instructions>> last {
|
||||||
|
[ ##compare-branch? ]
|
||||||
|
[ [ src1>> ] [ src2>> ] bi = ]
|
||||||
|
} 1&& ;
|
||||||
|
|
||||||
|
: chosen-successor ( bb -- succ )
|
||||||
|
[ instructions>> last cc>> { cc= cc<= cc>= } memq? 0 1 ? ]
|
||||||
|
[ successors>> ]
|
||||||
|
bi nth ;
|
||||||
|
|
||||||
|
: fold-branch ( bb -- )
|
||||||
|
dup chosen-successor 1vector >>successors
|
||||||
|
instructions>> [ pop* ] [ [ \ ##branch new-insn ] dip push ] bi ;
|
||||||
|
|
||||||
|
: fold-branches ( cfg -- cfg' )
|
||||||
|
dup [
|
||||||
|
dup fold-branch?
|
||||||
|
[ fold-branch ] [ drop ] if
|
||||||
|
] each-basic-block
|
||||||
|
f >>post-order ;
|
|
@ -9,6 +9,7 @@ compiler.cfg.branch-splitting
|
||||||
compiler.cfg.alias-analysis
|
compiler.cfg.alias-analysis
|
||||||
compiler.cfg.value-numbering
|
compiler.cfg.value-numbering
|
||||||
compiler.cfg.dce
|
compiler.cfg.dce
|
||||||
|
compiler.cfg.branch-folding
|
||||||
compiler.cfg.write-barrier
|
compiler.cfg.write-barrier
|
||||||
compiler.cfg.liveness
|
compiler.cfg.liveness
|
||||||
compiler.cfg.rpo
|
compiler.cfg.rpo
|
||||||
|
@ -24,6 +25,8 @@ SYMBOL: check-optimizer?
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
: optimize-cfg ( cfg -- cfg' )
|
: optimize-cfg ( cfg -- cfg' )
|
||||||
|
! Note that compute-predecessors has to be called several times.
|
||||||
|
! The passes that need this document it.
|
||||||
[
|
[
|
||||||
optimize-tail-calls
|
optimize-tail-calls
|
||||||
compute-predecessors
|
compute-predecessors
|
||||||
|
@ -34,6 +37,8 @@ SYMBOL: check-optimizer?
|
||||||
compute-liveness
|
compute-liveness
|
||||||
alias-analysis
|
alias-analysis
|
||||||
value-numbering
|
value-numbering
|
||||||
|
fold-branches
|
||||||
|
compute-predecessors
|
||||||
eliminate-dead-code
|
eliminate-dead-code
|
||||||
eliminate-write-barriers
|
eliminate-write-barriers
|
||||||
eliminate-phis
|
eliminate-phis
|
||||||
|
|
Loading…
Reference in New Issue