[llvm] [ThinLTO] optimize propagateAttributes performance (PR #132917)

Zhaoxuan Jiang via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 27 04:38:21 PDT 2025


nocchijiang wrote:

I managed to grab some interesting profiling data with a RelWithDebInfo `libLTO.dylib`.

# Baseline

![image](https://github.com/user-attachments/assets/def0f19c-b6b0-43de-879a-b3febde4ded0)

Most time are spent in `insert`:

![image](https://github.com/user-attachments/assets/f3063d33-6ef7-4fe2-8cd8-98355fc741bb)

```
19.52 min   68.9%        0 s                             llvm::detail::DenseSetImpl<llvm::ValueInfo, llvm::DenseMap<llvm::ValueInfo, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::ValueInfo, void>, llvm::detail::DenseSetPair<llvm::ValueInfo>>, llvm::DenseMapInfo<llvm::ValueInfo, void>>::insert(llvm::ValueInfo const&)
1.15 min    4.0%        0 s                             llvm::detail::DenseSetImpl<llvm::ValueInfo, llvm::DenseMap<llvm::ValueInfo, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::ValueInfo, void>, llvm::detail::DenseSetPair<llvm::ValueInfo>>, llvm::DenseMapInfo<llvm::ValueInfo, void>>::contains(llvm::ValueInfo const&) const
```

# `MarkedNonReadWriteOnly` in `GlobalValueSummaryInfo`

![image](https://github.com/user-attachments/assets/06f5af9d-a73d-478c-9288-e34bb74d9400)

# `MarkedNonReadWriteOnly` in `ValueInfo`

![image](https://github.com/user-attachments/assets/4c20c3e2-7c65-44cd-9b49-53fd80e875d1)

![image](https://github.com/user-attachments/assets/c5a4ab1d-8fbf-4cb7-90ab-aec763c34188)

I strongly suspect that the relationship between `ValueInfo` and `GlobalValueSummaryInfo` is not strictly 1-to-1, otherwise the 10x performance difference cannot be explained. This is also the reason why I initially decided to declare the flag in `GlobalValueSummaryInfo`: `DenseMapInfo<ValueInfo>` utilizes the pointer identity of `GlobalValueSummaryMapTy` entry, so the `MarkedNonReadWriteOnly` set was effectively marking the underlying `GlobalValueSummaryInfo` rather than `ValueInfo`. However, I am uncertain whether this is the expected behavior.


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


More information about the llvm-commits mailing list