cmd/compile: checking pointers for nilness inside a loop #41666
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
y
What operating system and processor architecture are you using (
go env
)?amd64
What did you do?
Tried to optimize a function by replacing a slice parameter with known size with a
*[N]T
parameter, in principle reducing the number of things passed to the function.https://godbolt.org/z/hz68Mn
What did you expect to see?
I'm honestly not sure, the whole exercise was perhaps doomed from the start.
What did you see instead?
There's extra tests. Well, not quite extra. But there's a
test al, cx
(spelled slightly differently in pprof output) before the first access to a given array in the function, which happens to be inside a loop, meaning that the test gets hit hundreds of times. Of course, it can't just be hoisted out of the loop in full generality -- if the loop only sometimes got hit, hitting the test before the loop would be bad, and if there are side-effects or something inside the loop, you don't want to panic before them. The corresponding slice case doesn't need this, because a slice with a nil pointer also has a 0 len and thus the loop doesn't get entered.Adding
_ = l1[0]
(for each value) to the top of the function does eliminate these.I'm not sure whether this could be trivially fixed but it feels like a lot of tests to keep testing for nilness for a pointer every time you use it...
The text was updated successfully, but these errors were encountered: