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: for small objects, use constants directly instead of copying from statictmp #21561

randall77 opened this issue Aug 22, 2017 · 1 comment


None yet
3 participants
Copy link

commented Aug 22, 2017

func f() []int {
	return []int{7}


0x001d 00029 (tmp1.go:3)  LEAQ    type.[1]int(SB), AX
0x0024 00036 (tmp1.go:4)  MOVQ    AX, (SP)
0x0028 00040 (tmp1.go:4)  CALL    runtime.newobject(SB)
0x002d 00045 (tmp1.go:4)  MOVQ    8(SP), AX
0x0032 00050 (tmp1.go:4)  MOVQ    "".statictmp_0(SB), CX
0x0039 00057 (tmp1.go:4)  MOVQ    CX, (AX)

Note that the 7 is written by loading from a readonly global and writing to the slice. We should just use a

MOVQ $7, (AX)

for the last 2 lines.
Up to some small constant in size, emitting the constants explicitly instead of copying them from a statictmp is better.

@randall77 randall77 added this to the Go1.10 milestone Aug 22, 2017


This comment has been minimized.

Copy link

commented Aug 23, 2017

We do this a few places already. IIRC, the cutoff we have used for "up to some small constant in size" is whether it is SSA-able.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.