diff --git a/basis/compiler/cfg/representations/peephole/peephole.factor b/basis/compiler/cfg/representations/peephole/peephole.factor index 1c590f88ff..22366f5714 100644 --- a/basis/compiler/cfg/representations/peephole/peephole.factor +++ b/basis/compiler/cfg/representations/peephole/peephole.factor @@ -46,14 +46,14 @@ M: ##load-integer optimize-insn ! if the architecture supports it : convert-to-load-double? ( insn -- ? ) { - [ drop object-immediates? ] + [ drop fused-unboxing? ] [ dst>> rep-of double-rep? ] [ obj>> float? ] } 1&& ; : convert-to-load-vector? ( insn -- ? ) { - [ drop object-immediates? ] + [ drop fused-unboxing? ] [ dst>> rep-of vector-rep? ] [ obj>> byte-array? ] } 1&& ; diff --git a/basis/compiler/cfg/value-numbering/misc/misc.factor b/basis/compiler/cfg/value-numbering/misc/misc.factor index e608c6e4ce..2624b29b61 100644 --- a/basis/compiler/cfg/value-numbering/misc/misc.factor +++ b/basis/compiler/cfg/value-numbering/misc/misc.factor @@ -1,13 +1,14 @@ ! Copyright (C) 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors compiler.cfg.instructions +USING: accessors cpu.architecture kernel +compiler.cfg.instructions compiler.cfg.value-numbering.graph -compiler.cfg.value-numbering.rewrite cpu.architecture kernel ; +compiler.cfg.value-numbering.rewrite ; IN: compiler.cfg.value-numbering.misc M: ##replace rewrite - object-immediates? [ - [ loc>> ] [ src>> vreg>insn ] bi dup literal-insn? - [ insn>literal swap \ ##replace-imm new-insn ] - [ 2drop f ] if - ] [ drop f ] if ; + [ loc>> ] [ src>> vreg>insn ] bi + dup literal-insn? [ + insn>literal dup immediate-store? + [ swap \ ##replace-imm new-insn ] [ 2drop f ] if + ] [ 2drop f ] if ; diff --git a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor index 7613a5948a..7c281d0fe7 100644 --- a/basis/compiler/cfg/value-numbering/value-numbering-tests.factor +++ b/basis/compiler/cfg/value-numbering/value-numbering-tests.factor @@ -60,6 +60,74 @@ IN: compiler.cfg.value-numbering.tests } value-numbering-step ] unit-test +! ##load-reference/##replace fusion +cpu x86? [ + [ + { + T{ ##load-integer f 0 10 } + T{ ##replace-imm f 10 D 0 } + } + ] [ + { + T{ ##load-integer f 0 10 } + T{ ##replace f 0 D 0 } + } value-numbering-step + ] unit-test + + [ + { + T{ ##load-reference f 0 f } + T{ ##replace-imm f f D 0 } + } + ] [ + { + T{ ##load-reference f 0 f } + T{ ##replace f 0 D 0 } + } value-numbering-step + ] unit-test +] when + +cpu x86.32? [ + [ + { + T{ ##load-reference f 0 + } + T{ ##replace-imm f 10 D + } + } + ] [ + { + T{ ##load-reference f 0 + } + T{ ##replace f 0 D 0 } + } value-numbering-step + ] unit-test +] when + +cpu x86.64? [ + [ + { + T{ ##load-integer f 0 10,000,000,000 } + T{ ##replace f 0 D 0 } + } + ] [ + { + T{ ##load-integer f 0 10,000,000,000 } + T{ ##replace f 0 D 0 } + } value-numbering-step + ] unit-test + + ! Boundary case + [ + { + T{ ##load-integer f 0 HEX: 7fffffff } + T{ ##replace f 0 D 0 } + } + ] [ + { + T{ ##load-integer f 0 HEX: 7fffffff } + T{ ##replace f 0 D 0 } + } value-numbering-step + ] unit-test +] when + ! Double compare elimination [ { diff --git a/basis/compiler/codegen/fixup/fixup.factor b/basis/compiler/codegen/fixup/fixup.factor index ebc9c7b476..427c7ff94c 100644 --- a/basis/compiler/codegen/fixup/fixup.factor +++ b/basis/compiler/codegen/fixup/fixup.factor @@ -7,6 +7,15 @@ system combinators math.bitwise math.order generalizations accessors growable fry compiler.constants memoize ; IN: compiler.codegen.fixup +! Utilities +: push-uint ( value vector -- ) + [ length ] [ B{ 0 0 0 0 } swap push-all ] [ underlying>> ] tri + swap set-alien-unsigned-4 ; + +: push-double ( value vector -- ) + [ length ] [ B{ 0 0 0 0 0 0 0 0 } swap push-all ] [ underlying>> ] tri + swap set-alien-double ; + ! Owner SYMBOL: compiling-word @@ -42,16 +51,18 @@ TUPLE: label-fixup { label label } { class integer } { offset integer } ; ! Relocation table SYMBOL: relocation-table -: push-4 ( value vector -- ) - [ length ] [ B{ 0 0 0 0 } swap push-all ] [ underlying>> ] tri - swap set-alien-unsigned-4 ; - : add-relocation-entry ( type class offset -- ) - { 0 24 28 } bitfield relocation-table get push-4 ; + { 0 24 28 } bitfield relocation-table get push-uint ; : rel-fixup ( class type -- ) swap compiled-offset add-relocation-entry ; +! Binary literal table +SYMBOL: binary-literal-table + +: add-binary-literal ( obj -- label ) +