Missing optimization with multiply-inlined magic statics
Open
llvm:optimizations
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
If a function with magic static is inlined into another function multiple times, it is inlined very literally; code for checking that the static variable was initialized, initializing it if it wasn't, and even the load itself are duplicated.
[*Example on godbolt*](https://godbolt.org/z/xsYT8nMd6)
```cpp
int opaque();
int adjust() {
static int base = opaque(); // force non-constant initialization
return base;
}
int double_adjusted() {
return adjust() + adjust();
}
```
The code for `double_adjusted` should check the guard variable just once, and produce the return value with the equivalent of `2 * adjust()`.
Contributor guide
Assessment
This issue has not been assessed yet.