-
Notifications
You must be signed in to change notification settings - Fork 13.6k
try
block prevents LLVM from identifying a throwing path is unreachable
#126670
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
Comments
#46035 seems related. |
@llvm/issue-subscribers-clang-codegen Author: Jeremy Rifkin (jeremy-rifkin)
For the following code LLVM inlines `std::vector::at` and optimizes away the bounds check
```cpp
std::vector<int> without_try_catch() {
std::vector<int> v(10'000);
for(int i = 0; i < 10'000; ++i) {
v.at(i) = i;
}
return v;
}
```
However, for the following, the presence of a std::vector<int> with_try_catch() {
std::vector<int> v(10'000);
for(int i = 0; i < 10'000; ++i) {
try {
v.at(i) = i;
} catch(...) {}
}
return v;
} As a result this dead-code CE link: https://godbolt.org/z/e3sT1z4bd |
-debug-only=gvn says:
Not sure how it's reaching that conclusion. The aliasing between the "catch" and the vector ultimately prevents analyzing the vector: we can't prove the vector isn't reallocated by the catch. (It's as if the user wrote something like |
This is because we're not treating extractvalue as an escape source. It would make sense to do that as long as CaptureTracking doesn't try to track captures through aggregates. |
CaptureTracking considers insertions into aggregates and vectors as captures. As such, extractions from aggregates and vectors are escape sources. A non-escaping identified local cannot alias with the result of an extractvalue/extractelement. Fixes llvm#126670.
…urces (#127640) CaptureTracking considers insertions into aggregates and vectors as captures. As such, extractions from aggregates and vectors are escape sources. A non-escaping identified local cannot alias with the result of an extractvalue/extractelement. Fixes llvm/llvm-project#126670.
For the following code LLVM inlines
std::vector::at
and optimizes away the bounds checkHowever, for the following, the presence of a
try
/catch
precludes LLVM from proving away the bounds check and the subsequent throwing path.As a result this dead-code
try
/catch
results in far worse codegen.CE link: https://godbolt.org/z/e3sT1z4bd
The text was updated successfully, but these errors were encountered: