Handling Overflow in MLton
Hansen, Alexander Bjerremand, Jan Midtgaard · 2012
The definition of Standard ML dictates that overflow in integer arithmetic raises an overflow exception. As a consequence standard-conforming implementations of the language have to check for overflow which can be costly.We examine the possibility of further optimizing the code generated by the industrial-strength compiler MLton. By studying the code generated for integer arithmetic we identify dead code where overflow cannot happen. We propose a flow-sensitive integer interval analysis that detects and removes such needless overflow checks on integer arithmetic. We have implemented an analysis prototype in Standard ML and integrated it into MLton as an additional optimization pass. It is able to remove 22% of the overflow checks in the MLton benchmark suite. The binary size of the programs decrease up to 10% and the run time of arithmetic heavy programs decrease significantly - in some cases up to 27%.