Closed
Description
I have noticed that for example NonZero
integers are not assumed to be non-zero.
pub fn leading_zeros(x: NonZeroU32) -> u32 {
//unsafe { std::intrinsics::assume(x.get() != 0) };
x.get().leading_zeros()
}
pub fn is_zero(x: NonZeroU32) -> bool {
//unsafe { std::intrinsics::assume(x.get() != 0) };
x.get() == 0
}
example::leading_zeros:
test edi, edi ; check if it is zero
je .LBB1_2
bsr eax, edi
xor eax, 31
ret
.LBB1_2:
mov eax, 32
ret
example::is_zero:
test edi, edi ; check if it is zero
sete al
ret
(it also affects division)
Manually adding intrinsics::assume
fixes that issue, but this cannot be used in const
functions.
Related to #79114 and #79134