Skip to content

cmd/compile: storing strings doesn't take advantage of paired stores on arm64 #72741

Open
@randall77

Description

@randall77
func f(p *string, s string) {
	*p = s
}

Compiles to:

	0x001c 00028 	MOVD	R2, 8(R0) // write length
	0x0020 00032 	MOVWU	runtime.writeBarrier(SB), R2
	0x0028 00040 	CBZW	R2, 56
	0x002c 00044 	MOVD	(R0), R2 // load old pointer
	0x0030 00048 	CALL	runtime.gcWriteBarrier2(SB)
	0x0034 00052 	STP	(R1, R2), (R25) // write new ptr & old ptr to write barrier buffer
	0x0038 00056 	MOVD	R1, (R0) // write new ptr

It would be nice if we wrote the length and ptr together at the end (effectively merging the first and last instructions).

The length and ptr writes get separated because the write barrier pass picks the smallest set of writes to include in the barrier. Which in this case, is just the one pointer write. Maybe we could include one more non-ptr write in the barrier group if we know it could be merged with a pointer write.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.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