]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.tree.propagation.transforms: fix redundant-bitand?.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 17 Mar 2021 03:52:37 +0000 (20:52 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 17 Mar 2021 04:17:00 +0000 (21:17 -0700)
When removing a redundant bitand (for example, in ``W*`` which does ``64
on-bits bitand``) make sure that we leave the ``>bignum`` to convert the
input integer to a bignum since the output type propagation assumes that
to be the case and we compiled the following code wrong.

    : mult ( a b -- x ) [ 32 bits ] bi@ W* ;

Before:

    \ mult optimized.
    [
        >R 4294967295 >R integer>fixnum R> fixnum-bitand
        R> 4294967295 >R integer>fixnum R> fixnum-bitand fixnum*
    ]

After:

    \ mult optimized.
    [
        >R 4294967295 >R integer>fixnum R> fixnum-bitand
        R> 4294967295 >R integer>fixnum R> fixnum-bitand fixnum*
        >bignum
    ]

basis/compiler/tree/propagation/transforms/transforms.factor

index 179aa1285e96086a296b31b7634db1f7706c902c..a7c1e2861e288d7fb2ed73b38ef592b0a35492fb 100644 (file)
@@ -77,19 +77,19 @@ IN: compiler.tree.propagation.transforms
         in-d>> first2 [ value-info ] bi@ {
             {
                 [ 2dup zero-bitand? ]
-                [ 2drop [ 2drop 0 ] ]
+                [ nip class>> bignum = [ 2drop 0 >bignum ] [ 2drop 0 ] ? ]
             }
             {
                 [ 2dup swap zero-bitand? ]
-                [ 2drop [ 2drop 0 ] ]
+                [ drop class>> bignum = [ 2drop 0 >bignum ] [ 2drop 0 ] ? ]
             }
             {
                 [ 2dup redundant-bitand? ]
-                [ 2drop [ drop ] ]
+                [ nip class>> bignum = [ drop >bignum ] [ drop ] ? ]
             }
             {
                 [ 2dup swap redundant-bitand? ]
-                [ 2drop [ nip ] ]
+                [ drop class>> bignum = [ nip >bignum ] [ nip ] ? ]
             }
             {
                 [ 2dup simplify-bitand? ]