llvm / llvm/llvm-project

missed optimization: combine writes to atomics

Open
#196,180 2 comments 0 reactions 0 assignees View on GitHub
missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

We should be able to combine atomic operations to the same address the same way we do with non-atomic operations.

https://godbolt.org/z/K54M5Y7e3

```
void foo(std::atomic& r) {
r.fetch_add(2, std::memory_order_relaxed);
r.fetch_add(4, std::memory_order_relaxed);
}

void foo2(std::atomic& r) {
r.fetch_add(6, std::memory_order_relaxed);
}

void bar(int& r) {
r += 2;
r += 4;
}

void bar2(int& r) {
r += 6;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.