[commit: packages/base] master: Improve list fusion for [n::Integer..m] (a60eecc)

git at git.haskell.org git at git.haskell.org
Fri Feb 14 10:17:03 UTC 2014


Repository : ssh://git@git.haskell.org/base

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/a60eeccf06c28bee3b87c561450320d17c7399e3/base

>---------------------------------------------------------------

commit a60eeccf06c28bee3b87c561450320d17c7399e3
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Fri Feb 14 09:17:22 2014 +0000

    Improve list fusion for [n::Integer..m]
    
    enumFromTo for Integers goes via enumDeltaToInteger, which is less
    efficient, as the "delta > = 0" check prevents more inlining which is
    required for good fusion code. This rule avoids tihs check for the
    common case of "delta = 1", makes up_fb visible and hence inlineable,
    which greatly improves "length [n:Integer..m]"; even more so with
    CallArity enabled. (#8766)


>---------------------------------------------------------------

a60eeccf06c28bee3b87c561450320d17c7399e3
 GHC/Enum.lhs |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/GHC/Enum.lhs b/GHC/Enum.lhs
index 332d205..2934c72 100644
--- a/GHC/Enum.lhs
+++ b/GHC/Enum.lhs
@@ -701,6 +701,13 @@ enumDeltaToIntegerFB c n x delta lim
   | delta >= 0 = up_fb c n x delta lim
   | otherwise  = dn_fb c n x delta lim
 
+{-# RULES
+"enumDeltaToInteger1"   [0] forall c n x . enumDeltaToIntegerFB c n x 1 = up_fb c n x 1
+ #-}
+-- This rule ensures that in the common case (delta = 1), we do not do the check here,
+-- and also that we have the chance to inline up_fb, which would allow the constuctor to be
+-- inlined and good things to happen.
+
 {-# NOINLINE [1] enumDeltaToInteger #-}
 enumDeltaToInteger :: Integer -> Integer -> Integer -> [Integer]
 enumDeltaToInteger x delta lim



More information about the ghc-commits mailing list