-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-layoutArea: Memory layout of typesArea: Memory layout of typesA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
Metadata
Metadata
Assignees
Labels
A-layoutArea: Memory layout of typesArea: Memory layout of typesA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.