Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,269
    • Issues 4,269
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 413
    • Merge Requests 413
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8311

Closed
Open
Opened Sep 16, 2013 by rwbarton@trac-rwbarton

suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64)

This appears to be the x86 assembly for a specialization for even :: Int -> Bool that's produced by a SPECIALISE pragma for (^) :: Int -> Int -> Int in GHC.Real. The relevant bit is offsets 0x2c through 0x3b.

0000000c <base_GHCziReal_evenzuzdseven1_info>:
   c:   8b 45 00                mov    0x0(%ebp),%eax
   f:   c7 45 00 2c 00 00 00    movl   $0x2c,0x0(%ebp)
                        12: R_386_32    .text
  16:   89 c6                   mov    %eax,%esi
  18:   f7 c6 03 00 00 00       test   $0x3,%esi
  1e:   75 0c                   jne    2c <c8gO_info>
  20:   ff 26                   jmp    *(%esi)
  22:   66 90                   xchg   %ax,%ax
  24:   00 00                   add    %al,(%eax)
  26:   00 00                   add    %al,(%eax)
  28:   20 00                   and    %al,(%eax)
        ...

0000002c <c8gO_info>:
  2c:   b8 02 00 00 00          mov    $0x2,%eax
  31:   89 c1                   mov    %eax,%ecx
  33:   8b 46 03                mov    0x3(%esi),%eax
  36:   99                      cltd   
  37:   f7 f9                   idiv   %ecx
  39:   85 d2                   test   %edx,%edx
  3b:   75 0b                   jne    48 <c8gO_info+0x1c>
  3d:   be 02 00 00 00          mov    $0x2,%esi
                        3e: R_386_32    ghczmprim_GHCziTypes_True_closure
  42:   83 c5 04                add    $0x4,%ebp
  45:   ff 65 00                jmp    *0x0(%ebp)
  48:   be 01 00 00 00          mov    $0x1,%esi
                        49: R_386_32    ghczmprim_GHCziTypes_False_closure
  4d:   83 c5 04                add    $0x4,%ebp
  50:   ff 65 00                jmp    *0x0(%ebp)

It would be much better to do a simple testb $0x1,0x3(%esi) in place of the first six instructions of c8gO_info.

The NCG generates similar code on x86_64.

Trac metadata
Trac field Value
Version 7.7
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (NCG)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#8311