From b5d7fd266145bc09088d78e7d5dafbd45195ab31 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 3 May 2005 10:29:19 +0000 Subject: [PATCH] [project @ 2005-05-03 10:29:19 by simonmar] MO_S_Conv folding: fold floating-point literals properly --- ghc/compiler/nativeGen/AsmCodeGen.lhs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ghc/compiler/nativeGen/AsmCodeGen.lhs b/ghc/compiler/nativeGen/AsmCodeGen.lhs index cb2d4f7..43eed18 100644 --- a/ghc/compiler/nativeGen/AsmCodeGen.lhs +++ b/ghc/compiler/nativeGen/AsmCodeGen.lhs @@ -547,9 +547,13 @@ cmmMachOpFold op arg@[CmmLit (CmmInt x rep)] -- "from" type, in order to truncate to the correct size. -- The final narrow/widen to the destination type -- is implicit in the CmmLit. - MO_S_Conv from to -> CmmLit (CmmInt (narrowS from x) to) + MO_S_Conv from to + | isFloatingRep to -> CmmLit (CmmFloat (fromInteger x) to) + | otherwise -> CmmLit (CmmInt (narrowS from x) to) MO_U_Conv from to -> CmmLit (CmmInt (narrowU from x) to) - _ -> panic "cmmMachOpFold: unknown unary op" + + _ -> panic "cmmMachOpFold: unknown unary op" + -- Eliminate conversion NOPs cmmMachOpFold (MO_S_Conv rep1 rep2) [x] | rep1 == rep2 = x @@ -576,10 +580,14 @@ cmmMachOpFold conv_outer args@[CmmMachOp conv_inner [x]] | otherwise -> CmmMachOp conv_outer args where - isIntConversion (MO_U_Conv rep1 rep2) = Just (rep1,rep2,False) - isIntConversion (MO_S_Conv rep1 rep2) = Just (rep1,rep2,True) + isIntConversion (MO_U_Conv rep1 rep2) + | not (isFloatingRep rep1) && not (isFloatingRep rep2) + = Just (rep1,rep2,False) + isIntConversion (MO_S_Conv rep1 rep2) + | not (isFloatingRep rep1) && not (isFloatingRep rep2) + = Just (rep1,rep2,True) isIntConversion _ = Nothing - + intconv True = MO_S_Conv intconv False = MO_U_Conv -- 1.7.10.4