[llvm] [BasicBlockUtils] Remove redundant llvm.dbg instructions after blocks to reduce compile time (PR #89069)

Jorge Gorbe Moya via llvm-commits llvm-commits at lists.llvm.org
Fri May 3 12:10:18 PDT 2024


slackito wrote:

We've bisected a compilation time increase to this patch. It seems to introduce quadratic behavior in SimplifyCFG. The source code of a possible reproducer looks like this:
```
#include <map>
#include <string>

void regression() {
  static const std::map<int, std::string>* m = new std::map<int, std::string>({
      {1, "1"},       {2, "2"},       {3, "3"},       {4, "4"},
      // Many more such nodes in the map. With around 1200 nodes I see a
      // slowdown of ~20 seconds.
  });
  (void)m;
}
```
Unfortunately, reproducing the problem from this source code requires a profile I can't share, so the source code is useful for illustrative purposes only.

However, I was able to dump the IR using `-mllvm -print-after=sample-profile` to get a standalone reproducer (see `slowdown.ll.txt` attached, Github didn't like a `.ll` attachment). You should be able to verify the slowdown by running `opt -O1 -o /dev/null slowdown.ll`. Apologies for the big file. I've tried to reduce it but it looks like a quadratic scaling problem so the input needs to reach a certain size before the performance begins to be noticeably problematic.

I'm also attaching two `--time-trace` profiles, before and after this change. You can visualize them using the Chrome profile viewer at `chrome://tracing` or https://ui.perfetto.dev. Hopefully the stack of passes in the flame graph will be more helpful to diagnose the problem.

[before.json](https://github.com/llvm/llvm-project/files/15204003/before.json)
[after.json](https://github.com/llvm/llvm-project/files/15204005/after.json)
[slowdown.ll.txt](https://github.com/llvm/llvm-project/files/15204007/slowdown.ll.txt)


https://github.com/llvm/llvm-project/pull/89069


More information about the llvm-commits mailing list