From 117cb78d6bc674a06ed30e0172b4dff15b39568b Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 27 May 2009 18:58:41 -0500 Subject: [PATCH] Fixing local optimizations --- basis/compiler/cfg/height/height.factor | 6 +++--- basis/compiler/cfg/rpo/rpo.factor | 2 +- .../value-numbering-tests.factor | 17 +++++++++++++++-- .../cfg/value-numbering/value-numbering.factor | 2 +- .../write-barrier/write-barrier-tests.factor | 3 +-- .../cfg/write-barrier/write-barrier.factor | 2 +- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/basis/compiler/cfg/height/height.factor b/basis/compiler/cfg/height/height.factor index 336a8a33c2..eed0aeb0b5 100644 --- a/basis/compiler/cfg/height/height.factor +++ b/basis/compiler/cfg/height/height.factor @@ -48,8 +48,8 @@ M: insn normalize-height* ; 0 rs-height set [ [ compute-heights ] each ] [ [ [ normalize-height* ] map sift ] with-scope ] bi - ds-height get dup zero? [ drop ] [ f \ ##inc-d boa prefix ] if - rs-height get dup zero? [ drop ] [ f \ ##inc-r boa prefix ] if ; + ds-height get dup 0 = [ drop ] [ f \ ##inc-d boa prefix ] if + rs-height get dup 0 = [ drop ] [ f \ ##inc-r boa prefix ] if ; : normalize-height ( rpo -- ) - [ ] [ height-step ] local-optimization ; + [ drop ] [ height-step ] local-optimization ; diff --git a/basis/compiler/cfg/rpo/rpo.factor b/basis/compiler/cfg/rpo/rpo.factor index 32ca87de97..babea55643 100644 --- a/basis/compiler/cfg/rpo/rpo.factor +++ b/basis/compiler/cfg/rpo/rpo.factor @@ -31,7 +31,7 @@ SYMBOL: visited [ reverse-post-order ] dip each ; inline : optimize-basic-block ( bb init-quot insn-quot -- ) - [ '[ live-in keys _ each ] ] [ '[ _ change-instructions drop ] ] bi* bi ; inline + [ '[ live-in keys _ call ] ] [ '[ _ change-instructions drop ] ] bi* bi ; inline : local-optimization ( rpo init-quot: ( live-in -- ) insn-quot: ( insns -- insns' ) -- ) '[ _ _ optimize-basic-block ] each ; \ No newline at end of file diff --git a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor index 11c0819027..c12b5afd2e 100644 --- a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor +++ b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor @@ -14,8 +14,8 @@ sequences compiler.cfg vectors arrays ; ] map ; : test-value-numbering ( insns -- insns ) - basic-block new swap >vector >>instructions - dup value-numbering-step instructions>> >array ; + { } init-value-numbering + value-numbering-step ; [ { @@ -156,3 +156,16 @@ sequences compiler.cfg vectors arrays ; T{ ##compare-imm-branch f V int-regs 33 5 cc/= } } test-value-numbering trim-temps ] unit-test + +[ + { + T{ ##copy f V int-regs 48 V int-regs 45 } + T{ ##compare-imm-branch f V int-regs 45 7 cc/= } + } +] [ + { V int-regs 45 } init-value-numbering + { + T{ ##copy f V int-regs 48 V int-regs 45 } + T{ ##compare-imm-branch f V int-regs 48 7 cc/= } + } value-numbering-step +] unit-test diff --git a/basis/compiler/cfg/value-numbering/value-numbering.factor b/basis/compiler/cfg/value-numbering/value-numbering.factor index b22c8b4388..c771d3b388 100644 --- a/basis/compiler/cfg/value-numbering/value-numbering.factor +++ b/basis/compiler/cfg/value-numbering/value-numbering.factor @@ -11,7 +11,7 @@ compiler.cfg.value-numbering.rewrite ; IN: compiler.cfg.value-numbering : number-input-values ( live-in -- ) - [ [ f next-input-expr ] dip set-vn ] each ; + [ [ f next-input-expr simplify ] dip set-vn ] each ; : init-value-numbering ( live-in -- ) init-value-graph diff --git a/basis/compiler/cfg/write-barrier/write-barrier-tests.factor b/basis/compiler/cfg/write-barrier/write-barrier-tests.factor index fb755399dc..c1a667c004 100644 --- a/basis/compiler/cfg/write-barrier/write-barrier-tests.factor +++ b/basis/compiler/cfg/write-barrier/write-barrier-tests.factor @@ -4,8 +4,7 @@ arrays tools.test vectors compiler.cfg kernel accessors ; IN: compiler.cfg.write-barrier.tests : test-write-barrier ( insns -- insns ) - basic-block new swap >vector >>instructions - dup write-barriers-step instructions>> >array ; + write-barriers-step ; [ { diff --git a/basis/compiler/cfg/write-barrier/write-barrier.factor b/basis/compiler/cfg/write-barrier/write-barrier.factor index b952c062e7..e4767599a7 100644 --- a/basis/compiler/cfg/write-barrier/write-barrier.factor +++ b/basis/compiler/cfg/write-barrier/write-barrier.factor @@ -43,4 +43,4 @@ M: insn eliminate-write-barrier ; [ eliminate-write-barrier ] map sift ; : eliminate-write-barriers ( rpo -- ) - [ ] [ write-barriers-step ] local-optimization ; + [ drop ] [ write-barriers-step ] local-optimization ;