Skip to content

Commit

Permalink
Better computeDiscount for ValAppCtxt
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Peyton Jones committed Jun 6, 2013
1 parent 9616743 commit 7f2a10f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions compiler/coreSyn/CoreUnfold.lhs
Expand Up @@ -1112,7 +1112,7 @@ AND

then we should not inline it (unless there is some other reason,
e.g. is is the sole occurrence). That is what is happening at
the use of 'lone_variable' in 'interesting_saturated_call'.
the use of 'lone_variable' in 'interesting_call'.

Why? At least in the case-scrutinee situation, turning
let x = (a,b) in case x of y -> ...
Expand Down Expand Up @@ -1183,9 +1183,9 @@ This kind of thing can occur if you have
which Roman did.
\begin{code}
computeDiscount :: DynFlags -> Int -> [Int] -> Int -> [ArgSummary] -> CallCtxt
computeDiscount :: DynFlags -> Arity -> [Int] -> Int -> [ArgSummary] -> CallCtxt
-> Int
computeDiscount dflags n_vals_wanted arg_discounts res_discount arg_infos cont_info
computeDiscount dflags uf_arity arg_discounts res_discount arg_infos cont_info
-- We multiple the raw discounts (args_discount and result_discount)
-- ty opt_UnfoldingKeenessFactor because the former have to do with
-- *size* whereas the discounts imply that there's some extra
Expand All @@ -1195,7 +1195,7 @@ computeDiscount dflags n_vals_wanted arg_discounts res_discount arg_infos cont_i
= 10 -- Discount of 1 because the result replaces the call
-- so we count 1 for the function itself
+ 10 * length (take n_vals_wanted arg_infos)
+ 10 * length (take uf_arity arg_infos)
-- Discount of (un-scaled) 1 for each arg supplied,
-- because the result replaces the call
Expand All @@ -1210,8 +1210,9 @@ computeDiscount dflags n_vals_wanted arg_discounts res_discount arg_infos cont_i
res_discount' = case cont_info of
BoringCtxt -> 0
CaseCtxt -> res_discount
_other -> 40 `min` res_discount
CaseCtxt -> res_discount -- Presumably a constructor
ValAppCtxt -> res_discount -- Presumably a function
ArgCtxt {} -> 40 `min` res_discount
-- res_discount can be very large when a function returns
-- constructors; but we only want to invoke that large discount
-- when there's a case continuation.
Expand Down

0 comments on commit 7f2a10f

Please sign in to comment.