Go version
go version go1.25-devel_2363897 Sat Jul 19 21:15:12 2025 -0700 linux/amd64
Output of go env
in your module/workspace:
Using service on https://go.godbolt.org/
Selected "x86-64 gc (tip)"
What did you do?
I entered following program
const (
N = 1048576
NN = 1.0 / N
)
func Bar(a []float64) {
for i := range a {
a[i] *= NN
}
}
What did you see happen?
This was codegen result for a[i] *= NN part:
MOVSD (AX)(CX*8), X0
MOVSD $f64.3eb0000000000000(SB), X1
MULSD X1, X0
MOVSD X0, (AX)(CX*8)
https://go.godbolt.org/z/7cK5b54zh
What did you expect to see?
The statement MOVSD $f64.3eb0000000000000(SB), X1
should be happen once outside loop.
There is no statements that invalidates content of X1 register inside loop.