#2838: -fast codeGen doesn't truncate CMMInt's at the right place
-----------------------------+----------------------------------------------
Reporter: TristanAllwood | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler
Version: 6.10.1 | Severity: normal
Keywords: | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
-----------------------------+----------------------------------------------
With this sample program:
{{{
{-# LANGUAGE MagicHash, UnboxedTuples #-}
module Simpl(complement) where
import GHC.Base
import GHC.Num
complement (I# x#) = I# (word2Int# (int2Word# (4294967295#) `xor#`
int2Word# (-1#)))
}}}
And compiling with
{{{
-O0 -fasm
}}}
on 6.10 or a recent head blows up in the assembler due to the constant.
{{{
Assembler messages:
Error: missing or invalid immediate expression `-4294967296' taken as 0
Error: suffix or operands invalid for `mov'
}}}
After some debugging with SPJ, we believe that what is happening is:
{{{CMMInt}}}is storing {{{4294967295}}} as an Integer. This magic number
is {{{(2^32) - 1}}}.
{{{4294967295 ^ -1}}} is
{{{00..011..1 ^ 11..111..1 = 11..100..0}}} which is {{{(-4294967296)}}}
We think internally using Integer arithmatic is fine (in e.g. CmmOpt),
however truncation isn't happening correctly when turning the Integer into
a real Int;
makeImmediate in nativeGen\machineRegs looks like a possible culprit.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2838>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs