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: low function inline cost #54407

Closed
subtle-byte opened this issue Aug 12, 2022 · 1 comment
Closed

cmd/compile: low function inline cost #54407

subtle-byte opened this issue Aug 12, 2022 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@subtle-byte
Copy link

subtle-byte commented Aug 12, 2022

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

$ go version
go version go1.19 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

I write the following code:

package main
import "encoding/binary"
func main() {
}

func A(b []byte) uint64 {
	return binary.LittleEndian.Uint64(b)
}

// Copy-paste of binary.LittleEndian.Uint64
func Uint64(b []byte) uint64 {
	_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
	return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
		uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
}

func B(b []byte) uint64 {
	return Uint64(b)
}

Then I run the command go build -gcflags -m=2 . and I see:

can inline A with cost 5 as: func([]byte) uint64 { return binary.littleEndian.Uint64(binary.LittleEndian, b) }
inlining call to binary.littleEndian.Uint64
can inline B with cost 63 as: func([]byte) uint64 { return Uint64(b) }
inlining call to Uint64

So A calls Uint64 from another module and B calls Uint64 from the same module, and A and B have different costs.

What did you expect to see?

I expected to see the same cost no matter where the called function is located.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 12, 2022
@subtle-byte subtle-byte changed the title cmd/compile: zero inline-cost of function from another module cmd/compile: low inline cost of function from another module Aug 12, 2022
@subtle-byte subtle-byte changed the title cmd/compile: low inline cost of function from another module cmd/compile: low function inline cost Aug 12, 2022
@subtle-byte
Copy link
Author

subtle-byte commented Aug 12, 2022

It is the effect of #42958. encoding/binary.LittleEndian.Uint64 is considered cheap for inline.

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

No branches or pull requests

2 participants