Opened 8 years ago

Last modified 8 months ago

#3781 new bug

Improve inlining for local functions

Reported by: simonpj Owned by:
Priority: lowest Milestone:
Component: Compiler Version: 6.12.1
Keywords: Inlining Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I found that boyer2/Rewritefuns.onewayunify1 has a join point that really should be inlined. It should get a big discount from scrutinizing free variables. But the inlining mechanism only take account of arguments, not free variables. There's a small optimisation opportunity here, which this ticket records.

Here's the code:

Rewritefns.onewayunify1 =
  \ (t1_acm :: Lisplikefns.Lisplist)
    (t2_acn :: Lisplikefns.Lisplist)
    (u_aco :: Lisplikefns.Lisplist) ->
    case t2_acn of wild_ao1 {
      __DEFAULT ->
        case t1_acm of wild_Xok {
          __DEFAULT ->
            let {
              $j_spS
                :: GHC.Prim.State# GHC.Prim.RealWorld
                   -> (GHC.Bool.Bool, Lisplikefns.Lisplist)
              [LclId,
               Arity=1,
               Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,
                       ConLike=True, Cheap=True, Expandable=True,
                       Guidance=IF_ARGS [0] 10 0}]
              $j_spS =
                \ _ ->
                  Rewritefns.onewayunify1lst
                    (case wild_Xok of _ {
                       Lisplikefns.Nil -> Lisplikefns.Nil;
                       Lisplikefns.Cons ds1_anT ->
                         case ds1_anT of _ { (_, y_anY) -> y_anY }
                     })
                    (case wild_ao1 of _ {
                       Lisplikefns.Nil -> Lisplikefns.Nil;
                       Lisplikefns.Cons ds1_anT ->
                         case ds1_anT of _ { (_, y_anY) -> y_anY }
                     })
                    u_aco } in
            case wild_Xok of _ {
              Lisplikefns.Nil ->
                case wild_ao1 of _ {
                  Lisplikefns.Nil ->
                    case Lisplikefns.$fEqLisplist_$c== Lisplikefns.Nil Lisplikefns.Nil
                    of _ {
                      GHC.Bool.False -> (GHC.Bool.False, u_aco);
                      GHC.Bool.True -> $j_spS GHC.Prim.realWorld#
                    };
                  Lisplikefns.Cons ds1_anJ ->
                    case ds1_anJ of _ { (x_anN, _) ->
                    case Lisplikefns.$fEqLisplist_$c== Lisplikefns.Nil x_anN of _ {
                      GHC.Bool.False -> (GHC.Bool.False, u_aco);
                      GHC.Bool.True -> $j_spS GHC.Prim.realWorld#
                    }
                    }
                };
              Lisplikefns.Cons ds1_anJ ->
                case ds1_anJ of _ { (x_anN, _) ->
                case wild_ao1 of _ {
                  Lisplikefns.Nil ->
                    case Lisplikefns.$fEqLisplist_$c== x_anN Lisplikefns.Nil of _ {
                      GHC.Bool.False -> (GHC.Bool.False, u_aco);
                      GHC.Bool.True -> $j_spS GHC.Prim.realWorld#
                    };
                  Lisplikefns.Cons ds1_Xof ->
                    case ds1_Xof of _ { (x_Xom, _) ->
                    case Lisplikefns.$fEqLisplist_$c== x_anN x_Xom of _ {
                      GHC.Bool.False -> (GHC.Bool.False, u_aco);
                      GHC.Bool.True -> $j_spS GHC.Prim.realWorld#
                    }
                    }
                }
                }
            };
          Lisplikefns.Atom x_ao3 -> (GHC.Bool.False, u_aco)
        };

You can see that $j_sps scrutinises wild_Xok and wild_ao1, but it currently gets no discount for doing so.

Attachments (1)

FVDiscountSim.hs (769 bytes) - added by nfrisby 5 years ago.
Small example abstracting nofib boyer2, where discounting FVs is a win

Download all attachments as: .zip

Change History (17)

comment:1 Changed 8 years ago by igloo

Milestone: 6.12 branch

comment:2 Changed 8 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:3 Changed 8 years ago by igloo

Milestone: 6.12.36.14.1
Priority: normallow

comment:4 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:5 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:6 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:7 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: lowlowest

comment:8 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

Changed 5 years ago by nfrisby

Attachment: FVDiscountSim.hs added

Small example abstracting nofib boyer2, where discounting FVs is a win

comment:9 Changed 5 years ago by nfrisby

For the record, we re-discovered this while investigating a late lambda float. If we move forward with that, it would partially achieve the functionality of discounting FVs, as discussed in #7664; see attached FVDiscountSim.hs

comment:10 Changed 3 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:11 Changed 3 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:12 Changed 3 years ago by thoughtpolice

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:13 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:14 Changed 23 months ago by thomie

Milestone: 8.0.1

comment:15 Changed 17 months ago by mpickering

Keywords: Inlining added

comment:16 Changed 8 months ago by simonpj

See also #3755, #7664

Note: See TracTickets for help on using tickets.