mirror of
https://github.com/golang/go
synced 2024-09-05 07:54:46 +00:00
cmd/compile,runtime: skip zero'ing order array for select statements
The order array was zero initialized by the compiler, but ends up being overwritten by the runtime anyway. So let the runtime takes full responsibility for initializing, save us one instruction per select. Fixes #40399 Change-Id: Iec1eca27ad7180d4fcb3cc9ef97348206b7fe6b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/251517 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
49bae98495
commit
27a30186ab
|
@ -251,10 +251,8 @@ func walkselectcases(cases *Nodes) []*Node {
|
|||
r = typecheck(r, ctxStmt)
|
||||
init = append(init, r)
|
||||
|
||||
// No initialization for order; runtime.selectgo is responsible for that.
|
||||
order := temp(types.NewArray(types.Types[TUINT16], 2*int64(ncas)))
|
||||
r = nod(OAS, order, nil)
|
||||
r = typecheck(r, ctxStmt)
|
||||
init = append(init, r)
|
||||
|
||||
var pc0, pcs *Node
|
||||
if flag_race {
|
||||
|
|
|
@ -118,6 +118,7 @@ func selectgo(cas0 *scase, order0 *uint16, pc0 *uintptr, nsends, nrecvs int, blo
|
|||
scases := cas1[:ncases:ncases]
|
||||
pollorder := order1[:ncases:ncases]
|
||||
lockorder := order1[ncases:][:ncases:ncases]
|
||||
// NOTE: pollorder/lockorder's underlying array was not zero-initialized by compiler.
|
||||
|
||||
// Even when raceenabled is true, there might be select
|
||||
// statements in packages compiled without -race (e.g.,
|
||||
|
|
20
test/codegen/select.go
Normal file
20
test/codegen/select.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
// asmcheck
|
||||
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package codegen
|
||||
|
||||
func f() {
|
||||
ch1 := make(chan int)
|
||||
ch2 := make(chan int)
|
||||
for {
|
||||
// amd64:-`MOVQ\t[$]0, ""..autotmp_3`
|
||||
select {
|
||||
case <-ch1:
|
||||
case <-ch2:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue