Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c05a643

Browse files
authoredMar 16, 2025
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.
2 parents 7c1555c + ccde0a2 commit c05a643

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎tests/codegen/issues/issue-129795.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ compile-flags: -Copt-level=3
2+
//@ min-llvm-version: 20
3+
#![crate_type = "lib"]
4+
5+
// Ensure that a modulo operation with an operand that is known to be
6+
// a power-of-two is properly optimized.
7+
8+
// CHECK-LABEL: @modulo_with_power_of_two_divisor
9+
// CHECK: add i64 %divisor, -1
10+
// CHECK-NEXT: and i64
11+
// CHECK-NEXT: ret i64
12+
#[no_mangle]
13+
pub fn modulo_with_power_of_two_divisor(dividend: u64, divisor: u64) -> u64 {
14+
assert!(divisor.is_power_of_two());
15+
// should be optimized to (dividend & (divisor - 1))
16+
dividend % divisor
17+
}

0 commit comments

Comments
 (0)
Failed to load comments.