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: missing combine constant store cases on amd64 #53324

Closed
wdvxdr1123 opened this issue Jun 10, 2022 · 4 comments
Closed

cmd/compile: missing combine constant store cases on amd64 #53324

wdvxdr1123 opened this issue Jun 10, 2022 · 4 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Milestone

Comments

@wdvxdr1123
Copy link
Contributor

What version of Go are you using (go version)?

gotip

What did you do?

func a(b []byte, idx int) {
	binary.LittleEndian.PutUint64(b[idx:], 123)
}

What did you expect to see?

MOVQ $123, (AX)(DX*1)

What did you see instead?

MOVB $123, (AX)(DI*1)
MOVB $0, 1(AX)(DI*1)
MOVB $0, 2(AX)(DI*1)
MOVB $0, 3(AX)(DI*1)
MOVB $0, 4(AX)(DI*1)
MOVB $0, 5(AX)(DI*1)
MOVB $0, 6(AX)(DI*1)
MOVB $0, 7(AX)(DI*1)
@gopherbot
Copy link

Change https://go.dev/cl/411614 mentions this issue: cmd/compile: combine more constant stores on amd64

@cherrymui cherrymui added Performance NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 10, 2022
@cherrymui cherrymui added this to the Unplanned milestone Jun 10, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
@klauspost
Copy link
Contributor

I am also seeing this for non-constants, eg binary.LittleEndian.PutUint64(a, binary.LittleEndian.Uint64(b)) will for non-trivial cases outputs:

        MOVQ    (AX)(DX*1), DX
[...]
        MOVB    DL, (AX)(DI*1)
        MOVQ    DX, SI
        SHRQ    $8, DX
        MOVL    DX, 1(AX)(DI*1)
        MOVQ    SI, DX
        SHRQ    $40, SI
        MOVW    SI, 5(AX)(DI*1)
        SHRQ    $56, DX
        MOVB    DL, 7(AX)(DI*1)

Load is fine, but the store is split into an 8 byte write, a 32 bit write, a 16 bit write and finally an 8 bit write. Seems rather random.

@randall77
Copy link
Contributor

@klauspost Yes, that doesn't look good. Should be fixable somehow.

@randall77 randall77 modified the milestones: Unplanned, Go1.20 Jul 28, 2022
@randall77
Copy link
Contributor

I'm going to open a second issue for Klaus's example, as there's already a CL to fix the OP's case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Projects
None yet
Development

No branches or pull requests

6 participants