valderman / haste-compiler

A GHC-based Haskell to JavaScript compiler
http://haste-lang.org
BSD 3-Clause "New" or "Revised" License
1.45k stars 109 forks source link

Optimize numeric operations #340

Open valderman opened 9 years ago

valderman commented 9 years ago

Currently, all calculations over Ints and other machine types are always performed |0. For any expression where the end result will never exceed 2^52, this is unnecessary and could be replaced by a single |0 at the topmost level of the expression given that all atomic operands are guaranteed to be in range.

This could be done using range propagation, if we're to get fancy, or partially by applying some simple rules (X1 + X2 ... + Xn where `n < 52' is always safe, for instance).