Skip to content

cmd/compile: inline small static initializers #18872

@randall77

Description

@randall77
type T struct {
	a, b, c, d int
}
func f(p *T) {
	*p = T{1, 2, 3, 4}
}

The code for f is:

(tmp1.go:8)	MOVQ	"".statictmp_0(SB), AX
(tmp1.go:8)	MOVQ	"".statictmp_0+8(SB), CX
(tmp1.go:8)	MOVQ	"".statictmp_0+16(SB), DX
(tmp1.go:8)	MOVQ	"".statictmp_0+24(SB), BX
(tmp1.go:8)	MOVQ	"".p+8(FP), SI
(tmp1.go:8)	MOVQ	AX, (SI)
(tmp1.go:8)	MOVQ	CX, 8(SI)
(tmp1.go:8)	MOVQ	DX, 16(SI)
(tmp1.go:8)	MOVQ	BX, 24(SI)

That's kind of dumb to copy from a statictmp. Just use MOVQ $1, (SI) and so forth.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions