[GHC] #14688: Note [Lone variables] leads to missing a case-of-case opportunity

GHC ghc-devs at haskell.org
Mon Jan 22 15:51:49 UTC 2018


#14688: Note [Lone variables] leads to missing a case-of-case opportunity
-------------------------------------+-------------------------------------
        Reporter:  mpickering        |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by mpickering):

 I tried to get to the bottom of what was going on here this afternoon.

 Here's a nice self-contained program now.

 https://gist.github.com/mpickering/37b7119561e825ba895ac2b014d178d7

 `foo` is the example from the original ticket. `x` is not work-free or
 expandable.

 `foo2` is a modified example where `x` is work-free and expandable but
 still doesn't get inlined even with the modified test (changing `is_wf` to
 `is_exp`).

 1. Something is definitely wrong in `tryUnfolding` as if `lone_variable`
 then either `some_benefit` or `is_wf` is going to be `False` so it won't
 get inlined. (Case 1: `is_wf` is False; trivial, Case 2: `is_wf` is True
 then `not (lone_variable && is_wf)` will be `False` and hence
 `some_benefit` is `False`.)

 2. Changing it to `is_exp` doesn't help `foo2` as `x` is reported to be
 expandable as well as work-free.

 3. Using a GADT means that GHC concludes that the `x` binding is no longer
 expandable or work-free which I found very surprising. Adding the type
 index shouldn't affect the optimiser like this?

 4. Changing the call to `is_exp` doesn't look like it would work anyway as
 there is no case for `Case` in `expandUnfolding_maybe` and so it will
 still return `Nothing`.

 Have you got any more hints Simon :) ?

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14688#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list