Open
Description
Bugzilla Link | 37690 |
Version | trunk |
OS | Linux |
CC | @DougGregor,@RKSimon,@rotateright,@TNorthover |
Extended Description
This is from an example to prove that atomic_thread_fence does not prevent the compiler from optimizing non-escaped memory.
https://godbolt.org/g/WXFdPL
#include <utility>
#include <atomic>
struct Type {
Type(Type&&)=default;
int i;
};
Type func(Type t) {
auto out = Type(Type(std::move(t)));
std::atomic_thread_fence(std::memory_order_seq_cst);
return out;
}
auto func2(Type t) { return func(func(func(func(std::move(t))))); }
func(Type): # @func(Type)
mfence
mov eax, edi
ret
func2(Type): # @func2(Type)
mfence
mfence
mfence
mfence
mov eax, edi
ret