
#8668: SPECIALIZE silently fails to apply -------------------------------------+---------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+---------------------------------- Comment (by crockeea): I updated the files again per your suggestion, and get identical behavior. I expect the `vtTest` (currently fast) and `fcTest` (currently slow) to have the same runtime, e.g. < 2 seconds runtime difference. The two functions are doing the same work, but `fcTest` has one more level of indirection (one more wrapper on the type, and one more function call per addition). As far as "doing a lot of work unpacking `Pow` constructors", `plusFastCyc` is iterated 100 times, but the runtime difference is 1 minute 18 seconds. I'm willing to pay for 100 function calls, but I think we can agree that something more is going on than just unpacking constructors. I put some core snippets here [http://lpaste.net/98593] This was compiled with -O3 using the `forall`'d SPECIALIZATION. On line 10, you can see that GHC does write a specialized version of `plusFastCyc`, compared to the generic version on line 167. The rule for the specialization is on line 225. I believe this rule should fire on line 270. (`main6` calls `iterate main8 y`, so `main8` is where `plusFastCyc` should be specialized.) In regards to GHC auto-specializing: if I do not explicitly specialize `plusFastCyc` at all (but still mark it as `INLINABLE`), `fcTest` is slow. If instead I specialize `plusFastCyc` with concrete types as in the comment, `fcTest` is fast. Thus it appears GHC is *not* auto-specializing `plusFastCyc`, despite it being marked as `INLINABLE`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8668#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler