Fix a bug in optimising division to shift right
authorSimon Marlow <simonmar@microsoft.com>
Wed, 12 Apr 2006 14:42:47 +0000 (14:42 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Wed, 12 Apr 2006 14:42:47 +0000 (14:42 +0000)
commit91a9aeebdf06c8c47a3b0eaf48ef297e7d460601
tree5fc52bf82132ee2e6323b8ac2df5ccbe0dde0942
parent93e677f64e39c2398c630d2ddff00b1bff0bf401
Fix a bug in optimising division to shift right
Division by an integral log2 can't be directly optimised to a shift
right, because shift right behaves like a division that rounds to
negative infinity, whereas we want one that rounds to zero.  Fix this
by adding (divisor-1) to the dividend when it is negative before
shifting.  We do this without jumps, generating very slightly worse
code than gcc, which uses conditional moves on CPUs that support it.
compiler/cmm/CmmOpt.hs