ocaml/ocaml — pull request #17 by stedolan (2014-02-18 22:32:08+00:00)
Title: Cmm arithmetic optimisations

Some optimisations on Cmm expressions involving tagging or constants. Here's a (best-case) example:

let int_of_digits a b c =
100 * (Char.code a - Char.code '0') +
10 * (Char.code b - Char.code '0') +
1 * (Char.code c - Char.code '0')

Trunk compiles this to:

(+
(+ (+ (* 200 (>>s (+ a/1020 -96) 1)) (* 20 (>>s (+ b/1021 -96) 1)))
(* 2 (>>s (+ c/1022 -96) 1)))
1)

This branch compiles this to:

(+ (+ (+ ( * a/1020 100) ( * b/1021 10)) c/1022) -10766)

Floating all of the constant operations, tags, etc. out of arithmetic means they can be merged into one addition.