Skip to content

cmd/compile: unnecessary slice literal zeroing #45573

Open
@icholy

Description

@icholy

Keyless slice literals zero the backing array and then immediately overwrite it. https://godbolt.org/z/5bx9TPo7n

What operating system and processor architecture are you using?

linux amd64

What did you do?

package main

func main() {
    a := []int{1, 2, 3, 4}
    println(a)
}

What did you expect to see?

movq    $1, ""..autotmp_2+24(SP)
movq    $2, ""..autotmp_2+32(SP)
movq    $3, ""..autotmp_2+40(SP)
movq    $4, ""..autotmp_2+48(SP)

What did you see instead?

leaq    ""..autotmp_2+24(SP), AX
xorps   X15, X15
movups  X15, (AX)
leaq    ""..autotmp_2+40(SP), CX
xorps   X15, X15
movups  X15, (CX)
movq    $1, ""..autotmp_2+24(SP)
movq    $2, ""..autotmp_2+32(SP)
movq    $3, ""..autotmp_2+40(SP)
movq    $4, ""..autotmp_2+48(SP)

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe 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

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions