Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005595OCamlOCaml backend (code generation)public2012-04-17 16:002013-08-31 12:49
Reporterfrisch 
Assigned Tofrisch 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0005595: Missed constant propagation
DescriptionThe following patch:

===================================================================
--- asmcomp/cmmgen.ml (revision 12366)
+++ asmcomp/cmmgen.ml (working copy)
@@ -78,7 +78,10 @@
           (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)
===================================================================

improves code generation, for instance for the following example:

===================================================================
let () =
  let tr = Bigarray.(Array2.of_array int fortran_layout [| [|1|] |]) in
  for i = 1 to 1000000000 do ignore tr.{1, 1} done
===================================================================

On my machine, runtime goes from 1.77s to 1.46s.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0007373)
frisch (developer)
2012-04-18 09:17

Commit 12368.

- Issue History
Date Modified Username Field Change
2012-04-17 16:00 frisch New Issue
2012-04-18 09:07 frisch Assigned To => frisch
2012-04-18 09:07 frisch Status new => assigned
2012-04-18 09:17 frisch Note Added: 0007373
2012-04-18 09:17 frisch Status assigned => resolved
2012-04-18 09:17 frisch Resolution open => fixed
2013-08-31 12:49 xleroy Status resolved => closed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker