Open jordanlewis opened 4 years ago
@brtzsnr @rasky @zdjones
It's not just the bounds check, it is also reloading the backing store pointer every time. c
is somehow being treated as having its address taken. I don't understand why that is.
You can fix this by doing
run(func() {
a := c
_ = a[n-1]
for i := 0; i < n; i++ {
a[i] = v
}
})
a := c[:n]
also works.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, using
amd64 gc (tip)
on go.godbolt.org.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I loaded the following program into go.godbolt.org:
https://go.godbolt.org/z/iPaz7f
What did you expect to see?
I expected that the bounds check for
c[i]
would be eliminated because of the early bounds check triggered byc[n-1]
, the way that it would if the inner loop wasn't sent as a closure torun
.This should be possible because
c
doesn't get assigned to within the closure.What did you see instead?
The compiler emits a bounds check for
c[i]
.