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

cmd/compile: optimize away redundant assignments #597

Closed
edsrzf opened this issue Feb 12, 2010 · 17 comments
Closed

cmd/compile: optimize away redundant assignments #597

edsrzf opened this issue Feb 12, 2010 · 17 comments

Comments

@edsrzf
Copy link

edsrzf commented Feb 12, 2010

I have the following program:

func main() {
    var a float

    a = 6.7

    ...
}

Here is the assembly generated with 6g:

0000 (test.go:12) TEXT    main+0(SB),$72-0
0001 (test.go:6) MOVSS   $(0.00000000000000000e+00),X0
0002 (test.go:8) MOVSS   $(6.70000000000000000e+00),X0
...

I would expect the first MOVSS to be optimized away. Subsequent assignments
generate more instructions still. 5g and 8g also generate similar instructions.

Which revision are you using?  (hg identify)
c20b85c872e5+ tip
@rsc
Copy link
Contributor

rsc commented Feb 12, 2010

Comment 1:

not specific to floating point.
not likely to happen any time soon either.

Status changed to LongTerm.

@rsc
Copy link
Contributor

rsc commented Feb 12, 2010

Comment 2:

Labels changed: added priority-low.

@edsrzf
Copy link
Author

edsrzf commented Feb 13, 2010

Comment 3:

ints behave a little bit better. For example, if I do:
var a int
a = 7
a = 6
...
With 6g I get:
0000 (test.go:11) TEXT    main+0(SB),$72-0
0001 (test.go:6) MOVL    $0,AX            
0002 (test.go:9) MOVL    $6,a+-28(SP)
...
So the first MOV isn't optimized away, but the one for a = 7 is. It wouldn't be for a
float. It also seems strange that the MOVs are using different destinations, but
that's probably a separate issue.

@lvdlvd
Copy link

lvdlvd commented Nov 7, 2011

Comment 4:

Labels changed: added compilerbug, performance.

@rsc
Copy link
Contributor

rsc commented Dec 9, 2011

Comment 5:

Labels changed: added priority-someday, removed priority-low.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 7:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 8:

Labels changed: added size-l.

@rsc
Copy link
Contributor

rsc commented Feb 3, 2013

Comment 9:

I have a fix pending for the integer case, which can be done by the optimizer. The
floating point case is more difficult: it really needs to be done during code
generation. That may happen with some analysis that is planned, but it's not trivial. It
may be ready for Go 1.1 but may not.

Labels changed: added go1.1maybe, removed go1.1.

@robpike
Copy link
Contributor

robpike commented Mar 7, 2013

Comment 10:

Labels changed: removed go1.1maybe.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 11:

Labels changed: added go1.3.

@robpike
Copy link
Contributor

robpike commented Aug 20, 2013

Comment 12:

Labels changed: removed go1.3.

@rsc
Copy link
Contributor

rsc commented Sep 3, 2013

Comment 13:

I still want to do this for Go 1.3.

Labels changed: added go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 14:

Labels changed: added release-go1.3, removed go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 15:

Labels changed: added repo-main.

@rsc
Copy link
Contributor

rsc commented Mar 12, 2014

Comment 16:

Labels changed: added release-go1.4, removed release-go1.3.

@rsc
Copy link
Contributor

rsc commented Sep 15, 2014

Comment 17:

Labels changed: added release-none, removed release-go1.4.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/gc: optimize away redundant assignments cmd/compile: optimize away redundant assignments Jun 8, 2015
@josharian
Copy link
Contributor

Fixed by the new SSA backend.

@golang golang locked and limited conversation to collaborators Jun 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants