We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 52daa7d commit 82a79b9Copy full SHA for 82a79b9
tests/codegen/issues/issue-129795.rs
@@ -0,0 +1,16 @@
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 a power-of-two is properly optimized.
6
7
+// CHECK-LABEL: @modulo_with_power_of_two_divisor
8
+// CHECK: add i64 %divisor, -1
9
+// CHECK-NEXT: and i64
10
+// CHECK-NEXT: ret i64
11
+#[no_mangle]
12
+pub fn modulo_with_power_of_two_divisor(dividend: u64, divisor: u64) -> u64 {
13
+ assert!(divisor.is_power_of_two());
14
+ // should be optimized to (dividend & (divisor - 1))
15
+ dividend % divisor
16
+}
0 commit comments