[GHC] #8311: suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64)
#8311: suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64) ------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 7.7 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- 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. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8311> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8311: suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64) -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * cc: simonmar (added) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8311#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8311: suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64) -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Could you give us the source Haskell code, and how you compiled it, that gives this sub-optimal result? Thanks! Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8311#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8311: suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64) -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by rwbarton): The source of that code is in GHC.Real in base, but for reproducing, use this: {{{ module Even where myEven :: Int -> Bool myEven n = n `rem` 2 == 0 }}} compiled with `ghc -O2 -o Even.o -c Even.hs`. The LLVM backend (`ghc -O2 -fllvm -o Even.o -c Even.hs`) does produce a `testb $0x1,0x3(%esi)` instruction. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8311#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8311: suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64) -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by carter): * cc: carter.schonwald@… (added) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8311#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8311: suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64) -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #9188 -------------------------------------+------------------------------------ Changes (by rwbarton): * related: => #9188 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8311#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8311: suboptimal code generated for even :: Int -> Bool by NCG (x86, x86_64) -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.7 Component: Compiler | Keywords: (NCG) | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: #5615 Type of failure: Runtime | performance bug | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * failure: None/Unknown => Runtime performance bug * related: #9188 => #5615 Comment: #9188 was closed as a duplicate of #5615. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8311#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC