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: coalesce adjacent writes to struct fields #66413

Closed
dsnet opened this issue Mar 19, 2024 · 2 comments
Closed

cmd/compile: coalesce adjacent writes to struct fields #66413

dsnet opened this issue Mar 19, 2024 · 2 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done. Performance
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Mar 19, 2024

Go version

go1.22

Output of go env in your module/workspace:

GOARCH=amd64
GOOS=linux

What did you do?

Compile the following:

var sink A

func main() {
	sink = A{31, false, true, 12}
}

type A struct {
	a byte
	b bool
	c bool
	d int8
}

What did you see happen?

The compiler output something like:

0x0000 00000 (main.go:13)	MOVB	$31, main.sink(SB)
0x0007 00007 (main.go:13)	MOVB	$0, main.sink+1(SB)
0x000e 00014 (main.go:13)	MOVB	$1, main.sink+2(SB)
0x0015 00021 (main.go:13)	MOVB	$12, main.sink+3(SB)

What did you expect to see?

A single MOVL instruction.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 19, 2024
@randall77
Copy link
Contributor

Looks like just an oversight of the bool case in cmd/compile/internal/ssa/memcombine.go.
This patch fixes it, maybe:

--- a/src/cmd/compile/internal/ssa/memcombine.go
+++ b/src/cmd/compile/internal/ssa/memcombine.go
@@ -534,7 +534,7 @@ func combineStores(root *Value, n int64) bool {
        isConst := true
        for i := int64(0); i < n; i++ {
                switch a[i].store.Args[1].Op {
-               case OpConst32, OpConst16, OpConst8:
+               case OpConst32, OpConst16, OpConst8, OpConstBool:
                default:
                        isConst = false
                        break

@dr2chase dr2chase added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 20, 2024
@mknyszek mknyszek added this to the Unplanned milestone Mar 20, 2024
@gopherbot
Copy link

Change https://go.dev/cl/573416 mentions this issue: cmd/compile: include constant bools in memcombine

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. NeedsFix The path to resolution is known, but the work has not been done. Performance
Projects
Development

No branches or pull requests

5 participants