Skip to content

Add codegen test for removing trailing zeroes from NonZero #145393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

clubby789
Copy link
Contributor

@clubby789 clubby789 commented Aug 14, 2025

Closes #138497

@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 14, 2025
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).

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removing trailing zeros of a NonZero
4 participants