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.value-numbering
|
||||
compiler.cfg.dce
|
||||
compiler.cfg.branch-folding
|
||||
compiler.cfg.write-barrier
|
||||
compiler.cfg.liveness
|
||||
compiler.cfg.rpo
|
||||
|
@ -24,6 +25,8 @@ SYMBOL: check-optimizer?
|
|||
] when ;
|
||||
|
||||
: optimize-cfg ( cfg -- cfg' )
|
||||
! Note that compute-predecessors has to be called several times.
|
||||
! The passes that need this document it.
|
||||
[
|
||||
optimize-tail-calls
|
||||
compute-predecessors
|
||||
|
@ -34,6 +37,8 @@ SYMBOL: check-optimizer?
|
|||
compute-liveness
|
||||
alias-analysis
|
||||
value-numbering
|
||||
fold-branches
|
||||
compute-predecessors
|
||||
eliminate-dead-code
|
||||
eliminate-write-barriers
|
||||
eliminate-phis
|
||||
|
|
Loading…
Reference in New Issue