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: unexpected write barrier for 1-element slice literal #34723

Closed
cuonglm opened this issue Oct 6, 2019 · 4 comments
Closed

cmd/compile: unexpected write barrier for 1-element slice literal #34723

cuonglm opened this issue Oct 6, 2019 · 4 comments
Assignees
Milestone

Comments

@cuonglm
Copy link
Contributor

@cuonglm cuonglm commented Oct 6, 2019

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

$ go version
go version devel +fc8bef06c4 Sun Oct 6 00:33:51 2019 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/cuonglm/Library/Caches/go-build"
GOENV="/Users/cuonglm/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/cuonglm/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/cuonglm/sources/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/cuonglm/sources/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y4/hs76ltbn7sb66lw_6934kq4m0000gn/T/go-build978643304=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ cat t.go
package t

func f25() []string {
	return []string{"a"} // no write barrier here
}

func f26() []string {
	return []string{"a", "b"} // no write barrier here
}
$ go tool compile -d=wb t.go
t.go:4:17: write barrier

What did you expect to see?

No write barrier emitted

What did you see instead?

Write barrier emitted in f25.

@cuonglm cuonglm changed the title cmd/compile: emit write barrier for 1-element slice literal cmd/compile: unexpected write barrier for 1-element slice literal Oct 6, 2019
@randall77

This comment has been minimized.

Copy link
Contributor

@randall77 randall77 commented Oct 6, 2019

I see f26 has the write barrier, and f25 doesn't.

I think what's happening here is a failure of the zero-memory tracking. The write barrier removal here requires the compiler to know that the target memory is zeroed.

The zero-memory tracking fails because we write the strings out of order (first length, then pointer). The zero-memory tracker keeps only a single range for each object, so when writes occur to the middle of a zero range it has to throw away the remainder.

I think we just need to update the zero tracker to handle a few ranges. Maybe a bitmap. I'll investigate.

@randall77 randall77 self-assigned this Oct 6, 2019
@randall77 randall77 added this to the Go1.14 milestone Oct 6, 2019
@randall77

This comment has been minimized.

Copy link
Contributor

@randall77 randall77 commented Oct 6, 2019

I see f26 has the write barrier, and f25 doesn't.

Sorry, my bad, it is f25 that has the write barrier.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Oct 7, 2019

Change https://golang.org/cl/199558 mentions this issue: cmd/compile: improve write barrier removal

@av86743

This comment has been minimized.

Copy link

@av86743 av86743 commented Oct 7, 2019

https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/writebarrier.go#L381 : CL turns range into map.

	// This analysis is conservative. We only keep track, for each memory state, of
	// a single constant range of a single object which is known to be zero.
@gopherbot gopherbot closed this in 30da79d Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.