summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Frisch <alain@frisch.fr>2012-04-18 07:12:54 +0000
committerAlain Frisch <alain@frisch.fr>2012-04-18 07:12:54 +0000
commit3930c2fd79e43bd02e3bc79d6b047f3aeab0effe (patch)
treeecd29bdcee929eb924ca4d3a16989a4b1bc5e9de
parentb510b67cb56e96588b81c537fab0d100c2fc0aac (diff)
#5595: Missed constant propagation.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12368 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--asmcomp/cmmgen.ml5
1 files changed, 4 insertions, 1 deletions
diff --git a/asmcomp/cmmgen.ml b/asmcomp/cmmgen.ml
index 0b5d09db7..d29f8c67c 100644
--- a/asmcomp/cmmgen.ml
+++ b/asmcomp/cmmgen.ml
@@ -78,7 +78,10 @@ let int_const n =
(Nativeint.add (Nativeint.shift_left (Nativeint.of_int n) 1) 1n)
let add_const c n =
- if n = 0 then c else Cop(Caddi, [c; Cconst_int n])
+ if n = 0 then c
+ else match c with
+ | Cconst_int x when no_overflow_add x n -> Cconst_int (x + n)
+ | c -> Cop(Caddi, [c; Cconst_int n])
let incr_int = function
Cconst_int n when n < max_int -> Cconst_int(n+1)