about summary refs log tree commit diff
path: root/tests/codegen-llvm/issues/issue-129795.rs
blob: 7a928389fab2d35cf19e82bd5f582c9b0bb0bf94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//@ compile-flags: -Copt-level=3
#![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
}