Opened 8 years ago

Closed 8 years ago

#2838 closed merge (fixed)

-fasm codeGen doesn't truncate CMMInt's at the right place

Reported by: TristanAllwood Owned by: igloo
Priority: normal Milestone: 6.10.2
Component: Compiler Version: 6.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

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:

CMMIntis 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.

Change History (9)

comment:1 Changed 8 years ago by TristanAllwood

Summary: -fast codeGen doesn't truncate CMMInt's at the right place-fasm codeGen doesn't truncate CMMInt's at the right place

For reference, the test case does seem to be handled fine with -fnew-codegen in Today's Head.

comment:2 Changed 8 years ago by TristanAllwood

given it's wrapped in #ifdef powepc, makeImmediate was probably a red herring.

comment:3 in reply to:  1 Changed 8 years ago by simonmar

difficulty: Unknown

Replying to TristanAllwood:

For reference, the test case does seem to be handled fine with -fnew-codegen in Today's Head.

I suspect this is by accident, as the new codegen is not running CmmOpt.

comment:4 Changed 8 years ago by igloo

Milestone: 6.10.2

What platform do you see this on?

comment:5 Changed 8 years ago by TristanAllwood

Operating System: Unknown/MultipleWindows

comment:6 Changed 8 years ago by TristanAllwood

Operating System: WindowsUnknown/Multiple

I can reproduce under both Windows (vista) and linux i686

comment:7 Changed 8 years ago by simonmar

Owner: set to simonmar

comment:8 Changed 8 years ago by simonmar

Owner: changed from simonmar to igloo
Type: bugmerge

Fixed, thanks:

Tue Dec  9 02:55:15 PST 2008  Simon Marlow <marlowsd@gmail.com>
  * Fix #2838: we should narrow a CmmInt before converting to ImmInteger

comment:9 Changed 8 years ago by igloo

Resolution: fixed
Status: newclosed

Merged.

Note: See TracTickets for help on using tickets.