Ticket #2078 (closed bug: fixed)

Opened 4 years ago

Last modified 4 months ago

INLINE and strictness

Reported by: simonpj Owned by: simonpj
Priority: lowest Milestone: 7.6.1
Component: Compiler Version: 6.8.2
Keywords: Cc: ndp@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Consider this code

module A where
  {-# INLINE [0] foo #-}
  {#- RULE foo (reverse xs) = xs #-}
  foo xs = reverse $ xs

module B where
  import A( foo )
  g b ys = foo (case b of 
                  True -> reverse ys
                  False -> ys)

  h xs = map foo xs

At the moment the body of foo is not optimised at all, because it's going to be inlined. But that means that

  • The foo executed by the map in h is very inefficient, because it actually calls $ etc.
  • The strictness analyser doesn't see that foo is strict, because again the $ gets in the way. So the rule for foo does not match in the RHS of g. (If foo were strict, we'd push the call to foo inside the case branches.)

For both reasons it'd be better to

  • Retain the original RHS of foo for inlining purposes
  • But otherwise optimise foo normally, so that if it is not inlined, we get the efficient version, and so that strictness analysis does the right thing.

Hmm. Maybe INLINE should turn into a RULE, rather than (as now) a Note in Core?

Anyway, this ticket is to make sure I don't forget this point.

Change History

Changed 4 years ago by simonpj

Here's a concrete example when this came up:

Wed Jan 23 16:12:07 PST 2008  Roman Leshchinskiy <rl@cse.unsw.edu.au>
  * Make zipD strict in both arguments

  The strictness analyser doesn't seem to be able to figure this out. This
  change improves fusion.

    M ./Data/Array/Parallel/Unlifted/Distributed/Types.hs -2 +2

Changed 4 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 4 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 3 years ago by igloo

  • milestone changed from 6.10 branch to 6.12 branch

Changed 3 years ago by simonmar

  • failure set to Runtime performance bug

Changed 2 years ago by igloo

  • milestone changed from 6.12 branch to 6.12.3

Changed 2 years ago by igloo

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

Changed 18 months ago by igloo

  • milestone changed from 7.0.1 to 7.0.2

Changed 15 months ago by igloo

  • milestone changed from 7.0.2 to 7.2.1

Changed 8 months ago by igloo

  • milestone changed from 7.2.1 to 7.4.1

Changed 4 months ago by igloo

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

Changed 4 months ago by simonpj

  • status changed from new to closed
  • resolution set to fixed

Actually this ticket is implemented, I forget exactly when. INLINE things do capture the RHS in the Unfolding and optimise the RHS separately. Hurrah.

Note: See TracTickets for help on using tickets.