Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: optimize bits.OnesCount(x) == 1 #38547
It'd be nice for the compiler to be able to optimize
This is a bit tricky, because by the time we get to the rewrite rules, there's already a branch to check cpu feature availability.
If we figure this out, there might be other math/bits function result comparisons we want to optimize.
Implementation ideas welcome.
Updates #38547 file before after Δ % compile 19678112 19669808 -8304 -0.042% total 113143160 113134856 -8304 -0.007% Change-Id: I5f8afe17401dbdb7c7b3d66d95fe40821c499a92 Reviewed-on: https://go-review.googlesource.com/c/go/+/229127 Run-TryBot: Josh Bleecher Snyder <email@example.com> Reviewed-by: Brad Fitzpatrick <firstname.lastname@example.org>
This is the second attempt. The first attempt was CL 229127, which got rolled back by CL 229177, because it caused an infinite loop during compilation on some platforms. I didn't notice that the trybots hadn't completed when I submitted; mea culpa. The bug was that we were checking x&(x-1)==0, which is also true of 0, which does not have exactly one bit set. This caused an infinite rewrite rule loop. Updates #38547 file before after Δ % compile 19678112 19669808 -8304 -0.042% total 113143160 113134856 -8304 -0.007% Change-Id: I417a4f806e1ba61277e31bab2e57dd3f1ac7e835 Reviewed-on: https://go-review.googlesource.com/c/go/+/229197 Run-TryBot: Josh Bleecher Snyder <email@example.com> TryBot-Result: Gobot Gobot <firstname.lastname@example.org> Reviewed-by: Michael Munday <email@example.com>