New MIR opt pass simplify_pow_of_two#114254
Closed
Centri3 wants to merge 5 commits intorust-lang:masterfrom
Closed
New MIR opt pass simplify_pow_of_two#114254Centri3 wants to merge 5 commits intorust-lang:masterfrom
simplify_pow_of_two#114254Centri3 wants to merge 5 commits intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This detects calls to
x.powwherexis a power of two and an integer. This can use shl instead, with some nuances. Unfortunately modifyingpowinstead results in this check being done at runtime, and also getting the power used, thus is even slower than without it.Supersedes the clippy lint rust-lang/rust-clippy#11057
I haven't benchmarked this yet but from my testing, without debug assertions this has 0 branches, thus is branchless, and only has a couple instructions, so I'm 99% confident this is faster. With debug assertions, I'm not sure,
custom_mirdoesn't really like assertions 😅For calls where
xis not 2, the rhs for shl can beexp * <power used to get x>.Hope I did everything right ^^