Commit 4bb4a1cf authored by dterei's avatar dterei

Fix negate op not working for -0 in llvm backend

parent f9686dd4
...@@ -95,7 +95,7 @@ data LlvmLit ...@@ -95,7 +95,7 @@ data LlvmLit
-- | Refers to an integer constant (i64 42). -- | Refers to an integer constant (i64 42).
= LMIntLit Integer LlvmType = LMIntLit Integer LlvmType
-- | Floating point literal -- | Floating point literal
| LMFloatLit Rational LlvmType | LMFloatLit Double LlvmType
deriving (Eq) deriving (Eq)
instance Show LlvmLit where instance Show LlvmLit where
...@@ -191,12 +191,8 @@ getPlainName (LMLitVar x ) = getLit x ...@@ -191,12 +191,8 @@ getPlainName (LMLitVar x ) = getLit x
-- | Print a literal value. No type. -- | Print a literal value. No type.
getLit :: LlvmLit -> String getLit :: LlvmLit -> String
getLit (LMIntLit i _) = show ((fromInteger i)::Int) getLit (LMIntLit i _) = show ((fromInteger i)::Int)
-- In Llvm float literals can be printed in a big-endian hexadecimal format, getLit (LMFloatLit r _) = dToStr r
-- regardless of underlying architecture.
getLit (LMFloatLit r LMFloat) = fToStr $ fromRational r
getLit (LMFloatLit r LMDouble) = dToStr $ fromRational r
getLit l = error $ "getLit: Usupported LlvmLit type! " ++ show (getLitType l)
-- | Return the 'LlvmType' of the 'LlvmVar' -- | Return the 'LlvmType' of the 'LlvmVar'
getVarType :: LlvmVar -> LlvmType getVarType :: LlvmVar -> LlvmType
...@@ -695,11 +691,9 @@ instance Show LlvmCastOp where ...@@ -695,11 +691,9 @@ instance Show LlvmCastOp where
-- * Floating point conversion -- * Floating point conversion
-- --
-- | Convert a Haskell Float to an LLVM hex encoded floating point form -- | Convert a Haskell Double to an LLVM hex encoded floating point form. In
fToStr :: Float -> String -- Llvm float literals can be printed in a big-endian hexadecimal format,
fToStr f = dToStr $ realToFrac f -- regardless of underlying architecture.
-- | Convert a Haskell Double to an LLVM hex encoded floating point form
dToStr :: Double -> String dToStr :: Double -> String
dToStr d dToStr d
= let bs = doubleToBytes d = let bs = doubleToBytes d
...@@ -712,9 +706,7 @@ dToStr d ...@@ -712,9 +706,7 @@ dToStr d
str = map toUpper $ concat . fixEndian . (map hex) $ bs str = map toUpper $ concat . fixEndian . (map hex) $ bs
in "0x" ++ str in "0x" ++ str
-- | Reverse or leave byte data alone to fix endianness on this -- | Reverse or leave byte data alone to fix endianness on this target.
-- target. LLVM generally wants things in Big-Endian form
-- regardless of target architecture.
fixEndian :: [a] -> [a] fixEndian :: [a] -> [a]
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
fixEndian = id fixEndian = id
......
...@@ -558,7 +558,7 @@ genMachOp env _ op [x] = case op of ...@@ -558,7 +558,7 @@ genMachOp env _ op [x] = case op of
in negate (widthToLlvmInt w) all0 LM_MO_Sub in negate (widthToLlvmInt w) all0 LM_MO_Sub
MO_F_Neg w -> MO_F_Neg w ->
let all0 = LMLitVar $ LMFloatLit 0 (widthToLlvmFloat w) let all0 = LMLitVar $ LMFloatLit (-0) (widthToLlvmFloat w)
in negate (widthToLlvmFloat w) all0 LM_MO_Sub in negate (widthToLlvmFloat w) all0 LM_MO_Sub
MO_SF_Conv _ w -> fiConv (widthToLlvmFloat w) LM_Sitofp MO_SF_Conv _ w -> fiConv (widthToLlvmFloat w) LM_Sitofp
...@@ -807,7 +807,8 @@ genLit env (CmmInt i w) ...@@ -807,7 +807,8 @@ genLit env (CmmInt i w)
= return (env, mkIntLit i (LMInt $ widthInBits w), nilOL, []) = return (env, mkIntLit i (LMInt $ widthInBits w), nilOL, [])
genLit env (CmmFloat r w) genLit env (CmmFloat r w)
= return (env, LMLitVar $ LMFloatLit r (widthToLlvmFloat w), nilOL, []) = return (env, LMLitVar $ LMFloatLit (fromRational r) (widthToLlvmFloat w),
nilOL, [])
genLit env cmm@(CmmLabel l) genLit env cmm@(CmmLabel l)
= let label = strCLabel_llvm l = let label = strCLabel_llvm l
......
...@@ -168,7 +168,7 @@ genStaticLit (CmmInt i w) ...@@ -168,7 +168,7 @@ genStaticLit (CmmInt i w)
= Right $ LMStaticLit (LMIntLit i (LMInt $ widthInBits w)) = Right $ LMStaticLit (LMIntLit i (LMInt $ widthInBits w))
genStaticLit (CmmFloat r w) genStaticLit (CmmFloat r w)
= Right $ LMStaticLit (LMFloatLit r (widthToLlvmFloat w)) = Right $ LMStaticLit (LMFloatLit (fromRational r) (widthToLlvmFloat w))
-- Leave unresolved, will fix later -- Leave unresolved, will fix later
genStaticLit c@(CmmLabel _ ) = Left $ c genStaticLit c@(CmmLabel _ ) = Left $ c
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment