#5615: ghc produces poor code for `div` with constant powers of 2.
-------------------------+--------------------------------------------------
Reporter: Lennart | Owner: daniel.is.fischer
Type: bug | Status: new
Priority: normal | Milestone: 7.6.1
Component: Compiler | Version: 7.4.1-rc1
Keywords: | Os: Unknown/Multiple
Architecture: x86 | Failure: None/Unknown
Difficulty: Unknown | Testcase:
Blockedby: | Blocking:
Related: |
-------------------------+--------------------------------------------------
Changes (by simonmar):
* version: 7.2.1 => 7.4.1-rc1
Comment:
One more thing to add: the backend does have some clever rewriting of
`quot#` to shift, this comment is from `cmm/CmmOpt.hs`:
{{{
-- shift right is not the same as quot, because it rounds
-- to minus infinity, whereasq quot rounds toward zero.
-- To fix this up, we add one less than the divisor to the
-- dividend if it is a negative number.
--
-- to avoid a test/jump, we use the following sequence:
-- x1 = x >> word_size-1 (all 1s if -ve, all 0s if
+ve)
-- x2 = y & (divisor-1)
-- result = (x+x2) >>= log2(divisor)
-- this could be done a bit more simply using conditional
moves,
-- but we're processor independent here.
--
-- we optimise the divide by 2 case slightly, generating
-- x1 = x >> word_size-1 (unsigned)
-- return = (x + x1) >>= log2(divisor)
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5615#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs