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: suboptimal code generation for bit test (regression in Go 1.15) #44228

Closed
cespare opened this issue Feb 12, 2021 · 1 comment
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Performance
Milestone

Comments

@cespare
Copy link
Contributor

cespare commented Feb 12, 2021

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

Go 1.15.8 and tip

Does this issue reproduce with the latest release?

yes

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

linux/amd64


We're upgrading from an old Go version (1.13.x) to Go 1.15 and I'm looking at a noticeable benchmark regression.

Here's a repro:

https://github.com/cespare/misc/blob/00c5f6e9852290b26ea32fc437c69eaa47fe63dd/btregression/btregression.go

The interesting bit is simply

var charSet [4]uint64

func inCharSet(b byte) bool {
	return charSet[b>>6]&(1<<(b&63)) != 0
}

It just does a lookup in a small global bitset.

On my machine (i7-8700K), here's the benchmark results comparing Go 1.14.15 and Go 1.15.8:

name          old time/op  new time/op  delta
InCharSet-12  10.5ns ± 1%  15.7ns ± 0%  +49.90%  (p=0.008 n=5+5)

The results are similar on tip.

The generated code used to use a BT instruction, but now it uses a longer sequence instead.

Go 1.14.15:

btregression.go:6       MOVL BX, SI
btregression.go:6       SHRL $0x6, BL
btregression.go:6       MOVZX BL, BX
btregression.go:6       LEAQ github.com/cespare/misc/btregression.charSet(SB), DI
btregression.go:6       MOVQ 0(DI)(BX*8), BX
btregression.go:6       BTQ SI, BX
btregression_test.go:9  JAE 0x4fd5ed

Go 1.15.8

btregression.go:6       MOVL BX, SI
btregression.go:6       SHRL $0x6, BL
btregression.go:6       MOVZX BL, BX
btregression_test.go:6  MOVQ CX, DI
btregression.go:6       MOVL SI, CX
btregression.go:6       MOVL $0x1, R8
btregression.go:6       SHLQ CL, R8
btregression.go:6       LEAQ github.com/cespare/misc/btregression.charSet(SB), SI
btregression.go:6       ANDQ 0(SI)(BX*8), R8
btregression.go:6       TESTQ R8, R8
btregression_test.go:9  JE 0x50a28d

I bisected the change back to 98cb767 (CL 217097).

/cc @randall77 @josharian

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 12, 2021
@randall77 randall77 added this to the Go1.17 milestone Feb 12, 2021
@randall77 randall77 self-assigned this Feb 12, 2021
@gopherbot
Copy link

Change https://golang.org/cl/291749 mentions this issue: cmd/compile: improve bit test code

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 13, 2021
@golang golang locked and limited conversation to collaborators Feb 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Performance
Projects
None yet
Development

No branches or pull requests

6 participants