Opened 8 years ago

Closed 4 years ago

Last modified 14 months ago

#5945 closed bug (duplicate)

Lambda lifting

Reported by: simonpj Owned by: simonpj
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.4.1
Keywords: LateLamLift Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: #11284, #9476 Differential Rev(s):
Wiki Page:

Description

Dan Rosen asks whether GHC has a lambda lifter. Yes, it does: GHC's full-laziness pass also doubles as a lambda lifter

  • It's controlled by the floatOutLambdas field of CoreMonad.FloatOutSwitches
  • This in turn is set from the floatLamArgs field of DynFlags in SimplCore
  • The DynFlags are set in module DynFlags (see -ffloat-all-lams, -ffloat-lam-args)

However on trying a small experiment on

	f x = map (\y -> (x,y))

I see a bug and an infelicity.

  • Bug: the comment with the floatOutLambdas field definition claims that Nothing means float all lambdas to the top. But the code in SetLevels.destLevel treats (Just 0) and Nothing identically, which contradicts the comment. Workaround: use (Just 100)
  • Infelicity: with -ffloat-lam-args=100 we get
    lvl_sdQ =
      \ (@ t_acm) (@ t_acn) (x_a9H :: t_acm) (y_a9I :: t_acn) ->
        (x_a9H, y_a9I)
    
    Foo.f =
      \ (@ t_acm)
        (@ t_acn)
        (x_a9H [Dmd=Just L] :: t_acm)
        (eta_B1 :: [t_acn]) ->
        GHC.Base.map
          @ t_acn @ (t_acm, t_acn) (lvl_sdQ @ t_acm @ t_acn x_a9H) eta_B1
    
    which is good, but then the next simplifier run inlines it straight back in again, via SimplUtils.preInlineUnconditionally.

I think preInlineUnconditionally should be a bit less gung-ho, perhaps, but I don't want to change it until I've see if there are any performance regressions.

Change History (9)

comment:1 Changed 7 years ago by igloo

Milestone: 7.8.1
Owner: set to simonpj

comment:2 Changed 5 years ago by thoughtpolice

Milestone: 7.8.37.10.1

Moving to 7.10.1.

comment:3 Changed 5 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:4 Changed 4 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:5 Changed 4 years ago by thomie

Type of failure: None/UnknownRuntime performance bug

comment:6 Changed 4 years ago by bgamari

This looks very similar to #11284.

comment:7 Changed 4 years ago by bgamari

Resolution: duplicate
Status: newclosed

There is an unmerged branch that implements late lambda-lifting. See LateLamLift and #9476.

comment:8 Changed 4 years ago by bgamari

comment:9 Changed 14 months ago by simonpj

Keywords: LateLamLift added
Note: See TracTickets for help on using tickets.