From bb9354305426be1189e6d2d9120f50ba4b4bdb4e Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 8 Oct 2009 15:20:42 -0500 Subject: [PATCH] Another identity in value numbering for bitfields --- .../struct/bit-accessors/bit-accessors.factor | 2 +- .../tree/propagation/propagation-tests.factor | 4 +++ .../propagation/transforms/transforms.factor | 29 +++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/basis/classes/struct/bit-accessors/bit-accessors.factor b/basis/classes/struct/bit-accessors/bit-accessors.factor index 7a2fdb0cac..c535e52c0a 100644 --- a/basis/classes/struct/bit-accessors/bit-accessors.factor +++ b/basis/classes/struct/bit-accessors/bit-accessors.factor @@ -4,7 +4,7 @@ USING: kernel sequences math fry locals math.order alien.accessors ; IN: classes.struct.bit-accessors ! Bitfield accessors are little-endian on all platforms -! Why not? It's platform-dependent in C +! Why not? It's unspecified in C : ones-between ( start end -- n ) [ 2^ 1 - ] bi@ swap bitnot bitand ; diff --git a/basis/compiler/tree/propagation/propagation-tests.factor b/basis/compiler/tree/propagation/propagation-tests.factor index c1b6691542..0a8cb61a9f 100644 --- a/basis/compiler/tree/propagation/propagation-tests.factor +++ b/basis/compiler/tree/propagation/propagation-tests.factor @@ -902,3 +902,7 @@ M: tuple-with-read-only-slot clone [ t ] [ [ alien-unsigned-1 255 bitand ] { bitand fixnum-bitand } inlined? ] unit-test [ t ] [ [ alien-unsigned-1 255 swap bitand ] { bitand fixnum-bitand } inlined? ] unit-test + +[ t ] [ [ { fixnum } declare 256 rem -256 bitand ] { fixnum-bitand } inlined? ] unit-test +[ t ] [ [ { fixnum } declare 250 rem -256 bitand ] { fixnum-bitand } inlined? ] unit-test +[ f ] [ [ { fixnum } declare 257 rem -256 bitand ] { fixnum-bitand } inlined? ] unit-test diff --git a/basis/compiler/tree/propagation/transforms/transforms.factor b/basis/compiler/tree/propagation/transforms/transforms.factor index 08ac306248..b8ff96f833 100644 --- a/basis/compiler/tree/propagation/transforms/transforms.factor +++ b/basis/compiler/tree/propagation/transforms/transforms.factor @@ -45,13 +45,26 @@ IN: compiler.tree.propagation.transforms : simplify-bitand? ( value -- ? ) value-info literal>> positive-fixnum? ; +: all-ones? ( int -- ? ) + dup 1 + bitand zero? ; inline + : redundant-bitand? ( var 111... -- ? ) - [ value-info ] bi@ { [ - nip literal>> - { [ positive-fixnum? ] [ dup 1 + bitand zero? ] } 1&& - ] [ - [ interval>> ] [ literal>> ] bi* 0 swap [a,b] interval-subset? - ] } 2&& ; + [ value-info ] bi@ [ interval>> ] [ literal>> ] bi* { + [ nip integer? ] + [ nip all-ones? ] + [ 0 swap [a,b] interval-subset? ] + } 2&& ; + +: (zero-bitand?) ( value-info value-info' -- ? ) + [ interval>> ] [ literal>> ] bi* { + [ nip integer? ] + [ nip bitnot all-ones? ] + [ 0 swap bitnot [a,b] interval-subset? ] + } 2&& ; + +: zero-bitand? ( var1 var2 -- ? ) + [ value-info ] bi@ + { [ (zero-bitand?) ] [ swap (zero-bitand?) ] } 2|| ; { bitand-integer-integer @@ -61,6 +74,10 @@ IN: compiler.tree.propagation.transforms } [ [ { + { + [ dup in-d>> first2 zero-bitand? ] + [ drop [ 2drop 0 ] ] + } { [ dup in-d>> first2 redundant-bitand? ] [ drop [ drop ] ]