You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.
use std::ptr::NonNull;// type Value = NonNull<i64>;typeValue = *consti64;pubfnpop2(stack:&mutVec<Value>) -> (Value,Value){assert!(stack.len() >= 2);let b = stack.pop().unwrap();let a = stack.pop().unwrap();(a, b)}
optimizes differently based on if Value is *const i64 or NonNull<i64> (or apparently any other type with niche optimizations, like &i64 or NonZeroI64).
Vec::pop returns Option<T>, so NonNull gets a niche opt there, which confuses LLVM. -Copt-level=3 --emit llvm-ir -Cno-prepopulate-passes shows what I assume is the key difference:
For Option<*const i64> we just load the discriminant from the option.
For Option<NonNull<i64>> we need a select to compute the discriminant.
Noratrieb
added
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
labels
Jan 25, 2023
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.
This code:
optimizes differently based on if
Value
is*const i64
orNonNull<i64>
(or apparently any other type with niche optimizations, like&i64
orNonZeroI64
).Reproducer
Specifically,
*const i64
has the unwrap panic checks optimized out,while
NonNull<i64>
keeps them.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: