From fd1952761ed3691ef118f6ef4c6cc51b4d37de75 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 29 May 2017 16:25:20 +0000 Subject: [PATCH] [X86] Don't fold away the memory operand of an xchg. xchg with a mem operand has different locking semantics. If we unfold it into a xchg r,r we will loose the implicit lock. Likewise we never want to fold a register xchg into a memory one as it would be a lot slower. This triggers during LLVM selfhost. llvm-svn: 304163 --- llvm/test/CodeGen/X86/xchg-nofold.ll | 37 ++++++++++++++++++++++++++++ llvm/utils/TableGen/X86FoldTablesEmitter.cpp | 9 ++++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/X86/xchg-nofold.ll diff --git a/llvm/test/CodeGen/X86/xchg-nofold.ll b/llvm/test/CodeGen/X86/xchg-nofold.ll new file mode 100644 index 0000000..fddc790 --- /dev/null +++ b/llvm/test/CodeGen/X86/xchg-nofold.ll @@ -0,0 +1,37 @@ +; RUN: llc -mtriple=x86_64-linux-gnu < %s | FileCheck %s + +%"struct.std::atomic" = type { %"struct.std::atomic_bool" } +%"struct.std::atomic_bool" = type { %"struct.std::__atomic_base" } +%"struct.std::__atomic_base" = type { i8 } + +; CHECK-LABEL: _Z3fooRSt6atomicIbEb +define zeroext i1 @_Z3fooRSt6atomicIbEb(%"struct.std::atomic"* nocapture dereferenceable(1) %a, i1 returned zeroext %b) nounwind { +entry: + %frombool.i.i = zext i1 %b to i8 + %_M_i.i.i = getelementptr inbounds %"struct.std::atomic", %"struct.std::atomic"* %a, i64 0, i32 0, i32 0, i32 0 + %0 = ptrtoint i8* %_M_i.i.i to i64 + %1 = lshr i64 %0, 3 + %2 = add i64 %1, 2147450880 + %3 = inttoptr i64 %2 to i8* + %4 = load i8, i8* %3 + %5 = icmp ne i8 %4, 0 + br i1 %5, label %6, label %11 + +;