[GHC] #9188: quot with a power of two is not optimized to a shift
GHC
ghc-devs at haskell.org
Mon Jun 9 18:56:07 UTC 2014
#9188: quot with a power of two is not optimized to a shift
--------------------------------------------+------------------------------
Reporter: tibbe | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime performance bug | Unknown/Multiple
Test Case: | Difficulty: Unknown
Blocking: | Blocked By:
| Related Tickets: #8311
--------------------------------------------+------------------------------
Changes (by rwbarton):
* related: => #8311
Comment:
See also #8311.
Note that `quot` by 2 rounds towards zero, so for negative `Int`s it's not
quite just a shift. The LLVM backend does handle this well, producing this
sequence for the division:
{{{
7c: 48 89 d0 mov %rdx,%rax
7f: 48 c1 e8 3f shr $0x3f,%rax
83: 48 01 d0 add %rdx,%rax ; add sign bit to move
towards 0
86: 48 d1 f8 sar %rax
}}}
A `div` by 2 really would be a single arithmetic shift, but at the Cmm
level there is still a function call to `divInt#` :(
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9188#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list