diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index bcb84add65d83e..b0abd1315bd812 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -30976,6 +30976,14 @@ bool X86TargetLowering::needsCmpXchgNb(Type *MemType) const { return false; } +TargetLoweringBase::AtomicExpansionKind +X86TargetLowering::shouldCastAtomicLoadInIR(LoadInst *LI) const { + if (LI->getType()->isVectorTy()) + if (cast(LI->getType())->getElementType()->isFloatingPointTy()) + return AtomicExpansionKind::CastToInteger; + return TargetLowering::shouldCastAtomicLoadInIR(LI); +} + TargetLoweringBase::AtomicExpansionKind X86TargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const { Type *MemType = SI->getValueOperand()->getType(); diff --git a/llvm/lib/Target/X86/X86ISelLowering.h b/llvm/lib/Target/X86/X86ISelLowering.h index 14ada1721fd40e..75f8c46362327f 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.h +++ b/llvm/lib/Target/X86/X86ISelLowering.h @@ -1808,6 +1808,8 @@ namespace llvm { const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override; ArrayRef getRoundingControlRegisters() const override; + TargetLoweringBase::AtomicExpansionKind + shouldCastAtomicLoadInIR(LoadInst *LI) const override; TargetLoweringBase::AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override; TargetLoweringBase::AtomicExpansionKind diff --git a/llvm/test/CodeGen/X86/atomic-float.ll b/llvm/test/CodeGen/X86/atomic-float.ll new file mode 100644 index 00000000000000..fa5977808aed51 --- /dev/null +++ b/llvm/test/CodeGen/X86/atomic-float.ll @@ -0,0 +1,15 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt < %s --mtriple=x86_64 --passes=atomic-expand -S -o - | FileCheck %s + +define float @load_atomic_float() { +; CHECK-LABEL: define float @load_atomic_float() { +; CHECK-NEXT: [[SRC:%.*]] = alloca float, align 4 +; CHECK-NEXT: [[TMP1:%.*]] = load atomic i32, ptr [[SRC]] acquire, align 4 +; CHECK-NEXT: [[TMP2:%.*]] = bitcast i32 [[TMP1]] to float +; CHECK-NEXT: ret float [[TMP2]] +; + %src = alloca float + %ret = load atomic float, ptr %src acquire, align 4 + ret float %ret +} +