Will two loads be combined with one in such scenarios? If it depends on the architecture, what will happen in the case of modern processors from Intel? I believe that atomic loads are equivalent to normal loads in Intel processors.
void run1() {
auto a = atomic_var.load(std::memory_order_relaxed);
auto b = atomic_var.load(std::memory_order_relaxed);
}
void run2() {
if (atomic_var.load(std::memory_order_relaxed) == 2 && ...) {
if (atomic_var.load(std::memory_order_relaxed) * somevar > 3) {
}
}
}
run1()and run2()are just two scenarios using two loads of the same atomic variable. Can the compiler collapse such two load scenarios into one load and reuse it?
source
share