-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
leading_zeros() return value is still bounds checked #83779
Copy link
Copy link
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
Type
Fields
Give feedbackNo fields configured for issues without a type.
leading_zeros()can return at most the number of bits of the underlying data type. The compiler does not seem to consider this during optimization.Code
Tested on
rustc 1.51.0 (2fd73fabe 2021-03-23),nightlyin the Compiler Explorer with-C opt-level=3.I expect the unsafe block to have no effect, since
u64::leading_zeros()shouldn't return a number greater than 64. Instead, the disassembly shows that there is a bounds check which disappears when theunsafeblock is uncommented.