Closed
Description
I tried this code:
#[no_mangle]
pub fn index(key: usize, buckets: usize) -> usize {
assert!(buckets.is_power_of_two());
key % buckets
}
Since assert!(buckets.is_power_of_two())
is run (and .is_power_of_two()
is an inbuilt function), the latter modulus operation should reduce to key & (buckets - 1)
.
Instead, the outputted assembly here shows that this reduction does not take place.
Meta
The compiler in the GodBolt link is version 1.80.0.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: An issue highlighting optimization opportunities or PRs implementing suchCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.