1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:00:06 -07:00
go/test/fixedbugs/issue7867.go
Josh Bleecher Snyder 1848d71445 cmd/gc: don't give credit for NOPs during register allocation
The register allocator decides which variables should be placed into registers by charging for each load/store and crediting for each use, and then selecting an allocation with minimal cost. NOPs will be eliminated, however, so using a variable in a NOP should not generate credit.

Issue 7867 arises from attempted registerization of multi-word variables because they are used in NOPs. By not crediting for that use, they will no longer be considered for registerization.

This fix could theoretically lead to better register allocation, but NOPs are rare relative to other instructions.

Fixes #7867.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/94810044
2014-05-09 09:55:17 -07:00

44 lines
826 B
Go

// runoutput
// Copyright 2014 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.
// Issue 7867.
package main
import "fmt"
const tpl = `
func Test%d(t %s) {
_ = t
_ = t
}
`
func main() {
fmt.Println("package main")
types := []string{
// These types always passed
"bool", "int", "rune",
"*int", "uintptr",
"float32", "float64",
"chan struct{}",
"map[string]struct{}",
"func()", "func(string)error",
// These types caused compilation failures
"complex64", "complex128",
"struct{}", "struct{n int}", "struct{e error}", "struct{m map[string]string}",
"string",
"[4]byte",
"[]byte",
"interface{}", "error",
}
for i, typ := range types {
fmt.Printf(tpl, i, typ)
}
fmt.Println("func main() {}")
}