Open
Description
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.