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,249
    • Issues 5,249
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 582
    • Merge requests 582
  • 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
  • #10129
Closed
Open
Issue created Mar 02, 2015 by Joachim Breitner@nomeataDeveloper

emitCmmLitSwitch could be better

This is a spin off #10124. While looking at the code generated for

f :: Int -> Bool
f a = case a of
        1  -> True
        2  -> True
        3  -> True
        4  -> True
        8  -> True
        9  -> True
        11 -> True
        19 -> True
        _  -> False

I noticed this Cmm:

       c2tI:
           if (%MO_S_Lt_W64(_s2sJ::I64, 3)) goto c2tw; else goto c2tx;
       c2tw:
           if (%MO_S_Lt_W64(_s2sJ::I64, 2)) goto c2tq; else goto c2tr;
       c2tq:
           if (_s2sJ::I64 != 1) goto c2tg; else goto c2th;
       c2tr:
           if (_s2sJ::I64 != 2) goto c2tg; else goto c2th;

Note that when c2tr is reached, we know 2 ≤ _s2sJ < 3, so _s2sJ already is 2, and this check is redundant.

emitCmmLitSwitch does not take that into account, probably because it also needs to work for floats.

I wonder if it isn’t a bit shady to use an if-then-else tree for floats. Maybe for float types, a sequence of equality tests is more suitable. For all other cases, the code generator could make use of "2 ≤ x < 3 ⇒ x = 2" and skip one check.

Trac metadata
Trac field Value
Version 7.8.4
Type Task
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (CodeGen)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC simonmar
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking