[Haskell] Expecting more inlining for bit shifting

Simon Peyton-Jones simonpj at microsoft.com
Wed Oct 11 05:04:39 EDT 2006

| So, my hypothesis is that the inliner doesn't recognise that
| ``if (x >= 0) then ...'' is effectively a case analysis on x, and thus
| argument discount is not fired.  So we need to figure out how to
| this criterion for when to apply the argument discount.

Correct.  GHC generates
	case (x# >=# 0#) of { True -> ...; False -> ... }
But the argument discount only applies when we have
	case y of { ... }

So you really want a discount for the args of a primop.

The relevant file is coreSyn/CoreUnfold.lhs, and the function is

I see some notes there with primops, namely:

	  PrimOpId op  -> primOpSize op (valArgCount args)
			  -- foldr addSize (primOpSize op) (map
arg_discount args)
			  -- At one time I tried giving an arg-discount
if a primop 
			  -- is applied to one of the function's
arguments, but it's
			  -- not good.  At the moment, any unlifted-type
arg gets a
			  -- 'True' for 'yes I'm evald', so we collect
the discount even
			  -- if we know nothing about it.  And just
having it in a primop
			  -- doesn't help at all if we don't know
something more.

At the call site, the call
	f x y
gets f's arg-discount for x if x is evaluated.  But in the case of
primitive types we don't just want "evaluated", we want to know the
value.  So one could refine that.  The relevant function is
interestingArg in simplCore/SimplUtils.

| (This whole idea of argument discounting seems rather ad hoc.  Is it
| possible try out an inline, and remove it if in the end it doesn't get
| reduced in size sufficently?)

Yes, you could try that too.  It might result in a lot of wasted work,
but it'd be a reasonable thing to try.  The relevant code is in


More information about the Glasgow-haskell-users mailing list