diff --git a/basis/compiler/cfg/representations/peephole/peephole.factor b/basis/compiler/cfg/representations/peephole/peephole.factor index f505cb7b8a..692c4dd742 100644 --- a/basis/compiler/cfg/representations/peephole/peephole.factor +++ b/basis/compiler/cfg/representations/peephole/peephole.factor @@ -281,3 +281,6 @@ M: ##not optimize-insn } [ call-next-method ] } cond ; + +M: ##bit-count optimize-insn + [ no-use-conversion ] [ finish ] [ emit-def-conversion ] tri ; diff --git a/basis/compiler/cfg/representations/representations-tests.factor b/basis/compiler/cfg/representations/representations-tests.factor index c5cdc5d2c4..1cea257b56 100644 --- a/basis/compiler/cfg/representations/representations-tests.factor +++ b/basis/compiler/cfg/representations/representations-tests.factor @@ -897,3 +897,21 @@ cpu x86.64? [ T{ ##replace f 1 D: 0 } } test-peephole ] unit-test + +! untag elimination for ##bit-count +2 vreg-counter set-global + +{ + V{ + T{ ##peek f 0 D: 0 } + T{ ##bit-count f 3 0 } + T{ ##shl-imm f 1 3 $[ tag-bits get ] } + T{ ##replace f 1 D: 0 } + } +} [ + V{ + T{ ##peek f 0 D: 0 } + T{ ##bit-count f 1 0 } + T{ ##replace f 1 D: 0 } + } test-peephole +] unit-test diff --git a/basis/compiler/cfg/representations/selection/selection.factor b/basis/compiler/cfg/representations/selection/selection.factor index 1192c6d075..42ee3fe5bf 100644 --- a/basis/compiler/cfg/representations/selection/selection.factor +++ b/basis/compiler/cfg/representations/selection/selection.factor @@ -109,7 +109,8 @@ UNION: peephole-optimizable ##test-imm ##test ##test-imm-branch - ##test-branch ; + ##test-branch + ##bit-count ; GENERIC: compute-insn-costs ( insn -- )