-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
optimisation opportunity missed due to assert! #45371
Copy link
Copy link
Open
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-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-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.
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-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I have noticed interesting behaviour regarding
assert!which was unexpected. I am not sure if this is a LLVM or Rust issue.in the following code (See godbolt link below) I have a vec like structure
OwnedRegion.I want to iterate over the region (implemented as
slice::IterMut) and populate an array.I expect LLVM to do loop unrolling and loop vectorisation. If you place
the necessary
intrinsics::assumeto trick llvm into removing the bound check you doindeed get the optimisations. However I wanted to replace the
assumewith anassert!but that removes the optimisation even if combined with an
assume! What I think is happeningis the bounds check is being reintroduced because the length check in the
assert!is being moved into the for loop or elided completely because it duplicates the length check in the index operation.What should happen is the bounds check in the for loop should be lifted/elided because of the
assert!with
assert!andassume:inner loops is:
where LBB6_4, LBB6_5, LBB6_8, and LBB6_10 jump to
std::panicwith just
assume:inner loops is:
here is a godbolt link