cmd/compile: negative shift check with trailing zeros #42094
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?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Tried to remove the trailing bit in a loop.
A simple example of this pattern which counts each bit: https://play.golang.org/p/iQc490A5DRV
Same thing with instruction dump: https://godbolt.org/z/E54rY4
What did you expect to see?
The compiler produces a tight loop, optimizing away the negative shift check.
It would be nice if the bounds check could be eliminated too, but that does not seem to be quite as straightforward to prove.
What did you see instead?
There is a runtime check to see if
bits.TrailingZeros64
is negative.The text was updated successfully, but these errors were encountered: