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: improve code generation for temporary slice copy and inlining #18529

Open
rasky opened this issue Jan 6, 2017 · 2 comments
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Milestone

Comments

@rasky
Copy link
Member

rasky commented Jan 6, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8beta2 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/rasky/Sources/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8beta2_1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8beta2_1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lw/jdbk7p_d4gj6qpydczpbw2080000gn/T/go-build116611858=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

func DebugPerf(mem []byte, x int) {
	op := binary.LittleEndian.Uint32(mem[x:])
	fmt.Println(op)
}

What did you expect to see?

When inlining, the temporary slice could be fully elided. Moreover, a single bound-check on x+3 would be sufficient.

What did you see instead?

	test.go:9	0x1086bc1	488b442470		MOVQ 0x70(SP), AX
	test.go:9	0x1086bc6	488b4c2460		MOVQ 0x60(SP), CX
	test.go:9	0x1086bcb	4839c8			CMPQ CX, AX
	test.go:9	0x1086bce	0f879c000000		JA 0x1086c70
	test.go:9	0x1086bd4	4829c1			SUBQ AX, CX
	test.go:9	0x1086bd7	488b542468		MOVQ 0x68(SP), DX
	test.go:9	0x1086bdc	4829c2			SUBQ AX, DX
	test.go:9	0x1086bdf	48ffca			DECQ DX
	test.go:9	0x1086be2	48c1fa3f		SARQ $0x3f, DX
	test.go:9	0x1086be6	4883f2ff		XORQ $-0x1, DX
	test.go:9	0x1086bea	4821d0			ANDQ DX, AX
	test.go:9	0x1086bed	4883f903		CMPQ $0x3, CX
	test.go:9	0x1086bf1	7676			JBE 0x1086c69
	test.go:9	0x1086bf3	488b4c2458		MOVQ 0x58(SP), CX
	test.go:9	0x1086bf8	8b0401			MOVL 0(CX)(AX*1), AX

Basically, the last line (with AX=x) plus a single bound-check would be sufficient.

@randall77
Copy link
Contributor

Related: #16813. The patch there doesn't seem to help here, unfortunately.

@randall77
Copy link
Contributor

Also related: #15397

@bradfitz bradfitz added this to the Go1.9Maybe milestone Jan 13, 2017
@bradfitz bradfitz modified the milestones: Go1.9Maybe, Go1.10 Jul 20, 2017
@bradfitz bradfitz modified the milestones: Go1.10, Go1.11 Nov 28, 2017
@bradfitz bradfitz modified the milestones: Go1.11, Unplanned May 18, 2018
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Projects
None yet
Development

No branches or pull requests

4 participants