Missed NonZero optimization opportunity #60044
Labels
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.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Godbolt link
When a
NonZeroUsize
is created throughnew_unchecked
and wrapped in aSome
, the optimizer does not recognize that the value is alwaysSome
. This can be fixed by adding astd::intrinsics::assume(value != 0)
line before creating the NonZero type.Lots of panicking code gets generated in this example.
Fixed by:
I would guess that adding
assume
inside ofnew_unchecked
would be ok, since it's already UB if it's not zero.Related: #51346. Posted as a new issue, because it can be fixed without any LLVM pass changes.
The text was updated successfully, but these errors were encountered: