From dc3ee923ca7316702bab1fbc4aee878f8744d292 Mon Sep 17 00:00:00 2001 From: Jon Harper Date: Tue, 3 Jan 2017 20:43:01 +0100 Subject: [PATCH] compiler.cfg: add peephole opt to never untag the input of ##bit-count. fixes #1764 --- .../representations/peephole/peephole.factor | 3 +++ .../representations-tests.factor | 18 ++++++++++++++++++ .../representations/selection/selection.factor | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) 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 -- )