Integer constant folding in the presence of new primops

Jan Stolarek jan.stolarek at p.lodz.pl
Thu May 16 13:32:22 CEST 2013


I'm finishing my patches for T6135, but I still have some work to do on integer-gmp and 
integer-simpl libraries. I changed the previously existing functions that compare Integers:

{-# NOINLINE #-}
eqInteger :: Integer -> Integer -> Bool
eqInteger = ...

to something like this:

{-# 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. I'm 
trying to figure out the proper way to fix this. I am considering two ways of doing it:

- 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)

- add new folding rules for eqIntegerPrim and other functions, remove the existing rules for 
eqInteger. This would fold (100012 :: Integer) == 100012 to tagToEnum# 1#

Which approach is better?

Another question related to this: how do I run validation with integer-simpl enabled? Wiki 
describes how to enable integer-simpl for the build, but I think that validation is always run 
against integer-gmp? Or am I wrong here?

Janek



More information about the ghc-devs mailing list