Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: runtime check for availability of popcount is spammy #30946

Open
seebs opened this issue Mar 20, 2019 · 2 comments
Open

cmd/compile: runtime check for availability of popcount is spammy #30946

seebs opened this issue Mar 20, 2019 · 2 comments
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

Comments

@seebs
Copy link
Contributor

seebs commented Mar 20, 2019

What version of Go are you using (go version)?

$ go version
1.12 (but also 1.11)

Does this issue reproduce with the latest release?

seems to

What operating system and processor architecture are you using (go env)?

amd64

What did you do?

Was looking at an unrolled loop.

https://godbolt.org/z/GQuZaf

What did you expect to see?

A test for whether the target system had popcount.

What did you see instead?

Four separate tests per unrolled loop, and the tests repeating every time through the loop.

This seems like it should be a cacheable result. It might even be worth generating two copies of the loop; the cost of all those branches is large, and doing a single branch up front would be nicer. I don't think there's any facility available to me to let me write the branch in my own code.

@randall77
Copy link
Contributor

Unfortunately, the compiler doesn't know that the global being checked is unchanging.
We could probably hack in a special case for feature flags like this.

Duplicating the loop would be harder. The compiler doesn't have the facility for optimizations like that at the moment.

@mikioh mikioh changed the title Runtime check for availability of popcount is spammy cmd/compile: Runtime check for availability of popcount is spammy Mar 20, 2019
@seebs
Copy link
Contributor Author

seebs commented Mar 20, 2019

It might be a cool feature to have a way to express that, like

if runtime.CpuFeature(x) {

which could contain enough compiler hint that the compiler could omit such runtime checks. Although it'd look really silly to just write the exact same loop on both sides of an if. :)

@randall77 randall77 added this to the Unplanned milestone Mar 20, 2019
@julieqiu julieqiu changed the title cmd/compile: Runtime check for availability of popcount is spammy cmd/compile: runtime check for availability of popcount is spammy May 28, 2019
@julieqiu julieqiu added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 28, 2019
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants