Add codegen test for modulo with power-of-two divisor
This commit is contained in:
parent
52daa7d835
commit
82a79b99e1
1 changed files with 16 additions and 0 deletions
16
tests/codegen/issues/issue-129795.rs
Normal file
16
tests/codegen/issues/issue-129795.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
//@ compile-flags: -Copt-level=3
|
||||
//@ min-llvm-version: 20
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// Ensure that a modulo operation with an operand that is known to be a power-of-two is properly optimized.
|
||||
|
||||
// CHECK-LABEL: @modulo_with_power_of_two_divisor
|
||||
// CHECK: add i64 %divisor, -1
|
||||
// CHECK-NEXT: and i64
|
||||
// CHECK-NEXT: ret i64
|
||||
#[no_mangle]
|
||||
pub fn modulo_with_power_of_two_divisor(dividend: u64, divisor: u64) -> u64 {
|
||||
assert!(divisor.is_power_of_two());
|
||||
// should be optimized to (dividend & (divisor - 1))
|
||||
dividend % divisor
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue