We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 7c1555c + ccde0a2 commit c05a643Copy full SHA for c05a643
tests/codegen/issues/issue-129795.rs
@@ -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