Skip to content

Commit c830b83

Browse files
[X86][GlobalISel] Enable Trigonometric functions with libcall mapping
1 parent be25d61 commit c830b83

File tree

11 files changed

+1848
-269
lines changed

11 files changed

+1848
-269
lines changed

llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
9999
.widenScalarToNextPow2(0, /*Min=*/8)
100100
.clampScalar(0, s8, sMaxScalar);
101101

102-
getActionDefinitionsBuilder(G_LROUND).libcall();
103-
104-
getActionDefinitionsBuilder(G_LLROUND).libcall();
102+
getActionDefinitionsBuilder({G_LROUND, G_LLROUND, G_FCOS, G_FCOSH, G_FACOS,
103+
G_FSIN, G_FSINH, G_FASIN, G_FTAN, G_FTANH,
104+
G_FATAN, G_FATAN2})
105+
.libcall();
105106

106107
// merge/unmerge
107108
for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) {

llvm/test/CodeGen/X86/llvm.acos.ll

Lines changed: 194 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,225 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2-
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
2+
; We don't handle fp16 and fp128 types for "-global-isel" so we allow fallbacks in these cases to SDAG.
3+
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel=0 | FileCheck %s --check-prefixes=X86,SDAG-X86
4+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 | FileCheck %s --check-prefixes=X64,SDAG-X64
5+
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X86,GISEL-X86
6+
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X64,GISEL-X64
37

48
define half @use_acosf16(half %a) nounwind {
5-
; CHECK-LABEL: use_acosf16:
6-
; CHECK: # %bb.0:
7-
; CHECK-NEXT: pushq %rax
8-
; CHECK-NEXT: callq __extendhfsf2@PLT
9-
; CHECK-NEXT: callq acosf@PLT
10-
; CHECK-NEXT: callq __truncsfhf2@PLT
11-
; CHECK-NEXT: popq %rax
12-
; CHECK-NEXT: retq
9+
; X86-LABEL: use_acosf16:
10+
; X86: # %bb.0:
11+
; X86-NEXT: subl $12, %esp
12+
; X86-NEXT: movzwl {{[0-9]+}}(%esp), %eax
13+
; X86-NEXT: movl %eax, (%esp)
14+
; X86-NEXT: calll __gnu_h2f_ieee
15+
; X86-NEXT: fstps (%esp)
16+
; X86-NEXT: calll acosf
17+
; X86-NEXT: fstps (%esp)
18+
; X86-NEXT: calll __gnu_f2h_ieee
19+
; X86-NEXT: addl $12, %esp
20+
; X86-NEXT: retl
21+
;
22+
; X64-LABEL: use_acosf16:
23+
; X64: # %bb.0:
24+
; X64-NEXT: pushq %rax
25+
; X64-NEXT: callq __extendhfsf2@PLT
26+
; X64-NEXT: callq acosf@PLT
27+
; X64-NEXT: callq __truncsfhf2@PLT
28+
; X64-NEXT: popq %rax
29+
; X64-NEXT: retq
1330
%x = call half @llvm.acos.f16(half %a)
1431
ret half %x
1532
}
1633

1734
define float @use_acosf32(float %a) nounwind {
18-
; CHECK-LABEL: use_acosf32:
19-
; CHECK: # %bb.0:
20-
; CHECK-NEXT: jmp acosf@PLT # TAILCALL
35+
; SDAG-X86-LABEL: use_acosf32:
36+
; SDAG-X86: # %bb.0:
37+
; SDAG-X86-NEXT: subl $12, %esp
38+
; SDAG-X86-NEXT: flds {{[0-9]+}}(%esp)
39+
; SDAG-X86-NEXT: fstps (%esp)
40+
; SDAG-X86-NEXT: calll acosf
41+
; SDAG-X86-NEXT: addl $12, %esp
42+
; SDAG-X86-NEXT: retl
43+
;
44+
; SDAG-X64-LABEL: use_acosf32:
45+
; SDAG-X64: # %bb.0:
46+
; SDAG-X64-NEXT: jmp acosf@PLT # TAILCALL
47+
;
48+
; GISEL-X86-LABEL: use_acosf32:
49+
; GISEL-X86: # %bb.0:
50+
; GISEL-X86-NEXT: subl $12, %esp
51+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
52+
; GISEL-X86-NEXT: movl %eax, (%esp)
53+
; GISEL-X86-NEXT: calll acosf
54+
; GISEL-X86-NEXT: addl $12, %esp
55+
; GISEL-X86-NEXT: retl
56+
;
57+
; GISEL-X64-LABEL: use_acosf32:
58+
; GISEL-X64: # %bb.0:
59+
; GISEL-X64-NEXT: pushq %rax
60+
; GISEL-X64-NEXT: callq acosf
61+
; GISEL-X64-NEXT: popq %rax
62+
; GISEL-X64-NEXT: retq
2163
%x = call float @llvm.acos.f32(float %a)
2264
ret float %x
2365
}
2466

2567
define double @use_acosf64(double %a) nounwind {
26-
; CHECK-LABEL: use_acosf64:
27-
; CHECK: # %bb.0:
28-
; CHECK-NEXT: jmp acos@PLT # TAILCALL
68+
; SDAG-X86-LABEL: use_acosf64:
69+
; SDAG-X86: # %bb.0:
70+
; SDAG-X86-NEXT: subl $12, %esp
71+
; SDAG-X86-NEXT: fldl {{[0-9]+}}(%esp)
72+
; SDAG-X86-NEXT: fstpl (%esp)
73+
; SDAG-X86-NEXT: calll acos
74+
; SDAG-X86-NEXT: addl $12, %esp
75+
; SDAG-X86-NEXT: retl
76+
;
77+
; SDAG-X64-LABEL: use_acosf64:
78+
; SDAG-X64: # %bb.0:
79+
; SDAG-X64-NEXT: jmp acos@PLT # TAILCALL
80+
;
81+
; GISEL-X86-LABEL: use_acosf64:
82+
; GISEL-X86: # %bb.0:
83+
; GISEL-X86-NEXT: subl $12, %esp
84+
; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
85+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
86+
; GISEL-X86-NEXT: movl 4(%eax), %eax
87+
; GISEL-X86-NEXT: xorl %edx, %edx
88+
; GISEL-X86-NEXT: addl %esp, %edx
89+
; GISEL-X86-NEXT: movl %ecx, (%esp)
90+
; GISEL-X86-NEXT: movl %eax, 4(%edx)
91+
; GISEL-X86-NEXT: calll acos
92+
; GISEL-X86-NEXT: addl $12, %esp
93+
; GISEL-X86-NEXT: retl
94+
;
95+
; GISEL-X64-LABEL: use_acosf64:
96+
; GISEL-X64: # %bb.0:
97+
; GISEL-X64-NEXT: pushq %rax
98+
; GISEL-X64-NEXT: callq acos
99+
; GISEL-X64-NEXT: popq %rax
100+
; GISEL-X64-NEXT: retq
29101
%x = call double @llvm.acos.f64(double %a)
30102
ret double %x
31103
}
32104

33105
define x86_fp80 @use_acosf80(x86_fp80 %a) nounwind {
34-
; CHECK-LABEL: use_acosf80:
35-
; CHECK: # %bb.0:
36-
; CHECK-NEXT: subq $24, %rsp
37-
; CHECK-NEXT: fldt 32(%rsp)
38-
; CHECK-NEXT: fstpt (%rsp)
39-
; CHECK-NEXT: callq acosl@PLT
40-
; CHECK-NEXT: addq $24, %rsp
41-
; CHECK-NEXT: retq
106+
; X86-LABEL: use_acosf80:
107+
; X86: # %bb.0:
108+
; X86-NEXT: subl $12, %esp
109+
; X86-NEXT: fldt {{[0-9]+}}(%esp)
110+
; X86-NEXT: fstpt (%esp)
111+
; X86-NEXT: calll acosl
112+
; X86-NEXT: addl $12, %esp
113+
; X86-NEXT: retl
114+
;
115+
; SDAG-X64-LABEL: use_acosf80:
116+
; SDAG-X64: # %bb.0:
117+
; SDAG-X64-NEXT: subq $24, %rsp
118+
; SDAG-X64-NEXT: fldt {{[0-9]+}}(%rsp)
119+
; SDAG-X64-NEXT: fstpt (%rsp)
120+
; SDAG-X64-NEXT: callq acosl@PLT
121+
; SDAG-X64-NEXT: addq $24, %rsp
122+
; SDAG-X64-NEXT: retq
123+
;
124+
; GISEL-X64-LABEL: use_acosf80:
125+
; GISEL-X64: # %bb.0:
126+
; GISEL-X64-NEXT: subq $24, %rsp
127+
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
128+
; GISEL-X64-NEXT: fstpt (%rsp)
129+
; GISEL-X64-NEXT: callq acosl
130+
; GISEL-X64-NEXT: addq $24, %rsp
131+
; GISEL-X64-NEXT: retq
42132
%x = call x86_fp80 @llvm.acos.f80(x86_fp80 %a)
43133
ret x86_fp80 %x
44134
}
45135

46136
define fp128 @use_acosfp128(fp128 %a) nounwind {
47-
; CHECK-LABEL: use_acosfp128:
48-
; CHECK: # %bb.0:
49-
; CHECK-NEXT: jmp acosf128@PLT # TAILCALL
137+
; X86-LABEL: use_acosfp128:
138+
; X86: # %bb.0:
139+
; X86-NEXT: pushl %edi
140+
; X86-NEXT: pushl %esi
141+
; X86-NEXT: subl $20, %esp
142+
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
143+
; X86-NEXT: subl $12, %esp
144+
; X86-NEXT: leal {{[0-9]+}}(%esp), %eax
145+
; X86-NEXT: pushl {{[0-9]+}}(%esp)
146+
; X86-NEXT: pushl {{[0-9]+}}(%esp)
147+
; X86-NEXT: pushl {{[0-9]+}}(%esp)
148+
; X86-NEXT: pushl {{[0-9]+}}(%esp)
149+
; X86-NEXT: pushl %eax
150+
; X86-NEXT: calll acosl
151+
; X86-NEXT: addl $28, %esp
152+
; X86-NEXT: movl (%esp), %eax
153+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
154+
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
155+
; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
156+
; X86-NEXT: movl %edi, 12(%esi)
157+
; X86-NEXT: movl %edx, 8(%esi)
158+
; X86-NEXT: movl %ecx, 4(%esi)
159+
; X86-NEXT: movl %eax, (%esi)
160+
; X86-NEXT: movl %esi, %eax
161+
; X86-NEXT: addl $20, %esp
162+
; X86-NEXT: popl %esi
163+
; X86-NEXT: popl %edi
164+
; X86-NEXT: retl $4
165+
;
166+
; SDAG-X64-LABEL: use_acosfp128:
167+
; SDAG-X64: # %bb.0:
168+
; SDAG-X64-NEXT: jmp acosf128@PLT # TAILCALL
169+
;
170+
; GISEL-X64-LABEL: use_acosfp128:
171+
; GISEL-X64: # %bb.0:
172+
; GISEL-X64-NEXT: pushq %rax
173+
; GISEL-X64-NEXT: callq acosf128
174+
; GISEL-X64-NEXT: popq %rax
175+
; GISEL-X64-NEXT: retq
50176
%x = call fp128 @llvm.acos.f128(fp128 %a)
51177
ret fp128 %x
52178
}
53179

54180
define ppc_fp128 @use_acosppc_fp128(ppc_fp128 %a) nounwind {
55-
; CHECK-LABEL: use_acosppc_fp128:
56-
; CHECK: # %bb.0:
57-
; CHECK-NEXT: pushq %rax
58-
; CHECK-NEXT: callq acosl@PLT
59-
; CHECK-NEXT: popq %rax
60-
; CHECK-NEXT: retq
181+
; X86-LABEL: use_acosppc_fp128:
182+
; X86: # %bb.0:
183+
; X86-NEXT: subl $92, %esp
184+
; X86-NEXT: fldl {{[0-9]+}}(%esp)
185+
; X86-NEXT: fldl {{[0-9]+}}(%esp)
186+
; X86-NEXT: fstpl {{[0-9]+}}(%esp)
187+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
188+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
189+
; X86-NEXT: movl %ecx, {{[0-9]+}}(%esp)
190+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
191+
; X86-NEXT: fldl {{[0-9]+}}(%esp)
192+
; X86-NEXT: fstpl {{[0-9]+}}(%esp)
193+
; X86-NEXT: fstpl {{[0-9]+}}(%esp)
194+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
195+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
196+
; X86-NEXT: movl %ecx, {{[0-9]+}}(%esp)
197+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
198+
; X86-NEXT: fldl {{[0-9]+}}(%esp)
199+
; X86-NEXT: fstpl (%esp)
200+
; X86-NEXT: calll acosl
201+
; X86-NEXT: fxch %st(1)
202+
; X86-NEXT: fstpl {{[0-9]+}}(%esp)
203+
; X86-NEXT: fstpl {{[0-9]+}}(%esp)
204+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
205+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
206+
; X86-NEXT: movl %ecx, {{[0-9]+}}(%esp)
207+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
208+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
209+
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
210+
; X86-NEXT: movl %ecx, {{[0-9]+}}(%esp)
211+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
212+
; X86-NEXT: fldl {{[0-9]+}}(%esp)
213+
; X86-NEXT: fldl {{[0-9]+}}(%esp)
214+
; X86-NEXT: addl $92, %esp
215+
; X86-NEXT: retl
216+
;
217+
; X64-LABEL: use_acosppc_fp128:
218+
; X64: # %bb.0:
219+
; X64-NEXT: pushq %rax
220+
; X64-NEXT: callq acosl@PLT
221+
; X64-NEXT: popq %rax
222+
; X64-NEXT: retq
61223
%x = call ppc_fp128 @llvm.acos.ppcf128(ppc_fp128 %a)
62224
ret ppc_fp128 %x
63225
}

0 commit comments

Comments
 (0)