Integer constant folding in the presence of new primops

Simon Peyton-Jones simonpj at microsoft.com
Thu May 16 18:00:59 CEST 2013


All the same issues arise for Int# too, right?  


| {-# NOINLINE eqIntegerPrim #-}
| eqIntegerPrim :: Integer -> Integer -> Int#
| eqIntegerPrim ... -- same as before, but uses new primops
| 
| eqInteger :: Integer -> Integer -> Bool
| eqInteger  a b = tagToEnum# (a `eqIntegerPrim`  b)
| 
| I noticed that in some cases this implementation prevents constant
| folding for Integers. 

Why?  Because eqInteger is now inlined, so the rule doesn't get a chance to fire?

| A add new folding rules for eqIntegerPrim and other functions, leave the
| existing rules for
| eqInteger. This should fold: (100012 :: Integer) == 100012 to True (as
| it does now)
| 
| B add new folding rules for eqIntegerPrim and other functions, remove
| the existing rules for
| eqInteger. This would fold (100012 :: Integer) == 100012 to tagToEnum#
| 1#

I'm not sure I understand, but I think that the difference between (A) and (B) is whether the existing rules for eqInteger remain or are removed. I'd remove them if you can; simpler, only one way for things to happen

S




More information about the ghc-devs mailing list