Improve compilation of short-circuit operators #1215
The compiler optimises short-circuit operations in if conditions. For example:
let foo x y = if (x > 4 && not (x < 10)) || (y > 3 && not (y < 9)) then x else 0
gets compiled to the following code (from
However, these optimisations are not applied for short-circuit operators outside of if conditions. For example:
let bar x y = (x > 4 && not (x < 10)) || (y > 3 && not (y < 9))
gets compiled to:
This PR tidies up these optimisations and applies them to all short-circuit operations (and
With flambda turned on these optimisations were broken both inside and outside of if conditions. For example, the
with this PR it produces the same code as the non-flambda compiler.
referenced this pull request
Jul 3, 2017
I haven't had time to review the code in details, but this sounds good, and doubly so if it also fixes a missed optimization in flambda.
The one point where I need to be reassured is that simple Boolean-valued expressions such as
are still compiled to branchless instructions (e.g.
Yeah, the patch keeps track of that case explicitly with the