Rollup merge of #138472 - KonaeAkira:master, r=Mark-Simulacrum

Add codegen test for #129795

Adds test for #129795.

Min LLVM version is 20 because the optimization only happens since LLVM 20.
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2025-03-16 09:40:09 +08:00 committed by GitHub
commit c05a643ca8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,17 @@
//@ 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
}