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

cespare opened this issue Feb 12, 2021 · 1 comment
FrozenDueToAge NeedsFix Performance


Copy link

@cespare 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?


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


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:

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, 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, 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 label Feb 12, 2021
@randall77 randall77 added this to the Go1.17 milestone Feb 12, 2021
@randall77 randall77 self-assigned this Feb 12, 2021
Copy link

@gopherbot gopherbot commented Feb 12, 2021

Change mentions this issue: cmd/compile: improve bit test code

@dmitshur dmitshur added NeedsFix and removed NeedsInvestigation 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.
FrozenDueToAge NeedsFix Performance
None yet

No branches or pull requests

6 participants