about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKonaeAkira <longtruong2411@gmail.com>2025-03-14 01:27:07 +0100
committerKonaeAkira <longtruong2411@gmail.com>2025-03-14 01:27:07 +0100
commit82a79b99e1279ad72cb93c2ad10c6be1facaca4a (patch)
tree3365d8e9ba4ec0c9422ad5e8a2d9793becb70628
parent52daa7d835e7ff51cb387340082bf9a59b949738 (diff)
downloadrust-82a79b99e1279ad72cb93c2ad10c6be1facaca4a.tar.gz
rust-82a79b99e1279ad72cb93c2ad10c6be1facaca4a.zip
Add codegen test for modulo with power-of-two divisor
-rw-r--r--tests/codegen/issues/issue-129795.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/codegen/issues/issue-129795.rs b/tests/codegen/issues/issue-129795.rs
new file mode 100644
index 00000000000..7346227c53f
--- /dev/null
+++ b/tests/codegen/issues/issue-129795.rs
@@ -0,0 +1,16 @@
+//@ 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
+}