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: incomplete optimization of inlining leads to useless instructions. #15152

Closed
Julio-Guerra opened this issue Apr 6, 2016 · 2 comments

Comments

@Julio-Guerra
Copy link

  1. What version of Go are you using (go version)?

go version go1.6 linux/amd64

  1. What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

  1. What did you do?

Given this example:
https://play.golang.org/p/LqaVgTCP57

Compiling it with default optimization options correctly inlines the call to the empty function f() but its argument, even if not "consumed" by anything in the inlined call to f() is still computed. I was expecting a deeper optimization level correctly seeing that these rvalues are not used at all when f() is empty.

Here are the output of gc using the -S flag with and without inlining to highlight the fact that the computation of the arguments are still here whether the inlining results in a noop or not.

$ go build -gcflags='-S' example.go
...
        0x0000 00000 (/home/julio/farjump/lab/example.go:11)    MOVQ    $42, AX
        0x0007 00007 (/home/julio/farjump/lab/example.go:12)    CMPQ    AX, $42
        0x000b 00011 (/home/julio/farjump/lab/example.go:12)    SETEQ   AL
...
$ go build -gcflags='-l -S' example.go
...
        0x0018 00024 (/home/julio/farjump/lab/example.go:11)    MOVQ    (SP), BX
        0x001c 00028 (/home/julio/farjump/lab/example.go:12)    CMPQ    BX, $42
        0x0020 00032 (/home/julio/farjump/lab/example.go:12)    SETEQ   (SP)
        0x0024 00036 (/home/julio/farjump/lab/example.go:12)    PCDATA  $0, $0
        0x0024 00036 (/home/julio/farjump/lab/example.go:12)    CALL    "".f(SB)
...
  1. What did you expect to see?

The data-flow analyser should be able to delete useless arguments (and associated computations).

  1. What did you see instead?

Useless instructions.

@martisch
Copy link
Contributor

martisch commented Apr 6, 2016

see #4204.

@randall77
Copy link
Contributor

This is fixed with the SSA compiler at tip.

@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.
Projects
None yet
Development

No branches or pull requests

4 participants