Ticket #3123 (new feature request)

Opened 4 years ago

Last modified 8 months ago

make INLINE work for recursive definitions (generalized loop peeling/loop unrolling)

Reported by: claus Owned by:
Priority: lowest Milestone: 7.6.2
Component: Compiler Version: 6.11
Keywords: Cc: batterseapower@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Inlining refers to the unfolding of definitions, ie replacing uses of identifiers with the definitions bound to them. Doing this at compile time can expose potential for other optimizations. As described in the User Guide, this is currently limited to non-recursive definitions, to avoid non-terminating recursion in the inliner. Unfolding Recursions

Since many definitions in non-trivial programs are either recursive themselves or are built from recursion combinators, leaving recursion out of inlining alltogether is a serious limitation, especially in view of the encoding of loops via tail recursion. In conventional languages, loop transformations such as loop unrolling are at the heart of optimizing high performance code (for a useful overview, see Compiler Transformations for High-Performance Computing, ACM Computing Surveys, 1994). As a consequence, many performance-critical Haskell programs contain hand-unrolled and hand-peeled recursions, which is error-prone and obscures declarative contents.

More details, examples, and an informal spec: wiki:Inlining

Change History

Changed 4 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.12 branch

Changed 4 years ago by augustss

See also #2353. Using INLINE doesn't even always force inlining normally. So even carefully crafted INLINE pragmas will not help because ghc thinks it's more clever than I and refuses to inline (thereby missing other optimisation opportunities).

Changed 4 years ago by simonpj

I have a months-old project, now so-nearly complete, to make INLINE do what it says, and be much easier to morph to explore other possibilities. Stay tuned.

Simon

Changed 4 years ago by batterseapower

  • cc batterseapower@… added

Changed 4 years ago by batterseapower

Implemented as a compiler plugin ( http://github.com/batterseapower/unroll-plugin/tree/master). Has some unfortunate limitations:

  • Annotations can only occur on top level things, so we can't unroll local definitions
  • Ugly annotation syntax :-)
  • If your functions require dictionaries, the annotated functions sometimes don't 'look' recursive before the simplifier / specialiser has had a go at them, because they call directly into a recursive worker. Workaround: always give your functions monomorphic types! I've tried to avoid this by simplifying a bit before we hit the unroller, though.

Changed 3 years ago by igloo

  • milestone changed from 6.12 branch to 6.12.3

Changed 3 years ago by igloo

  • priority changed from normal to low
  • milestone changed from 6.12.3 to 6.14.1

Changed 2 years ago by igloo

  • milestone changed from 7.0.1 to 7.0.2

Changed 2 years ago by igloo

  • milestone changed from 7.0.2 to 7.2.1

Changed 20 months ago by igloo

  • milestone changed from 7.2.1 to 7.4.1

Changed 16 months ago by igloo

  • priority changed from low to lowest
  • milestone changed from 7.4.1 to 7.6.1

Changed 8 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2
Note: See TracTickets for help on using tickets.