-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Closed
Copy link
Labels
llvm:analysisIncludes value tracking, cost tables and constant foldingIncludes value tracking, cost tables and constant foldingmissed-optimization
Description
For the following code LLVM inlines std::vector::at
and optimizes away the bounds check
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 try
/catch
precludes LLVM from proving away the bounds check and the subsequent throwing path.
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 try
/catch
results in far worse codegen.
CE link: https://godbolt.org/z/e3sT1z4bd
HolyBlackCat, frederick-vs-ja, yeetfield and OfekShilon
Metadata
Metadata
Assignees
Labels
llvm:analysisIncludes value tracking, cost tables and constant foldingIncludes value tracking, cost tables and constant foldingmissed-optimization