Stefan O'Rear wrote:
On Thu, Dec 13, 2007 at 11:17:10PM +1100, Roman Leshchinskiy wrote:
Hi everyone,

here's a simple program:

foo :: Int
foo = 8 `div` 1

I was a bit surprised to see that GHC (both 6.8 and HEAD) generates the following Core for this:

foo = case GHC.Base.divInt# 8 1 of wild21_afL
        { __DEFAULT -> GHC.Base.I# wild21_afL }

It turns out that there are no rules for divInt#, quotInt#, remInt# and modInt# in GHC.Base and that no constant folding happens for divInt# and modInt# in PrelRules.lhs. In fact, the latter two don't even seem to be primops. This also seems to be the case for their Word# counterparts. I assume this is just an oversight but thought I'd ask before doing anything. Is it ok to add the primops and a couple of rules?

divInt# and modInt# are not primops because (i386) division corresponds
to quotInt# and remInt#, so the other two absolutely need to be
implemented in software.  But I'd call it an probably inliner bug if
they show up in optimized Core output.

Hmm, I should have investigated further before posting. That's a very Intel-specific reason, though. On the Sparc, for instance, it wouldn't make much sense to implement divInt# in terms of quotInt#, I think (but then again, we don't have a Sparc NCG).

Anyway, I don't think it's an inliner bug because divInt# and friends aren't marked INLINE. If nobody objects, I'll go ahead and add the INLINE pragmas at least. We lose the opportunity to have rewrite rules for divInt# this way, though, which is a pity.

Roman


_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to