#4470: Loop optimization: identical counters
---------------------------------+------------------------------------------
Reporter: choenerzs | Owner:
Type: feature request | Status: new
Priority: normal | Component: Compiler
Version: | Keywords: loop optimization
Testcase: | Blockedby:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by rl):
Here is another example:
{{{
import Data.Vector.Unboxed as V
dotp :: Vector Double -> Vector Double -> Double
dotp xs ys = V.sum (V.zipWith (*) xs ys)
}}}
GHC generates this loop:
{{{
letrec {
$s$wfoldlM'_loop_s1TD [Occ=LoopBreaker]
:: Int# -> Int# -> Double# -> Double#
$s$wfoldlM'_loop_s1TD =
\ (sc_s1Tk :: Int#) (sc1_s1Tl :: Int#) (sc2_s1Tm :: Double#) ->
case >=# sc1_s1Tl ipv1_s1QU of _ {
False ->
case >=# sc_s1Tk ipv4_s1Rb of _ {
False ->
$s$wfoldlM'_loop_s1TD
(+# sc_s1Tk 1)
(+# sc1_s1Tl 1)
(+##
sc2_s1Tm
(*##
(indexDoubleArray# ipv2_s1QV (+# ipv_s1QT
sc1_s1Tl))
(indexDoubleArray# ipv5_s1Rc (+# ipv3_s1Ra
sc_s1Tk))));
True -> sc2_s1Tm
};
True -> sc2_s1Tm
}; } in
$s$wfoldlM'_loop_s1TD 0 0 0.0
}}}
It should be easy to spot that `sc_s1Tk` and `sc1_s1Tl` are always equal.
In fact, !SpecConstr probably already has most of the machinery for this.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4470#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs