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: inlining of empty functions computes arguments #4204

Closed
dvyukov opened this issue Oct 7, 2012 · 15 comments
Closed

cmd/compile: inlining of empty functions computes arguments #4204

dvyukov opened this issue Oct 7, 2012 · 15 comments
Labels
FrozenDueToAge Performance Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Oct 7, 2012

14531:7b037816cd5c tip linux/amd64

The following code:

func raceAcquire(addr unsafe.Pointer) {
}
func (rw *RWMutex) Lock() {
  raceAcquire(unsafe.Pointer(&rw.readerSem))
}

leads to generation of the following machine code:

  raceAcquire(unsafe.Pointer(&rw.readerSem))
  450e3e:       48 8b 44 24 20          mov    0x20(%rsp),%rax
  450e43:       48 83 c0 0c             add    $0xc,%rax
  // later %rax is not used

I would expect raceAcquire() call to yield no code at all.
@rsc
Copy link
Contributor

rsc commented Oct 7, 2012

Comment 2:

Thanks. Some computation of arguments may be necessary, but in this specific case we
should be able to avoid it.

Labels changed: added priority-later, go1.1, removed priority-triage.

Owner changed to ---.

Status changed to Accepted.

@dvyukov
Copy link
Member Author

dvyukov commented Oct 7, 2012

Comment 3:

Here is another test case for the issue:
package main
import "fmt"
type Foo struct {
    x, y, z, w int
}
func (Foo) Bar() {
}
func main() {
    f := new(Foo)
    fmt.Println(f)
    f.Bar()
  400c9d:       48 8b 74 24 30          mov    0x30(%rsp),%rsi
  400ca2:       48 8d 7c 24 68          lea    0x68(%rsp),%rdi
  400ca7:       48 c7 c1 04 00 00 00    mov    $0x4,%rcx
  400cae:       f3 48 a5                rep movsq %ds:(%rsi),%es:(%rdi)
}

@cznic
Copy link
Contributor

cznic commented Oct 7, 2012

Comment 4:

What about (empty) `bar` inlined here?
// http://play.golang.org/p/oh_n16JptE
package main
var i int
func foo() int  { i++; return 0 }
func bar(n int) {}
func main() {
    bar(foo())
    println(i)
}

@rsc
Copy link
Contributor

rsc commented Oct 7, 2012

Comment 5:

You can't eliminate all arguments, as I said. But we can eliminate
them after we've called cheapexpr to move the side effects out.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 6:

Labels changed: added size-l.

@rsc
Copy link
Contributor

rsc commented Feb 3, 2013

Comment 7:

I tried this but it's pretty complex, for very little reward. Moving to "maybe" list.

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

@robpike
Copy link
Contributor

robpike commented Mar 7, 2013

Comment 8:

Labels changed: removed go1.1maybe.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 9:

Labels changed: added go1.3maybe.

@robpike
Copy link
Contributor

robpike commented Aug 20, 2013

Comment 10:

Labels changed: removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 11:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 12:

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

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 13:

Labels changed: added repo-main.

@ianlancetaylor
Copy link
Contributor

Comment 14:

Labels changed: added suggested, removed priority-later.

@dvyukov dvyukov added accepted Suggested Issues that may be good for new contributors looking for work to do. Performance labels Apr 2, 2014
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/gc: inlining of empty functions computes arguments cmd/compile: inlining of empty functions computes arguments Jun 8, 2015
@randall77
Copy link
Contributor

This should be fixed with the SSA backend at tip.

@martisch
Copy link
Contributor

martisch commented Apr 6, 2016

Go tip generates a call to the empty function if the function is only empty e.g. after some dead code elimination (e.g. when used with a compile time debug constant) in the function: #4563
Maybe that is easier to remove with SSA now too.

@golang golang locked and limited conversation to collaborators Apr 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Performance Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

8 participants