summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Laviron <vincent.laviron@gmail.com>2021-10-05 11:01:54 +0200
committerVincent Laviron <vincent.laviron@gmail.com>2021-10-21 09:01:04 +0200
commitff41359014aa0c2965c151c699bd888ea1478b87 (patch)
treedafc5a8a5adc08194c2be168ccd099fb28991866
parent37298b0b9f3ee6a48b6eaae2f981e12cc4f9a665 (diff)
downloadocaml-ff41359014aa0c2965c151c699bd888ea1478b87.tar.gz
Enable if-then-else elimination in Cmmgen
-rw-r--r--asmcomp/cmmgen.ml12
1 files changed, 10 insertions, 2 deletions
diff --git a/asmcomp/cmmgen.ml b/asmcomp/cmmgen.ml
index 3876da2e60..ac4f47771c 100644
--- a/asmcomp/cmmgen.ml
+++ b/asmcomp/cmmgen.ml
@@ -609,8 +609,16 @@ let rec transl env e =
let ifso_dbg = Debuginfo.none in
let ifnot_dbg = Debuginfo.none in
let dbg = Debuginfo.none in
- transl_if env Unknown dbg cond
- ifso_dbg (transl env ifso) ifnot_dbg (transl env ifnot)
+ let ifso = transl env ifso in
+ let ifnot = transl env ifnot in
+ let approx =
+ match ifso, ifnot with
+ | Cconst_int (1, _), Cconst_int (3, _) -> Then_false_else_true
+ | Cconst_int (3, _), Cconst_int (1, _) -> Then_true_else_false
+ | _, _ -> Unknown
+ in
+ transl_if env approx dbg cond
+ ifso_dbg ifso ifnot_dbg ifnot
| Usequence(exp1, exp2) ->
Csequence(remove_unit(transl env exp1), transl env exp2)
| Uwhile(cond, body) ->