Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005313OCamlOCaml generalpublic2011-07-10 12:342012-09-25 20:07
Reporterygrek 
Assigned Tomeyer 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.12.0 
Target VersionFixed in Version3.13.0+dev 
Summary0005313: ocamlopt -g misses optimizations
Description$ cat opt.ml
let x = ref 0 in
for i = 1 to 10 do
  x := !x + i
done

$ /opt/ocaml-3.12.1/bin/ocamlopt -dlambda -c opt.ml
(seq (let (x/1030 0) (for i/1031 1 to 10 (assign x/1030 (+ x/1030 i/1031))))
  0a)

$ /opt/ocaml-3.12.1/bin/ocamlopt -g -dlambda -c opt.ml
(seq
  (let (x/1030 (makemutable 0 0))
    (before 17-54
      (for i/1031 1 to 10
        (before 38-49 (setfield_imm 0 x/1030 (+ (field 0 x/1030) i/1031))))))
  0a)

When using -g int ref is allocated on the heap. This is rather surprising - I expected -g to only add debugging symbols and not prevent optimizations.
TagsNo tags attached.
Attached Files

- Relationships
related to 0005426closedmeyer How does option -g affect optimization passes? 

-  Notes
(0006278)
meyer (developer)
2011-12-13 21:25
edited on: 2011-12-13 21:27

This is not longer happening on trunk with r11307:

$ ../../bin/ocamlopt -g -dlambda -c opt.ml:
(seq
  (let (x/1030 0)
    (before 17-54
      (for i/1031 1 to 10 (before 38-49 (assign x/1030 (+ x/1030 i/1031))))))
  0a)

(0006279)
meyer (developer)
2011-12-13 21:51

I suspect it was fixed on trunk with PR#5205 @ r11085..

Could you confirm it's been fixed with the current trunk?
(0006289)
ygrek (reporter)
2011-12-14 13:49

Yes, this exact use case is fixed, thanks!

But I am not sure that using -g will not prevent other optimizations cause looking at the code it seems that some optimization passes take -g option into the consideration. Actually, initially I wanted to clarify the meaning of -g and this specific example was the easiest to spot. So is it expected for -g to influence the generated code?
(0006296)
gasche (developer)
2011-12-15 00:53

I created the more accurate bug 0005426 to track the new question. Thanks for your participation.
(0006511)
meyer (developer)
2011-12-22 20:08

Reopening, as one place in the code needs better handling of -g flag

- Issue History
Date Modified Username Field Change
2011-07-10 12:34 ygrek New Issue
2011-12-13 21:25 meyer Note Added: 0006278
2011-12-13 21:27 meyer Note Edited: 0006278 View Revisions
2011-12-13 21:51 meyer Note Added: 0006279
2011-12-14 08:37 gasche Status new => feedback
2011-12-14 13:49 ygrek Note Added: 0006289
2011-12-14 13:49 ygrek Status feedback => new
2011-12-15 00:51 gasche Relationship added related to 0005426
2011-12-15 00:53 gasche Note Added: 0006296
2011-12-15 00:53 gasche Status new => closed
2011-12-15 00:53 gasche Resolution open => fixed
2011-12-22 20:08 meyer Assigned To => meyer
2011-12-22 20:08 meyer Note Added: 0006511
2011-12-22 20:08 meyer Status closed => feedback
2011-12-22 20:08 meyer Resolution fixed => reopened
2011-12-22 20:15 meyer Status feedback => resolved
2011-12-22 20:15 meyer Fixed in Version => 3.13.0+dev
2011-12-22 20:15 meyer Resolution reopened => fixed
2012-09-25 20:07 xleroy Status resolved => closed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker