llvm / llvm/llvm-project

Significant IR compilation regression from LLVM 21 to LLVM 22

Open
#182,954 12 comments 0 reactions 0 assignees View on GitHub
slow-compile
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Branching from #179611, I have found **a broader LLVM JIT perf regression**. I can demonstrate this using an unmodified `clang-repl`, simply by creating many symbols and asking LLVM to resolve one of them.

**I believe everyone on Linux using ORC is affected by this, though they may not realize it yet.**

## `test.cpp`
```cpp
template struct SymbolFactory {
static void create() { SymbolFactory::create(); }
};

template <> struct SymbolFactory<0> {
static void create() {}
};

extern "C" int printf(const char *, ...);
extern "C" void find_me() {
SymbolFactory<1000>::create();
printf("found!\n");
}
```

## Timing
To run this test, we just need to invoke `clang-repl` and tell it to include this file.

```bash
time echo -e "#include \"test.cpp\"\n find_me();" | clang-repl
```

## Results
Note the exponential growth here.

|| LLVM 21 | LLVM 22|
| --| -- | -- |
|N=1 | 36ms | 45ms|
|N=100|51ms|80ms|
|N=500|135ms|355ms|
|N=1000| 300ms | 1800ms|
|N=2000|450ms|8700ms|

Image

## Flamegraph (click to expand)
Image

## Notes
This problem is not specific to the `SymbolFactory` template. That is just a helper to create more symbols. Instead, if we just did the following, to introduce 1000 symbols, we would arrive at the same performance discrepancy between LLVM 21 and LLVM 22.

```cpp
void foo1() {}
void foo2() {}
// ... continue until foo1000
```

Contributor guide

Open the contributing guide

Research direction

Start with the test.cpp reproducer and run the provided clang-repl timing command under LLVM 21 and LLVM 22. Use the supplied flamegraph and measurements at increasing symbol counts to locate the regression in the LLVM JIT/ORC path. Done means identifying the cause and demonstrating that the performance discrepancy or scaling regression is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli, compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.