Skip to content

Commit b651be2

Browse files
authored
Rollup merge of #145393 - clubby789:issue-138497, r=Mark-Simulacrum
Add codegen test for removing trailing zeroes from `NonZero` Closes #138497
2 parents 75963ce + 76438f0 commit b651be2

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! This test checks that removing trailing zeroes from a `NonZero`,
2+
//! then creating a new `NonZero` from the result does not panic.
3+
4+
//@ min-llvm-version: 21
5+
//@ compile-flags: -O -Zmerge-functions=disabled
6+
#![crate_type = "lib"]
7+
8+
use std::num::NonZero;
9+
10+
// CHECK-LABEL: @remove_trailing_zeros
11+
#[no_mangle]
12+
pub fn remove_trailing_zeros(x: NonZero<u8>) -> NonZero<u8> {
13+
// CHECK: %[[TRAILING:[a-z0-9_-]+]] = {{.*}} call {{.*}} i8 @llvm.cttz.i8(i8 %x, i1 true)
14+
// CHECK-NEXT: %[[RET:[a-z0-9_-]+]] = lshr exact i8 %x, %[[TRAILING]]
15+
// CHECK-NEXT: ret i8 %[[RET]]
16+
NonZero::new(x.get() >> x.trailing_zeros()).unwrap()
17+
}

0 commit comments

Comments
 (0)