Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! This test checks that removing trailing zeroes from a `NonZero`,
//! then creating a new `NonZero` from the result does not panic.

//@ min-llvm-version: 21
//@ compile-flags: -O -Zmerge-functions=disabled
#![crate_type = "lib"]

use std::num::NonZero;

// CHECK-LABEL: @remove_trailing_zeros
#[no_mangle]
pub fn remove_trailing_zeros(x: NonZero<u8>) -> NonZero<u8> {
// CHECK-NOT: unwrap_failed
// CHECK-NOT: br
// CHECK ret i8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check the exact instruction sequence?

  %0 = tail call range(i8 0, 9) i8 @llvm.cttz.i8(i8 %x, i1 true)
  %n = lshr exact i8 %x, %0
  ret i8 %n

It seems unlikely to change from cttz + lshr + ret, and that seems less brittle than checking for absence of particular words (br/unwrap).

NonZero::new(x.get() >> x.trailing_zeros()).unwrap()
}
Loading