Ticket #5161 (closed bug: fixed)
Poor performance of division; unnecessary branching
|Reported by:||rtvd||Owned by:||igloo|
|Keywords:||div quot rem mod performance slow branching||Cc:|
|Type of failure:||Runtime performance bug||Difficulty:|
|Test Case:||Blocked By:|
In case an Int* is divided by a constant the compiled code contains unnecessary checks whether the value being divided is minBound. This check is necessary only if a value is being divided by -1 so that an exception would be thrown.
The branch can be removed by the GHC's optimiser after a small change: the two parts of the corresponding condition have to be flipped. This provides an opportunity to short-circuit this condition to 'false' without knowing the first argument (patch is attached).