Skip to content

Commit 141279f

Browse files
committed
[SelectionDAG][X86] Add floating point promotion.
When lowering atomic <1 x T> vector types with floats, selection can fail since this pattern is unsupported. To support this, floats can be casted to an integer type of the same size. commit-id:f9d761c5
1 parent e294f9f commit 141279f

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,6 +2595,10 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
25952595
setOperationAction(Op, MVT::f32, Promote);
25962596
}
25972597

2598+
setOperationPromotedToType(ISD::ATOMIC_LOAD, MVT::f16, MVT::i16);
2599+
setOperationPromotedToType(ISD::ATOMIC_LOAD, MVT::f32, MVT::i32);
2600+
setOperationPromotedToType(ISD::ATOMIC_LOAD, MVT::f64, MVT::i64);
2601+
25982602
// We have target-specific dag combine patterns for the following nodes:
25992603
setTargetDAGCombine({ISD::VECTOR_SHUFFLE,
26002604
ISD::SCALAR_TO_VECTOR,

llvm/test/CodeGen/X86/atomic-load-store.ll

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc < %s -mtriple=x86_64-apple-macosx10.7.0 -verify-machineinstrs | FileCheck %s
3-
; RUN: llc < %s -mtriple=x86_64-apple-macosx10.7.0 -verify-machineinstrs -O0 | FileCheck %s
3+
; RUN: llc < %s -mtriple=x86_64-apple-macosx10.7.0 -verify-machineinstrs -O0 | FileCheck %s --check-prefix=CHECK0
44

55
define void @test1(ptr %ptr, i32 %val1) {
66
; CHECK-LABEL: test1:
77
; CHECK: ## %bb.0:
88
; CHECK-NEXT: xchgl %esi, (%rdi)
99
; CHECK-NEXT: retq
10+
;
11+
; CHECK0-LABEL: test1:
12+
; CHECK0: ## %bb.0:
13+
; CHECK0-NEXT: xchgl %esi, (%rdi)
14+
; CHECK0-NEXT: retq
1015
store atomic i32 %val1, ptr %ptr seq_cst, align 4
1116
ret void
1217
}
@@ -16,6 +21,11 @@ define void @test2(ptr %ptr, i32 %val1) {
1621
; CHECK: ## %bb.0:
1722
; CHECK-NEXT: movl %esi, (%rdi)
1823
; CHECK-NEXT: retq
24+
;
25+
; CHECK0-LABEL: test2:
26+
; CHECK0: ## %bb.0:
27+
; CHECK0-NEXT: movl %esi, (%rdi)
28+
; CHECK0-NEXT: retq
1929
store atomic i32 %val1, ptr %ptr release, align 4
2030
ret void
2131
}
@@ -25,6 +35,11 @@ define i32 @test3(ptr %ptr) {
2535
; CHECK: ## %bb.0:
2636
; CHECK-NEXT: movl (%rdi), %eax
2737
; CHECK-NEXT: retq
38+
;
39+
; CHECK0-LABEL: test3:
40+
; CHECK0: ## %bb.0:
41+
; CHECK0-NEXT: movl (%rdi), %eax
42+
; CHECK0-NEXT: retq
2843
%val = load atomic i32, ptr %ptr seq_cst, align 4
2944
ret i32 %val
3045
}
@@ -34,6 +49,64 @@ define <1 x i32> @atomic_vec1_i32(ptr %x) {
3449
; CHECK: ## %bb.0:
3550
; CHECK-NEXT: movl (%rdi), %eax
3651
; CHECK-NEXT: retq
52+
;
53+
; CHECK0-LABEL: atomic_vec1_i32:
54+
; CHECK0: ## %bb.0:
55+
; CHECK0-NEXT: movl (%rdi), %eax
56+
; CHECK0-NEXT: retq
3757
%ret = load atomic <1 x i32>, ptr %x acquire, align 4
3858
ret <1 x i32> %ret
3959
}
60+
61+
define <1 x half> @atomic_vec1_half(ptr %x) {
62+
; CHECK-LABEL: atomic_vec1_half:
63+
; CHECK: ## %bb.0:
64+
; CHECK-NEXT: movzwl (%rdi), %eax
65+
; CHECK-NEXT: pinsrw $0, %eax, %xmm0
66+
; CHECK-NEXT: retq
67+
;
68+
; CHECK0-LABEL: atomic_vec1_half:
69+
; CHECK0: ## %bb.0:
70+
; CHECK0-NEXT: movw (%rdi), %cx
71+
; CHECK0-NEXT: ## implicit-def: $eax
72+
; CHECK0-NEXT: movw %cx, %ax
73+
; CHECK0-NEXT: ## implicit-def: $xmm0
74+
; CHECK0-NEXT: pinsrw $0, %eax, %xmm0
75+
; CHECK0-NEXT: retq
76+
%ret = load atomic <1 x half>, ptr %x acquire, align 4
77+
ret <1 x half> %ret
78+
}
79+
80+
define <1 x float> @atomic_vec1_float(ptr %x) {
81+
; CHECK-LABEL: atomic_vec1_float:
82+
; CHECK: ## %bb.0:
83+
; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
84+
; CHECK-NEXT: retq
85+
;
86+
; CHECK0-LABEL: atomic_vec1_float:
87+
; CHECK0: ## %bb.0:
88+
; CHECK0-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
89+
; CHECK0-NEXT: retq
90+
%ret = load atomic <1 x float>, ptr %x acquire, align 4
91+
ret <1 x float> %ret
92+
}
93+
94+
define <1 x bfloat> @atomic_vec1_bfloat(ptr %x) {
95+
; CHECK-LABEL: atomic_vec1_bfloat:
96+
; CHECK: ## %bb.0:
97+
; CHECK-NEXT: movzwl (%rdi), %eax
98+
; CHECK-NEXT: pinsrw $0, %eax, %xmm0
99+
; CHECK-NEXT: retq
100+
;
101+
; CHECK0-LABEL: atomic_vec1_bfloat:
102+
; CHECK0: ## %bb.0:
103+
; CHECK0-NEXT: movw (%rdi), %cx
104+
; CHECK0-NEXT: ## implicit-def: $eax
105+
; CHECK0-NEXT: movw %cx, %ax
106+
; CHECK0-NEXT: ## implicit-def: $xmm0
107+
; CHECK0-NEXT: pinsrw $0, %eax, %xmm0
108+
; CHECK0-NEXT: retq
109+
%ret = load atomic <1 x bfloat>, ptr %x acquire, align 4
110+
ret <1 x bfloat> %ret
111+
}
112+

0 commit comments

Comments
 (0)