Skip to content

Codegen can result in multiple sequential mfence instructions #37038

Open
@redbeard0531

Description

@redbeard0531
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzilla

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions