Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 638
    • Merge requests 638
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Model experiments
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #2838

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

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.

Trac metadata
Trac field Value
Version 6.10.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown/Multiple
Architecture
Edited Mar 09, 2019 by ToRA
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking