Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocamlopt -g misses optimizations #5313

Closed
vicuna opened this Issue Jul 10, 2011 · 5 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link
Collaborator

vicuna commented Jul 10, 2011

Original bug ID: 5313
Reporter: @ygrek
Assigned to: meyer
Status: closed (set by @xavierleroy on 2012-09-25T18:07:21Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 3.12.0
Fixed in version: 3.13.0+dev
Category: ~DO NOT USE (was: OCaml general)
Related to: #5426
Monitored by: @gasche tgazagna "Dmitry Grebeniuk" thelema @jberdine @Chris00 gerd

Bug 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.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 13, 2011

Comment author: meyer

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)

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 13, 2011

Comment author: meyer

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

Could you confirm it's been fixed with the current trunk?

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 14, 2011

Comment author: @ygrek

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?

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 14, 2011

Comment author: @gasche

I created the more accurate bug #5426 to track the new question. Thanks for your participation.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 22, 2011

Comment author: meyer

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.