Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,400
    • Issues 5,400
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 590
    • Merge requests 590
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • 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
  • #19641
Closed
Open
Issue created Apr 02, 2021 by Simon Jakobi@sjakobiDeveloper

`toIntegralSized :: Integer -> Maybe Int` has suboptimal Core

integer_to_int :: Integer -> Maybe Int
integer_to_int = toIntegralSized

ghc-9.2.1-alpha1 -O2 -fforce-recomp -ddump-simpl -dsuppress-uniques -dsuppress-all produces the following Core:

-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
integer_to_int1 = 9223372036854775807

-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
integer_to_int2 = -9223372036854775808

-- RHS size: {terms: 22, types: 7, coercions: 0, joins: 0/0}
integer_to_int
  = \ x ->
      case integerLe# integer_to_int2 x of {
        __DEFAULT -> Nothing;
        1# ->
          case integerLe# x integer_to_int1 of {
            __DEFAULT -> Nothing;
            1# ->
              Just (case integerToInt# x of wild2 { __DEFAULT -> I# wild2 })
          }
      }

It would be nice if we could exploit the documented invariant that any Int-sized Integer will be represented with the IS constructor. The resulting Core should look roughly like this:

integer_to_int
  = \ x ->
      case x of {
        __DEFAULT -> Nothing;
        IS y -> Just (I# y)
      }

Could this be accomplished by adding a RULE?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking