-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Missed Optimization for NonZeroU32 to NonZeroUsize Conversions #119422
Comments
@rustbot label C-optimization I-heavy I-slow T-compiler |
As I understand, the root cause of this is that LLVM doesn't support This The only good thing is that if your values are stored in memory (e.g. in some vector), it would be optimized correctly. |
Another example: godbolt pub fn non_zero_cmp(a: NonZeroU32)->bool {
a.get() == 0
} It should generate just example::non_zero_cmp:
test edi, edi
sete al
ret @zmtaub May you rename your issue to "Compiler fails to optimize NonZero integers passed as function parameters"? |
Made a LLVM issue. |
LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang#119422 Related to llvm/llvm-project#76628
I started to work on issue. |
Duplicate of #49572. |
LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang#119422 Related to llvm/llvm-project#76628 Related to rust-lang#49572
…get_assume_nonzero, r=<try> Add assume into `NonZeroIntX::get` LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang#119422 Related to llvm/llvm-project#76628 Related to rust-lang#49572
LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang#119422 Related to llvm/llvm-project#76628 Related to rust-lang#49572
LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang#119422 Related to llvm/llvm-project#76628 Related to rust-lang#49572
…get_assume_nonzero, r=<try> Add assume into `NonZeroIntX::get` LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang#119422 Related to llvm/llvm-project#76628 Related to rust-lang#49572
…get_assume_nonzero, r=scottmcm Add assume into `NonZeroIntX::get` LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang#119422 Related to llvm/llvm-project#76628 Related to rust-lang#49572
…e_nonzero, r=scottmcm Add assume into `NonZeroIntX::get` LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang/rust#119422 Related to llvm/llvm-project#76628 Related to rust-lang/rust#49572
…e_nonzero, r=scottmcm Add assume into `NonZeroIntX::get` LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang/rust#119422 Related to llvm/llvm-project#76628 Related to rust-lang/rust#49572
…e_nonzero, r=scottmcm Add assume into `NonZeroIntX::get` LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments. Related to rust-lang/rust#119422 Related to llvm/llvm-project#76628 Related to rust-lang/rust#49572
I tried this code:
I expected to see this happen:
I expected equivalent assembly generated for each function on 64-bit platforms when compiling with
-C opt-level=3
.Indeed, if
f3
is removed, this assembly is generated according to Compiler Explorer:Instead, this happened:
According to Compiler Explorer, this assembly is generated:
The
try_into().unwrap()
isn't optimized away forf3
, unlike the other functions.Compiler Explorer link
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: