[commit: packages/base] ghc-7.8: Improve list fusion for [n::Integer..m] (45dccb9)

git at git.haskell.org git at git.haskell.org
Mon Feb 17 14:09:11 UTC 2014


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

On branch  : ghc-7.8
Link       : http://ghc.haskell.org/trac/ghc/changeset/45dccb9c862dac16e27813e189da5944647e38b7/base

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

commit 45dccb9c862dac16e27813e189da5944647e38b7
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)
    
    (cherry picked from commit a60eeccf06c28bee3b87c561450320d17c7399e3)


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

45dccb9c862dac16e27813e189da5944647e38b7
 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