diff --git a/basis/compiler/tree/propagation/propagation-tests.factor b/basis/compiler/tree/propagation/propagation-tests.factor index f20afc77f3..511f87dd09 100644 --- a/basis/compiler/tree/propagation/propagation-tests.factor +++ b/basis/compiler/tree/propagation/propagation-tests.factor @@ -82,6 +82,8 @@ IN: compiler.tree.propagation.tests [ bignum ] [ [ { bignum bignum } declare bitxor ] final-math-class ] unit-test +[ bignum ] [ [ { integer } declare 123 >bignum bitand ] final-math-class ] unit-test + [ float ] [ [ { float float } declare mod ] final-math-class ] unit-test [ V{ fixnum } ] [ [ 255 bitand ] final-classes ] unit-test diff --git a/basis/compiler/tree/propagation/transforms/transforms.factor b/basis/compiler/tree/propagation/transforms/transforms.factor index d6c107b74b..683c182903 100644 --- a/basis/compiler/tree/propagation/transforms/transforms.factor +++ b/basis/compiler/tree/propagation/transforms/transforms.factor @@ -38,6 +38,12 @@ IN: compiler.tree.propagation.transforms in-d>> rem-custom-inlining ] "custom-inlining" set-word-prop +: positive-fixnum? ( obj -- ? ) + { [ fixnum? ] [ 0 >= ] } 1&& ; + +: simplify-bitand? ( value -- ? ) + value-info literal>> positive-fixnum? ; + { bitand-integer-integer bitand-integer-fixnum @@ -45,10 +51,17 @@ IN: compiler.tree.propagation.transforms bitand } [ [ - in-d>> second value-info >literal< [ - 0 most-positive-fixnum between? - [ [ >fixnum ] bi@ fixnum-bitand ] f ? - ] when + { + { + [ dup in-d>> first simplify-bitand? ] + [ drop [ >fixnum fixnum-bitand ] ] + } + { + [ dup in-d>> second simplify-bitand? ] + [ drop [ [ >fixnum ] dip fixnum-bitand ] ] + } + [ drop f ] + } cond ] "custom-inlining" set-word-prop ] each