Skip to content

Commit

Permalink
[X86] Lowering of load atomic float via cast
Browse files Browse the repository at this point in the history
X86 backend does not lower load atomic float, so we can cast to an
integer before lowering.
  • Loading branch information
jofrn committed Nov 21, 2024
1 parent fe480cf commit 2d0ad97
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VectorType>(LI->getType())->getElementType()->isFloatingPointTy())
return AtomicExpansionKind::CastToInteger;
return TargetLowering::shouldCastAtomicLoadInIR(LI);
}

TargetLoweringBase::AtomicExpansionKind
X86TargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
Type *MemType = SI->getValueOperand()->getType();
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/X86/X86ISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,8 @@ namespace llvm {
const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
ArrayRef<MCPhysReg> getRoundingControlRegisters() const override;

TargetLoweringBase::AtomicExpansionKind
shouldCastAtomicLoadInIR(LoadInst *LI) const override;
TargetLoweringBase::AtomicExpansionKind
shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
TargetLoweringBase::AtomicExpansionKind
Expand Down
15 changes: 15 additions & 0 deletions llvm/test/CodeGen/X86/atomic-float.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 2d0ad97

Please sign in to comment.