compiler.cfg.value-numbering: merge 'simplify' pass into 'rewrite'

db4
Slava Pestov 2010-04-24 02:38:43 -04:00
parent 378c2b2a46
commit f14f2cbdab
12 changed files with 350 additions and 216 deletions

View File

@ -9,6 +9,7 @@ compiler.cfg.def-use
compiler.cfg.liveness
compiler.cfg.copy-prop
compiler.cfg.registers
compiler.cfg.utilities
compiler.cfg.comparisons
compiler.cfg.instructions
compiler.cfg.representations.preferred ;
@ -245,11 +246,10 @@ M: ##allocation analyze-aliases*
M: ##read analyze-aliases*
call-next-method
dup [ dst>> ] [ insn-slot# ] [ insn-object ] tri
2dup live-slot dup [
2nip any-rep \ ##copy new-insn analyze-aliases* nip
] [
drop remember-slot
] if ;
2dup live-slot dup
[ 2nip <copy> analyze-aliases* nip ]
[ drop remember-slot ]
if ;
: idempotent? ( value slot#/f vreg -- ? )
#! Are we storing a value back to the same slot it was read

View File

@ -96,7 +96,7 @@ use: obj/tagged-rep index/int-rep
temp: temp/int-rep ;
! Register transfers
PURE-INSN: ##copy
INSN: ##copy
def: dst
use: src
literal: rep ;

View File

@ -1,4 +1,4 @@
! Copyright (C) 2008, 2009 Slava Pestov.
! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs combinators combinators.short-circuit
cpu.architecture kernel layouts locals make math namespaces sequences
@ -79,3 +79,5 @@ SYMBOL: visited
: predecessor ( bb -- pred )
predecessors>> first ; inline
: <copy> ( dst src -- insn )
any-rep \ ##copy new-insn ;

View File

@ -2,14 +2,20 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors combinators combinators.short-circuit fry
kernel make math sequences
cpu.architecture
compiler.cfg.hats
compiler.cfg.instructions
compiler.cfg.utilities
compiler.cfg.registers
compiler.cfg.instructions
compiler.cfg.value-numbering.expressions
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.rewrite ;
IN: compiler.cfg.value-numbering.alien
M: ##box-displaced-alien rewrite
dup displacement>> vreg>expr expr-zero?
[ [ dst>> ] [ base>> ] bi <copy> ] [ drop f ] if ;
! ##box-displaced-alien f 1 2 3 <class>
! ##unbox-c-ptr 4 1 <class>
! =>
@ -17,6 +23,9 @@ IN: compiler.cfg.value-numbering.alien
! ##unbox-c-ptr 5 3 <class>
! ##add 4 5 2
: rewrite-unbox-alien ( insn expr -- insn )
[ dst>> ] [ src>> vn>vreg ] bi* <copy> ;
: rewrite-unbox-displaced-alien ( insn expr -- insns )
[
[ dst>> ]
@ -25,9 +34,17 @@ IN: compiler.cfg.value-numbering.alien
##add
] { } make ;
M: ##unbox-any-c-ptr rewrite
dup src>> vreg>expr dup box-displaced-alien-expr?
[ rewrite-unbox-displaced-alien ] [ 2drop f ] if ;
: rewrite-unbox-any-c-ptr ( insn -- insn/f )
dup src>> vreg>expr
{
{ [ dup box-alien-expr? ] [ rewrite-unbox-alien ] }
{ [ dup box-displaced-alien-expr? ] [ rewrite-unbox-displaced-alien ] }
[ 2drop f ]
} cond ;
M: ##unbox-any-c-ptr rewrite rewrite-unbox-any-c-ptr ;
M: ##unbox-alien rewrite rewrite-unbox-any-c-ptr ;
! Fuse ##add-imm into ##load-memory(-imm) and ##store-memory(-imm)
! just update the offset in the instruction

View File

@ -3,9 +3,11 @@
USING: accessors combinators kernel math math.order namespaces
sequences vectors combinators.short-circuit compiler.cfg
compiler.cfg.comparisons compiler.cfg.instructions
compiler.cfg.registers compiler.cfg.value-numbering.expressions
compiler.cfg.registers
compiler.cfg.value-numbering.math
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.rewrite ;
compiler.cfg.value-numbering.rewrite
compiler.cfg.value-numbering.expressions ;
IN: compiler.cfg.value-numbering.comparisons
! Optimizations performed here:
@ -127,9 +129,6 @@ M: ##compare-integer-imm-branch rewrite
[ vreg>integer ] dip
\ ##compare-integer-imm-branch new-insn ; inline
: self-compare? ( insn -- ? )
[ src1>> ] [ src2>> ] bi [ vreg>vn ] bi@ = ; inline
: evaluate-self-compare ( insn -- ? )
cc>> { cc= cc<= cc>= } member-eq? ;
@ -140,7 +139,7 @@ M: ##compare-branch rewrite
{
{ [ dup src1>> vreg-immediate-comparand? ] [ t >compare-imm-branch ] }
{ [ dup src2>> vreg-immediate-comparand? ] [ f >compare-imm-branch ] }
{ [ dup self-compare? ] [ rewrite-self-compare-branch ] }
{ [ dup diagonal? ] [ rewrite-self-compare-branch ] }
[ drop f ]
} cond ;
@ -148,7 +147,7 @@ M: ##compare-integer-branch rewrite
{
{ [ dup src1>> vreg-immediate-arithmetic? ] [ t >compare-integer-imm-branch ] }
{ [ dup src2>> vreg-immediate-arithmetic? ] [ f >compare-integer-imm-branch ] }
{ [ dup self-compare? ] [ rewrite-self-compare-branch ] }
{ [ dup diagonal? ] [ rewrite-self-compare-branch ] }
[ drop f ]
} cond ;
@ -176,7 +175,7 @@ M: ##compare rewrite
{
{ [ dup src1>> vreg-immediate-comparand? ] [ t >compare-imm ] }
{ [ dup src2>> vreg-immediate-comparand? ] [ f >compare-imm ] }
{ [ dup self-compare? ] [ rewrite-self-compare ] }
{ [ dup diagonal? ] [ rewrite-self-compare ] }
[ drop f ]
} cond ;
@ -184,7 +183,7 @@ M: ##compare-integer rewrite
{
{ [ dup src1>> vreg-immediate-arithmetic? ] [ t >compare-integer-imm ] }
{ [ dup src2>> vreg-immediate-arithmetic? ] [ f >compare-integer-imm ] }
{ [ dup self-compare? ] [ rewrite-self-compare ] }
{ [ dup diagonal? ] [ rewrite-self-compare ] }
[ drop f ]
} cond ;

View File

@ -14,6 +14,10 @@ TUPLE: integer-expr < expr value ;
C: <integer-expr> integer-expr
: expr-zero? ( expr -- ? ) T{ integer-expr f 0 } = ; inline
: expr-one? ( expr -- ? ) T{ integer-expr f 1 } = ; inline
: expr-neg-one? ( expr -- ? ) T{ integer-expr f -1 } = ; inline
TUPLE: reference-expr < expr value ;
C: <reference-expr> reference-expr
@ -34,6 +38,8 @@ GENERIC: >expr ( insn -- expr )
M: insn >expr drop next-input-expr ;
M: ##copy >expr "Fail" throw ;
M: ##load-integer >expr val>> <integer-expr> ;
M: ##load-reference >expr obj>> <reference-expr> ;

View File

@ -3,11 +3,11 @@
USING: accessors combinators cpu.architecture fry kernel layouts
locals make math sequences compiler.cfg.instructions
compiler.cfg.registers
compiler.cfg.utilities
compiler.cfg.value-numbering.expressions
compiler.cfg.value-numbering.folding
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.rewrite
compiler.cfg.value-numbering.simplify ;
compiler.cfg.value-numbering.rewrite ;
IN: compiler.cfg.value-numbering.math
: f-expr? ( expr -- ? ) T{ reference-expr f f } = ;
@ -19,11 +19,25 @@ M: ##tagged>integer rewrite
[ 2drop f ]
} cond ;
: self-inverse ( insn -- insn' )
[ dst>> ] [ src>> vreg>expr src>> vn>vreg ] bi <copy> ;
: identity ( insn -- insn' )
[ dst>> ] [ src1>> ] bi <copy> ;
M: ##neg rewrite
dup unary-constant-fold? [ unary-constant-fold ] [ drop f ] if ;
{
{ [ dup src>> vreg>expr neg-expr? ] [ self-inverse ] }
{ [ dup unary-constant-fold? ] [ unary-constant-fold ] }
[ drop f ]
} cond ;
M: ##not rewrite
dup unary-constant-fold? [ unary-constant-fold ] [ drop f ] if ;
{
{ [ dup src>> vreg>expr not-expr? ] [ self-inverse ] }
{ [ dup unary-constant-fold? ] [ unary-constant-fold ] }
[ drop f ]
} cond ;
! Reassociation converts
! ## *-imm 2 1 X
@ -56,20 +70,18 @@ M: ##not rewrite
M: ##add-imm rewrite
{
{ [ dup src2>> 0 = ] [ identity ] }
{ [ dup binary-constant-fold? ] [ binary-constant-fold ] }
{ [ dup src1>> vreg>expr add-imm-expr? ] [ \ ##add-imm reassociate-arithmetic ] }
[ drop f ]
} cond ;
: sub-imm>add-imm ( insn -- insn' )
[ dst>> ] [ src1>> ] [ src2>> neg ] tri dup immediate-arithmetic?
[ dst>> ] [ src1>> ] [ src2>> neg ] tri
dup immediate-arithmetic?
\ ##add-imm ?new-insn ;
M: ##sub-imm rewrite
{
{ [ dup binary-constant-fold? ] [ binary-constant-fold ] }
[ sub-imm>add-imm ]
} cond ;
M: ##sub-imm rewrite sub-imm>add-imm ;
! Convert ##mul-imm -1 => ##neg
: mul-to-neg? ( insn -- ? )
@ -129,11 +141,15 @@ M: ##and-imm rewrite
{
{ [ dup binary-constant-fold? ] [ binary-constant-fold ] }
{ [ dup src1>> vreg>expr and-imm-expr? ] [ \ ##and-imm reassociate-bitwise ] }
{ [ dup src2>> 0 = ] [ dst>> 0 \ ##load-integer new-insn ] }
{ [ dup src2>> -1 = ] [ identity ] }
[ drop f ]
} cond ;
M: ##or-imm rewrite
{
{ [ dup src2>> 0 = ] [ identity ] }
{ [ dup src2>> -1 = ] [ dst>> -1 \ ##load-integer new-insn ] }
{ [ dup binary-constant-fold? ] [ binary-constant-fold ] }
{ [ dup src1>> vreg>expr or-imm-expr? ] [ \ ##or-imm reassociate-bitwise ] }
[ drop f ]
@ -141,6 +157,8 @@ M: ##or-imm rewrite
M: ##xor-imm rewrite
{
{ [ dup src2>> 0 = ] [ identity ] }
{ [ dup src2>> -1 = ] [ [ dst>> ] [ src1>> ] bi \ ##not new-insn ] }
{ [ dup binary-constant-fold? ] [ binary-constant-fold ] }
{ [ dup src1>> vreg>expr xor-imm-expr? ] [ \ ##xor-imm reassociate-bitwise ] }
[ drop f ]
@ -148,6 +166,7 @@ M: ##xor-imm rewrite
M: ##shl-imm rewrite
{
{ [ dup src2>> 0 = ] [ identity ] }
{ [ dup binary-constant-fold? ] [ binary-constant-fold ] }
{ [ dup src1>> vreg>expr shl-imm-expr? ] [ \ ##shl-imm reassociate-shift ] }
{ [ dup distribute-over-add? ] [ \ ##add-imm \ ##shl-imm distribute ] }
@ -157,6 +176,7 @@ M: ##shl-imm rewrite
M: ##shr-imm rewrite
{
{ [ dup src2>> 0 = ] [ identity ] }
{ [ dup binary-constant-fold? ] [ binary-constant-fold ] }
{ [ dup src1>> vreg>expr shr-imm-expr? ] [ \ ##shr-imm reassociate-shift ] }
[ drop f ]
@ -164,6 +184,7 @@ M: ##shr-imm rewrite
M: ##sar-imm rewrite
{
{ [ dup src2>> 0 = ] [ identity ] }
{ [ dup binary-constant-fold? ] [ binary-constant-fold ] }
{ [ dup src1>> vreg>expr sar-imm-expr? ] [ \ ##sar-imm reassociate-shift ] }
[ drop f ]
@ -187,10 +208,10 @@ M: ##add rewrite
[ drop f ]
} cond ;
! ##sub 2 1 1 => ##load-integer 2 0
: subtraction-identity? ( insn -- ? )
[ src1>> ] [ src2>> ] bi [ vreg>vn ] bi@ eq? ;
: diagonal? ( insn -- ? )
[ src1>> vreg>vn ] [ src2>> vreg>vn ] bi = ; inline
! ##sub 2 1 1 => ##load-integer 2 0
: rewrite-subtraction-identity ( insn -- insn' )
dst>> 0 \ ##load-integer new-insn ;
@ -207,7 +228,7 @@ M: ##add rewrite
M: ##sub rewrite
{
{ [ dup sub-to-neg? ] [ sub-to-neg ] }
{ [ dup subtraction-identity? ] [ rewrite-subtraction-identity ] }
{ [ dup diagonal? ] [ rewrite-subtraction-identity ] }
{ [ dup src2>> vreg-immediate-arithmetic? ] [ \ ##sub-imm f insn>imm-insn ] }
[ drop f ]
} cond ;
@ -221,6 +242,7 @@ M: ##mul rewrite
M: ##and rewrite
{
{ [ dup diagonal? ] [ identity ] }
{ [ dup src2>> vreg-immediate-bitwise? ] [ \ ##and-imm f insn>imm-insn ] }
{ [ dup src1>> vreg-immediate-bitwise? ] [ \ ##and-imm t insn>imm-insn ] }
[ drop f ]
@ -228,6 +250,7 @@ M: ##and rewrite
M: ##or rewrite
{
{ [ dup diagonal? ] [ identity ] }
{ [ dup src2>> vreg-immediate-bitwise? ] [ \ ##or-imm f insn>imm-insn ] }
{ [ dup src1>> vreg-immediate-bitwise? ] [ \ ##or-imm t insn>imm-insn ] }
[ drop f ]
@ -235,6 +258,7 @@ M: ##or rewrite
M: ##xor rewrite
{
{ [ dup diagonal? ] [ dst>> 0 \ ##load-integer new-insn ] }
{ [ dup src2>> vreg-immediate-bitwise? ] [ \ ##xor-imm f insn>imm-insn ] }
{ [ dup src1>> vreg-immediate-bitwise? ] [ \ ##xor-imm t insn>imm-insn ] }
[ drop f ]

View File

@ -7,19 +7,22 @@ vectors locals make alien.c-types io.binary grouping
math.vectors.simd.intrinsics
compiler.cfg
compiler.cfg.registers
compiler.cfg.utilities
compiler.cfg.comparisons
compiler.cfg.instructions
compiler.cfg.value-numbering.alien
compiler.cfg.value-numbering.expressions
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.rewrite
compiler.cfg.value-numbering.simplify ;
compiler.cfg.value-numbering.rewrite ;
IN: compiler.cfg.value-numbering.simd
! Some lame constant folding for SIMD intrinsics. Eventually this
! should be redone completely.
: rewrite-shuffle-vector-imm ( insn expr -- insn' )
: useless-shuffle-vector-imm? ( insn -- ? )
[ shuffle>> ] [ rep>> rep-length iota ] bi sequence= ;
: compose-shuffle-vector-imm ( insn expr -- insn' )
2dup [ rep>> ] bi@ eq? [
[ [ dst>> ] [ src>> vn>vreg ] bi* ]
[ [ shuffle>> ] bi@ nths ]
@ -36,7 +39,8 @@ IN: compiler.cfg.value-numbering.simd
M: ##shuffle-vector-imm rewrite
dup src>> vreg>expr {
{ [ dup shuffle-vector-imm-expr? ] [ rewrite-shuffle-vector-imm ] }
{ [ over useless-shuffle-vector-imm? ] [ drop [ dst>> ] [ src>> ] bi <copy> ] }
{ [ dup shuffle-vector-imm-expr? ] [ compose-shuffle-vector-imm ] }
{ [ dup reference-expr? ] [ fold-shuffle-vector-imm ] }
[ 2drop f ]
} cond ;
@ -53,8 +57,11 @@ M: ##shuffle-vector-imm rewrite
} case ;
M: ##scalar>vector rewrite
dup src>> vreg>expr dup reference-expr?
[ fold-scalar>vector ] [ 2drop f ] if ;
dup src>> vreg>expr {
{ [ dup reference-expr? ] [ fold-scalar>vector ] }
{ [ dup vector>scalar-expr? ] [ [ dst>> ] [ src>> ] bi* <copy> ] }
[ 2drop f ]
} cond ;
M: ##xor-vector rewrite
dup [ src1>> vreg>vn ] [ src2>> vreg>vn ] bi eq?
@ -104,13 +111,3 @@ M: ##andn-vector rewrite
[ rep>> ]
} cleave \ ##and-vector new-insn
] [ drop f ] if ;
M: scalar>vector-expr simplify*
src>> vn>expr {
{ [ dup vector>scalar-expr? ] [ src>> ] }
[ drop f ]
} cond ;
M: shuffle-vector-imm-expr simplify*
[ src>> ] [ shuffle>> ] [ rep>> rep-length iota ] tri
sequence= [ drop f ] unless ;

View File

@ -1,136 +0,0 @@
! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors combinators classes math layouts
sequences
compiler.cfg.instructions
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.expressions ;
IN: compiler.cfg.value-numbering.simplify
! Return value of f means we didn't simplify.
GENERIC: simplify* ( expr -- vn/expr/f )
M: copy-expr simplify* src>> ;
: simplify-unbox-alien ( expr -- vn/expr/f )
src>> vn>expr dup box-alien-expr? [ src>> ] [ drop f ] if ;
M: unbox-alien-expr simplify* simplify-unbox-alien ;
M: unbox-any-c-ptr-expr simplify* simplify-unbox-alien ;
: expr-zero? ( expr -- ? ) T{ integer-expr f 0 } = ; inline
: expr-one? ( expr -- ? ) T{ integer-expr f 1 } = ; inline
: expr-neg-one? ( expr -- ? ) T{ integer-expr f -1 } = ; inline
: >unary-expr< ( expr -- in ) src>> vn>expr ; inline
M: neg-expr simplify*
>unary-expr< {
{ [ dup neg-expr? ] [ src>> ] }
[ drop f ]
} cond ;
M: not-expr simplify*
>unary-expr< {
{ [ dup not-expr? ] [ src>> ] }
[ drop f ]
} cond ;
: >binary-expr< ( expr -- in1 in2 )
[ src1>> vn>expr ] [ src2>> vn>expr ] bi ; inline
: simplify-add ( expr -- vn/expr/f )
>binary-expr< {
{ [ over expr-zero? ] [ nip ] }
{ [ dup expr-zero? ] [ drop ] }
[ 2drop f ]
} cond ; inline
M: add-expr simplify* simplify-add ;
M: add-imm-expr simplify* simplify-add ;
: simplify-sub ( expr -- vn/expr/f )
>binary-expr< {
{ [ dup expr-zero? ] [ drop ] }
[ 2drop f ]
} cond ; inline
M: sub-expr simplify* simplify-sub ;
M: sub-imm-expr simplify* simplify-sub ;
: simplify-mul ( expr -- vn/expr/f )
>binary-expr< {
{ [ over expr-one? ] [ drop ] }
{ [ dup expr-one? ] [ drop ] }
[ 2drop f ]
} cond ; inline
M: mul-expr simplify* simplify-mul ;
M: mul-imm-expr simplify* simplify-mul ;
: simplify-and ( expr -- vn/expr/f )
>binary-expr< {
{ [ 2dup eq? ] [ drop ] }
[ 2drop f ]
} cond ; inline
M: and-expr simplify* simplify-and ;
M: and-imm-expr simplify* simplify-and ;
: simplify-or ( expr -- vn/expr/f )
>binary-expr< {
{ [ 2dup eq? ] [ drop ] }
{ [ over expr-zero? ] [ nip ] }
{ [ dup expr-zero? ] [ drop ] }
[ 2drop f ]
} cond ; inline
M: or-expr simplify* simplify-or ;
M: or-imm-expr simplify* simplify-or ;
: simplify-xor ( expr -- vn/expr/f )
>binary-expr< {
{ [ over expr-zero? ] [ nip ] }
{ [ dup expr-zero? ] [ drop ] }
[ 2drop f ]
} cond ; inline
M: xor-expr simplify* simplify-xor ;
M: xor-imm-expr simplify* simplify-xor ;
: simplify-shr ( expr -- vn/expr/f )
>binary-expr< {
{ [ dup expr-zero? ] [ drop ] }
[ 2drop f ]
} cond ; inline
M: shr-expr simplify* simplify-shr ;
M: shr-imm-expr simplify* simplify-shr ;
: simplify-shl ( expr -- vn/expr/f )
>binary-expr< {
{ [ dup expr-zero? ] [ drop ] }
[ 2drop f ]
} cond ; inline
M: shl-expr simplify* simplify-shl ;
M: shl-imm-expr simplify* simplify-shl ;
M: box-displaced-alien-expr simplify*
[ base>> ] [ displacement>> ] bi {
{ [ dup vn>expr expr-zero? ] [ drop ] }
[ 2drop f ]
} cond ;
M: expr simplify* drop f ;
: simplify ( expr -- vn )
dup simplify* {
{ [ dup not ] [ drop expr>vn ] }
{ [ dup expr? ] [ expr>vn nip ] }
{ [ dup integer? ] [ nip ] }
} cond ;
: number-values ( insn -- )
[ >expr simplify ] [ dst>> ] bi set-vn ;

View File

@ -1 +0,0 @@
Algebraic simplification of expressions

View File

@ -392,6 +392,20 @@ cpu x86.32? [
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##neg f 1 0 }
T{ ##copy f 2 0 any-rep }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##neg f 1 0 }
T{ ##neg f 2 1 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
@ -727,6 +741,20 @@ cpu x86.32? [
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 1 0 any-rep }
T{ ##load-reference f 2 f }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##copy f 1 0 any-rep }
T{ ##compare-integer f 2 0 1 cc< }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
@ -1314,7 +1342,6 @@ cpu x86.32? [
{
T{ ##peek f 0 D 0 }
T{ ##peek f 1 D 1 }
T{ ##load-integer f 2 0 }
T{ ##copy f 3 0 any-rep }
T{ ##replace f 3 D 0 }
}
@ -1322,8 +1349,7 @@ cpu x86.32? [
{
T{ ##peek f 0 D 0 }
T{ ##peek f 1 D 1 }
T{ ##sub f 2 1 1 }
T{ ##add f 3 0 2 }
T{ ##add-imm f 3 0 0 }
T{ ##replace f 3 D 0 }
} value-numbering-step
] unit-test
@ -1332,7 +1358,6 @@ cpu x86.32? [
{
T{ ##peek f 0 D 0 }
T{ ##peek f 1 D 1 }
T{ ##load-integer f 2 0 }
T{ ##copy f 3 0 any-rep }
T{ ##replace f 3 D 0 }
}
@ -1340,8 +1365,7 @@ cpu x86.32? [
{
T{ ##peek f 0 D 0 }
T{ ##peek f 1 D 1 }
T{ ##sub f 2 1 1 }
T{ ##sub f 3 0 2 }
T{ ##or-imm f 3 0 0 }
T{ ##replace f 3 D 0 }
} value-numbering-step
] unit-test
@ -1350,7 +1374,6 @@ cpu x86.32? [
{
T{ ##peek f 0 D 0 }
T{ ##peek f 1 D 1 }
T{ ##load-integer f 2 0 }
T{ ##copy f 3 0 any-rep }
T{ ##replace f 3 D 0 }
}
@ -1358,8 +1381,7 @@ cpu x86.32? [
{
T{ ##peek f 0 D 0 }
T{ ##peek f 1 D 1 }
T{ ##sub f 2 1 1 }
T{ ##or f 3 0 2 }
T{ ##xor-imm f 3 0 0 }
T{ ##replace f 3 D 0 }
} value-numbering-step
] unit-test
@ -1367,33 +1389,181 @@ cpu x86.32? [
[
{
T{ ##peek f 0 D 0 }
T{ ##peek f 1 D 1 }
T{ ##load-integer f 2 0 }
T{ ##copy f 3 0 any-rep }
T{ ##replace f 3 D 0 }
T{ ##load-integer f 1 0 }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##peek f 1 D 1 }
T{ ##sub f 2 1 1 }
T{ ##xor f 3 0 2 }
T{ ##replace f 3 D 0 }
T{ ##and-imm f 1 0 0 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 1 0 any-rep }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##and-imm f 1 0 -1 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 1 0 any-rep }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##and f 1 0 0 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 1 0 any-rep }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##or-imm f 1 0 0 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##load-integer f 1 -1 }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##or-imm f 1 0 -1 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 1 0 any-rep }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##or f 1 0 0 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 1 0 any-rep }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##xor-imm f 1 0 0 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##not f 1 0 }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##xor-imm f 1 0 -1 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##load-integer f 1 0 }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##xor f 1 0 0 }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##load-integer f 1 1 }
T{ ##copy f 2 0 any-rep }
T{ ##replace f 2 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##load-integer f 1 1 }
T{ ##mul f 2 0 1 }
T{ ##mul-imm f 2 0 1 }
T{ ##replace f 2 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 2 0 any-rep }
T{ ##replace f 2 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##shl-imm f 2 0 0 }
T{ ##replace f 2 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 2 0 any-rep }
T{ ##replace f 2 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##shr-imm f 2 0 0 }
T{ ##replace f 2 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##copy f 2 0 any-rep }
T{ ##replace f 2 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##sar-imm f 2 0 0 }
T{ ##replace f 2 D 0 }
} value-numbering-step
] unit-test
@ -1644,7 +1814,55 @@ cell 8 = [
} value-numbering-step
] unit-test
! Displaced alien optimizations
! Alien boxing and unboxing
[
{
T{ ##peek f 0 D 0 }
T{ ##box-alien f 1 0 }
T{ ##copy f 2 0 any-rep }
T{ ##replace f 2 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##box-alien f 1 0 }
T{ ##unbox-alien f 2 1 }
T{ ##replace f 2 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##box-alien f 1 0 }
T{ ##copy f 2 0 any-rep }
T{ ##replace f 2 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##box-alien f 1 0 }
T{ ##unbox-any-c-ptr f 2 1 }
T{ ##replace f 2 D 0 }
} value-numbering-step
] unit-test
[
{
T{ ##peek f 0 D 0 }
T{ ##load-integer f 2 0 }
T{ ##copy f 1 0 any-rep }
T{ ##replace f 1 D 0 }
}
] [
{
T{ ##peek f 0 D 0 }
T{ ##load-integer f 2 0 }
T{ ##box-displaced-alien f 1 2 0 c-ptr }
T{ ##replace f 1 D 0 }
} value-numbering-step
] unit-test
3 vreg-counter set-global
[
@ -1701,6 +1919,7 @@ cell 8 = [
} value-numbering-step
] unit-test
! Various SIMD simplifications
[
{
T{ ##vector>scalar f 1 0 float-4-rep }

View File

@ -1,4 +1,4 @@
! Copyright (C) 2008, 2009 Slava Pestov.
! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces assocs kernel accessors
sorting sets sequences arrays
@ -7,6 +7,7 @@ sequences.deep
compiler.cfg
compiler.cfg.rpo
compiler.cfg.def-use
compiler.cfg.utilities
compiler.cfg.instructions
compiler.cfg.value-numbering.alien
compiler.cfg.value-numbering.comparisons
@ -14,22 +15,28 @@ compiler.cfg.value-numbering.expressions
compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.math
compiler.cfg.value-numbering.rewrite
compiler.cfg.value-numbering.simplify
compiler.cfg.value-numbering.slots ;
IN: compiler.cfg.value-numbering
! Local value numbering.
: >copy ( insn -- insn/##copy )
dup dst>> dup vreg>vn vn>vreg
2dup eq? [ 2drop ] [ any-rep \ ##copy new-insn nip ] if ;
: >copy ( insn vn dst -- insn/##copy )
swap vn>vreg 2dup eq? [ 2drop ] [ <copy> nip ] if ;
GENERIC: process-instruction ( insn -- insn' )
M: insn process-instruction
dup rewrite
[ process-instruction ]
[ dup defs-vreg [ dup number-values >copy ] when ] ?if ;
[
dup defs-vreg [
dup [ >expr expr>vn ] [ dst>> ] bi
[ set-vn drop ]
[ >copy ]
3bi
] when
] ?if ;
M: ##copy process-instruction
dup [ src>> vreg>vn ] [ dst>> ] bi set-vn ;
M: array process-instruction
[ process-instruction ] map ;