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

Comments

Projects
None yet
2 participants
@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

This comment has been minimized.

Copy link
Contributor

randall77 commented Mar 20, 2019

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

This comment has been minimized.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.