Skip to content

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

Closed

Description

@dsnet

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.

Activity

  1. randall77 commented on Mar 19, 2024

    @randall77
    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
    
  2. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Mar 20, 2024
  3. added this to the Unplanned milestone on Mar 20, 2024
  4. gopherbot commented on Mar 21, 2024

    @gopherbot
    Contributor

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

  5. added a commit that references this issue on Mar 21, 2024
    802473c
  6. locked and limited conversation to collaborators on Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions