diff options
| author | 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> | 2025-03-16 09:40:09 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-16 09:40:09 +0800 |
| commit | c05a643ca87aec724ef2aa9c44ef9de1ba223d8c (patch) | |
| tree | f011f4f15d72ac06ebd65d8b3868bd26199f0803 | |
| parent | 7c1555cb9bb6c69927e80c3d284ed2555598e547 (diff) | |
| parent | ccde0a22035dee21373c5c7f47c50aaa484ba70e (diff) | |
| download | rust-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.rs | 17 |
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 +} |
