]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.tree.propagation: bitand custom inlining was wrong if the second input was...
authorSlava Pestov <slava@shill.local>
Thu, 20 Aug 2009 08:47:07 +0000 (03:47 -0500)
committerSlava Pestov <slava@shill.local>
Thu, 20 Aug 2009 08:47:07 +0000 (03:47 -0500)
basis/compiler/tree/propagation/propagation-tests.factor
basis/compiler/tree/propagation/transforms/transforms.factor

index f20afc77f3c538695810faad9683bd7c69504033..511f87dd094b394e4caa8a7f5942981dbc988af4 100644 (file)
@@ -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
index d6c107b74beb2733491bf3f43476a3d3ed921256..683c182903fc88a6c0513acb8999af297f63184f 100644 (file)
@@ -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