From a07f118c08ac5fd5923b6e0b2c994f4185121604 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Fri, 13 Jul 2012 19:51:08 +0100 Subject: [PATCH] Tweak RULEs; fixes #7041 In particular, the gcd rule now uses smallInteger rather than S#, which means that it actually fires. Also fixed a bug when the result is minBound :: Int. --- GHC/Integer/Type.lhs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/GHC/Integer/Type.lhs b/GHC/Integer/Type.lhs index be3ebea..a402f37 100644 --- a/GHC/Integer/Type.lhs +++ b/GHC/Integer/Type.lhs @@ -135,11 +135,6 @@ int64ToInteger i = if ((i `leInt64#` intToInt64# 0x7FFFFFFF#) && integerToInt :: Integer -> Int# {-# NOINLINE integerToInt #-} -{-# RULES "integerToInt" forall i. integerToInt (S# i) = i #-} --- Don't inline integerToInt, because it can't do much unless --- it sees a (S# i), and inlining just creates fruitless --- join points. But we do need a RULE to get the constants --- to work right: 1::Int had better optimise to (I# 1)! integerToInt (S# i) = i integerToInt (J# s d) = integer2Int# s d @@ -287,8 +282,10 @@ lcmInteger a b = if a `eqInteger` S# 0# then S# 0# where aa = absInteger a ab = absInteger b +-- This rule needs to use absInteger so that it works correctly when +-- the result is minBound :: Int {-# RULES "gcdInteger/Int" forall a b. - gcdInteger (S# a) (S# b) = S# (gcdInt a b) + gcdInteger (smallInteger a) (smallInteger b) = absInteger (smallInteger (gcdInt a b)) #-} gcdInt :: Int# -> Int# -> Int# gcdInt 0# y = absInt y -- 1.9.1