about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2025-03-16 09:40:09 +0800
committerGitHub <noreply@github.com>2025-03-16 09:40:09 +0800
commitc05a643ca87aec724ef2aa9c44ef9de1ba223d8c (patch)
treef011f4f15d72ac06ebd65d8b3868bd26199f0803
parent7c1555cb9bb6c69927e80c3d284ed2555598e547 (diff)
parentccde0a22035dee21373c5c7f47c50aaa484ba70e (diff)
downloadrust-c05a643ca87aec724ef2aa9c44ef9de1ba223d8c.tar.gz
rust-c05a643ca87aec724ef2aa9c44ef9de1ba223d8c.zip
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.
-rw-r--r--tests/codegen/issues/issue-129795.rs17
1 files changed, 17 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..dc64ee35c97
--- /dev/null
+++ b/tests/codegen/issues/issue-129795.rs
@@ -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
+}