Skip to content

Commit b693e1c

Browse files
[X86][GlobalISel] Enable G_LROUND/G_LLROUND with libcall mapping (#125096)
1 parent fe9a97c commit b693e1c

File tree

5 files changed

+340
-14
lines changed

5 files changed

+340
-14
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ static RTLIB::Libcall getRTLibDesc(unsigned Opcode, unsigned Size) {
411411
} while (0)
412412

413413
switch (Opcode) {
414+
case TargetOpcode::G_LROUND:
415+
RTLIBCASE(LROUND_F);
416+
case TargetOpcode::G_LLROUND:
417+
RTLIBCASE(LLROUND_F);
414418
case TargetOpcode::G_MUL:
415419
RTLIBCASE_INT(MUL_I);
416420
case TargetOpcode::G_SDIV:
@@ -1267,6 +1271,8 @@ LegalizerHelper::libcall(MachineInstr &MI, LostDebugLocObserver &LocObserver) {
12671271
return Status;
12681272
break;
12691273
}
1274+
case TargetOpcode::G_LROUND:
1275+
case TargetOpcode::G_LLROUND:
12701276
case TargetOpcode::G_INTRINSIC_LRINT:
12711277
case TargetOpcode::G_INTRINSIC_LLRINT: {
12721278
LLT LLTy = MRI.getType(MI.getOperand(1).getReg());

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +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();
105+
102106
// merge/unmerge
103107
for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) {
104108
unsigned BigTyIdx = Op == G_MERGE_VALUES ? 0 : 1;

llvm/test/CodeGen/X86/llround-conv.ll

Lines changed: 201 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc < %s -mtriple=i686-unknown | FileCheck %s --check-prefix=X86
33
; RUN: llc < %s -mtriple=i686-unknown -mattr=sse2 | FileCheck %s --check-prefix=SSE2
4+
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X86
45
; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s --check-prefix=X64
6+
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
57

68
define i64 @testmsxs(float %x) {
79
; X86-LABEL: testmsxs:
@@ -26,9 +28,29 @@ define i64 @testmsxs(float %x) {
2628
; SSE2-NEXT: .cfi_def_cfa_offset 4
2729
; SSE2-NEXT: retl
2830
;
31+
; GISEL-X86-LABEL: testmsxs:
32+
; GISEL-X86: # %bb.0: # %entry
33+
; GISEL-X86-NEXT: subl $12, %esp
34+
; GISEL-X86-NEXT: .cfi_def_cfa_offset 16
35+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
36+
; GISEL-X86-NEXT: movl %eax, (%esp)
37+
; GISEL-X86-NEXT: calll llroundf
38+
; GISEL-X86-NEXT: addl $12, %esp
39+
; GISEL-X86-NEXT: .cfi_def_cfa_offset 4
40+
; GISEL-X86-NEXT: retl
41+
;
2942
; X64-LABEL: testmsxs:
3043
; X64: # %bb.0: # %entry
3144
; X64-NEXT: jmp llroundf@PLT # TAILCALL
45+
;
46+
; GISEL-X64-LABEL: testmsxs:
47+
; GISEL-X64: # %bb.0: # %entry
48+
; GISEL-X64-NEXT: pushq %rax
49+
; GISEL-X64-NEXT: .cfi_def_cfa_offset 16
50+
; GISEL-X64-NEXT: callq llroundf
51+
; GISEL-X64-NEXT: popq %rcx
52+
; GISEL-X64-NEXT: .cfi_def_cfa_offset 8
53+
; GISEL-X64-NEXT: retq
3254
entry:
3355
%0 = tail call i64 @llvm.llround.f32(float %x)
3456
ret i64 %0
@@ -57,9 +79,34 @@ define i64 @testmsxd(double %x) {
5779
; SSE2-NEXT: .cfi_def_cfa_offset 4
5880
; SSE2-NEXT: retl
5981
;
82+
; GISEL-X86-LABEL: testmsxd:
83+
; GISEL-X86: # %bb.0: # %entry
84+
; GISEL-X86-NEXT: subl $12, %esp
85+
; GISEL-X86-NEXT: .cfi_def_cfa_offset 16
86+
; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
87+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
88+
; GISEL-X86-NEXT: movl 4(%eax), %eax
89+
; GISEL-X86-NEXT: xorl %edx, %edx
90+
; GISEL-X86-NEXT: addl %esp, %edx
91+
; GISEL-X86-NEXT: movl %ecx, (%esp)
92+
; GISEL-X86-NEXT: movl %eax, 4(%edx)
93+
; GISEL-X86-NEXT: calll llround
94+
; GISEL-X86-NEXT: addl $12, %esp
95+
; GISEL-X86-NEXT: .cfi_def_cfa_offset 4
96+
; GISEL-X86-NEXT: retl
97+
;
6098
; X64-LABEL: testmsxd:
6199
; X64: # %bb.0: # %entry
62100
; X64-NEXT: jmp llround@PLT # TAILCALL
101+
;
102+
; GISEL-X64-LABEL: testmsxd:
103+
; GISEL-X64: # %bb.0: # %entry
104+
; GISEL-X64-NEXT: pushq %rax
105+
; GISEL-X64-NEXT: .cfi_def_cfa_offset 16
106+
; GISEL-X64-NEXT: callq llround
107+
; GISEL-X64-NEXT: popq %rcx
108+
; GISEL-X64-NEXT: .cfi_def_cfa_offset 8
109+
; GISEL-X64-NEXT: retq
63110
entry:
64111
%0 = tail call i64 @llvm.llround.f64(double %x)
65112
ret i64 %0
@@ -88,14 +135,165 @@ define i64 @testmsll(x86_fp80 %x) {
88135
; SSE2-NEXT: .cfi_def_cfa_offset 4
89136
; SSE2-NEXT: retl
90137
;
138+
; GISEL-X86-LABEL: testmsll:
139+
; GISEL-X86: # %bb.0: # %entry
140+
; GISEL-X86-NEXT: subl $12, %esp
141+
; GISEL-X86-NEXT: .cfi_def_cfa_offset 16
142+
; GISEL-X86-NEXT: fldt {{[0-9]+}}(%esp)
143+
; GISEL-X86-NEXT: fstpt (%esp)
144+
; GISEL-X86-NEXT: calll llroundl
145+
; GISEL-X86-NEXT: addl $12, %esp
146+
; GISEL-X86-NEXT: .cfi_def_cfa_offset 4
147+
; GISEL-X86-NEXT: retl
148+
;
91149
; X64-LABEL: testmsll:
92150
; X64: # %bb.0: # %entry
93151
; X64-NEXT: jmp llroundl@PLT # TAILCALL
152+
;
153+
; GISEL-X64-LABEL: testmsll:
154+
; GISEL-X64: # %bb.0: # %entry
155+
; GISEL-X64-NEXT: subq $24, %rsp
156+
; GISEL-X64-NEXT: .cfi_def_cfa_offset 32
157+
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
158+
; GISEL-X64-NEXT: fstpt (%rsp)
159+
; GISEL-X64-NEXT: callq llroundl
160+
; GISEL-X64-NEXT: addq $24, %rsp
161+
; GISEL-X64-NEXT: .cfi_def_cfa_offset 8
162+
; GISEL-X64-NEXT: retq
94163
entry:
95164
%0 = tail call i64 @llvm.llround.f80(x86_fp80 %x)
96165
ret i64 %0
97166
}
98167

99-
declare i64 @llvm.llround.f32(float) nounwind readnone
100-
declare i64 @llvm.llround.f64(double) nounwind readnone
101-
declare i64 @llvm.llround.f80(x86_fp80) nounwind readnone
168+
define i64 @test_llround_i64_f32(float %x) nounwind {
169+
; X86-LABEL: test_llround_i64_f32:
170+
; X86: # %bb.0:
171+
; X86-NEXT: pushl %eax
172+
; X86-NEXT: flds {{[0-9]+}}(%esp)
173+
; X86-NEXT: fstps (%esp)
174+
; X86-NEXT: calll llroundf
175+
; X86-NEXT: popl %ecx
176+
; X86-NEXT: retl
177+
;
178+
; SSE2-LABEL: test_llround_i64_f32:
179+
; SSE2: # %bb.0:
180+
; SSE2-NEXT: pushl %eax
181+
; SSE2-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
182+
; SSE2-NEXT: movss %xmm0, (%esp)
183+
; SSE2-NEXT: calll llroundf
184+
; SSE2-NEXT: popl %ecx
185+
; SSE2-NEXT: retl
186+
;
187+
; GISEL-X86-LABEL: test_llround_i64_f32:
188+
; GISEL-X86: # %bb.0:
189+
; GISEL-X86-NEXT: subl $12, %esp
190+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
191+
; GISEL-X86-NEXT: movl %eax, (%esp)
192+
; GISEL-X86-NEXT: calll llroundf
193+
; GISEL-X86-NEXT: addl $12, %esp
194+
; GISEL-X86-NEXT: retl
195+
;
196+
; X64-LABEL: test_llround_i64_f32:
197+
; X64: # %bb.0:
198+
; X64-NEXT: jmp llroundf@PLT # TAILCALL
199+
;
200+
; GISEL-X64-LABEL: test_llround_i64_f32:
201+
; GISEL-X64: # %bb.0:
202+
; GISEL-X64-NEXT: pushq %rax
203+
; GISEL-X64-NEXT: callq llroundf
204+
; GISEL-X64-NEXT: popq %rcx
205+
; GISEL-X64-NEXT: retq
206+
%conv = call i64 @llvm.llround.i64.f32(float %x)
207+
ret i64 %conv
208+
}
209+
210+
define i64 @test_llround_i64_f64(double %x) nounwind {
211+
; X86-LABEL: test_llround_i64_f64:
212+
; X86: # %bb.0:
213+
; X86-NEXT: subl $8, %esp
214+
; X86-NEXT: fldl {{[0-9]+}}(%esp)
215+
; X86-NEXT: fstpl (%esp)
216+
; X86-NEXT: calll llround
217+
; X86-NEXT: addl $8, %esp
218+
; X86-NEXT: retl
219+
;
220+
; SSE2-LABEL: test_llround_i64_f64:
221+
; SSE2: # %bb.0:
222+
; SSE2-NEXT: subl $8, %esp
223+
; SSE2-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
224+
; SSE2-NEXT: movsd %xmm0, (%esp)
225+
; SSE2-NEXT: calll llround
226+
; SSE2-NEXT: addl $8, %esp
227+
; SSE2-NEXT: retl
228+
;
229+
; GISEL-X86-LABEL: test_llround_i64_f64:
230+
; GISEL-X86: # %bb.0:
231+
; GISEL-X86-NEXT: subl $12, %esp
232+
; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
233+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
234+
; GISEL-X86-NEXT: movl 4(%eax), %eax
235+
; GISEL-X86-NEXT: xorl %edx, %edx
236+
; GISEL-X86-NEXT: addl %esp, %edx
237+
; GISEL-X86-NEXT: movl %ecx, (%esp)
238+
; GISEL-X86-NEXT: movl %eax, 4(%edx)
239+
; GISEL-X86-NEXT: calll llround
240+
; GISEL-X86-NEXT: addl $12, %esp
241+
; GISEL-X86-NEXT: retl
242+
;
243+
; X64-LABEL: test_llround_i64_f64:
244+
; X64: # %bb.0:
245+
; X64-NEXT: jmp llround@PLT # TAILCALL
246+
;
247+
; GISEL-X64-LABEL: test_llround_i64_f64:
248+
; GISEL-X64: # %bb.0:
249+
; GISEL-X64-NEXT: pushq %rax
250+
; GISEL-X64-NEXT: callq llround
251+
; GISEL-X64-NEXT: popq %rcx
252+
; GISEL-X64-NEXT: retq
253+
%conv = call i64 @llvm.llround.i64.f64(double %x)
254+
ret i64 %conv
255+
}
256+
257+
define i64 @test_llround_i64_f80(x86_fp80 %x) nounwind {
258+
; X86-LABEL: test_llround_i64_f80:
259+
; X86: # %bb.0:
260+
; X86-NEXT: subl $12, %esp
261+
; X86-NEXT: fldt {{[0-9]+}}(%esp)
262+
; X86-NEXT: fstpt (%esp)
263+
; X86-NEXT: calll llroundl
264+
; X86-NEXT: addl $12, %esp
265+
; X86-NEXT: retl
266+
;
267+
; SSE2-LABEL: test_llround_i64_f80:
268+
; SSE2: # %bb.0:
269+
; SSE2-NEXT: subl $12, %esp
270+
; SSE2-NEXT: fldt {{[0-9]+}}(%esp)
271+
; SSE2-NEXT: fstpt (%esp)
272+
; SSE2-NEXT: calll llroundl
273+
; SSE2-NEXT: addl $12, %esp
274+
; SSE2-NEXT: retl
275+
;
276+
; GISEL-X86-LABEL: test_llround_i64_f80:
277+
; GISEL-X86: # %bb.0:
278+
; GISEL-X86-NEXT: subl $12, %esp
279+
; GISEL-X86-NEXT: fldt {{[0-9]+}}(%esp)
280+
; GISEL-X86-NEXT: fstpt (%esp)
281+
; GISEL-X86-NEXT: calll llroundl
282+
; GISEL-X86-NEXT: addl $12, %esp
283+
; GISEL-X86-NEXT: retl
284+
;
285+
; X64-LABEL: test_llround_i64_f80:
286+
; X64: # %bb.0:
287+
; X64-NEXT: jmp llroundl@PLT # TAILCALL
288+
;
289+
; GISEL-X64-LABEL: test_llround_i64_f80:
290+
; GISEL-X64: # %bb.0:
291+
; GISEL-X64-NEXT: subq $24, %rsp
292+
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
293+
; GISEL-X64-NEXT: fstpt (%rsp)
294+
; GISEL-X64-NEXT: callq llroundl
295+
; GISEL-X64-NEXT: addq $24, %rsp
296+
; GISEL-X64-NEXT: retq
297+
%conv = call i64 @llvm.llround.i64.f80(x86_fp80 %x)
298+
ret i64 %conv
299+
}

llvm/test/CodeGen/X86/lround-conv-i32.ll

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,100 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc < %s -mtriple=i686-unknown | FileCheck %s
33
; RUN: llc < %s -mtriple=i686-unknown -mattr=sse2 | FileCheck %s
4+
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X86
45
; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s --check-prefix=X64
6+
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
57

6-
define i32 @testmsws(float %x) {
8+
define i32 @testmsws(float %x) nounwind {
79
; CHECK-LABEL: testmsws:
810
; CHECK: # %bb.0: # %entry
911
; CHECK-NEXT: jmp lroundf # TAILCALL
1012
;
13+
; GISEL-X86-LABEL: testmsws:
14+
; GISEL-X86: # %bb.0: # %entry
15+
; GISEL-X86-NEXT: subl $12, %esp
16+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
17+
; GISEL-X86-NEXT: movl %eax, (%esp)
18+
; GISEL-X86-NEXT: calll lroundf
19+
; GISEL-X86-NEXT: addl $12, %esp
20+
; GISEL-X86-NEXT: retl
21+
;
1122
; X64-LABEL: testmsws:
1223
; X64: # %bb.0: # %entry
1324
; X64-NEXT: jmp lroundf@PLT # TAILCALL
25+
;
26+
; GISEL-X64-LABEL: testmsws:
27+
; GISEL-X64: # %bb.0: # %entry
28+
; GISEL-X64-NEXT: pushq %rax
29+
; GISEL-X64-NEXT: callq lroundf
30+
; GISEL-X64-NEXT: popq %rcx
31+
; GISEL-X64-NEXT: retq
1432
entry:
1533
%0 = tail call i32 @llvm.lround.i32.f32(float %x)
1634
ret i32 %0
1735
}
1836

19-
define i32 @testmswd(double %x) {
37+
define i32 @testmswd(double %x) nounwind {
2038
; CHECK-LABEL: testmswd:
2139
; CHECK: # %bb.0: # %entry
2240
; CHECK-NEXT: jmp lround # TAILCALL
2341
;
42+
; GISEL-X86-LABEL: testmswd:
43+
; GISEL-X86: # %bb.0: # %entry
44+
; GISEL-X86-NEXT: subl $12, %esp
45+
; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
46+
; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
47+
; GISEL-X86-NEXT: movl 4(%eax), %eax
48+
; GISEL-X86-NEXT: xorl %edx, %edx
49+
; GISEL-X86-NEXT: addl %esp, %edx
50+
; GISEL-X86-NEXT: movl %ecx, (%esp)
51+
; GISEL-X86-NEXT: movl %eax, 4(%edx)
52+
; GISEL-X86-NEXT: calll lround
53+
; GISEL-X86-NEXT: addl $12, %esp
54+
; GISEL-X86-NEXT: retl
55+
;
2456
; X64-LABEL: testmswd:
2557
; X64: # %bb.0: # %entry
2658
; X64-NEXT: jmp lround@PLT # TAILCALL
59+
;
60+
; GISEL-X64-LABEL: testmswd:
61+
; GISEL-X64: # %bb.0: # %entry
62+
; GISEL-X64-NEXT: pushq %rax
63+
; GISEL-X64-NEXT: callq lround
64+
; GISEL-X64-NEXT: popq %rcx
65+
; GISEL-X64-NEXT: retq
2766
entry:
2867
%0 = tail call i32 @llvm.lround.i32.f64(double %x)
2968
ret i32 %0
3069
}
3170

32-
define i32 @testmsll(x86_fp80 %x) {
71+
define i32 @testmsll(x86_fp80 %x) nounwind {
3372
; CHECK-LABEL: testmsll:
3473
; CHECK: # %bb.0: # %entry
3574
; CHECK-NEXT: jmp lroundl # TAILCALL
3675
;
76+
; GISEL-X86-LABEL: testmsll:
77+
; GISEL-X86: # %bb.0: # %entry
78+
; GISEL-X86-NEXT: subl $12, %esp
79+
; GISEL-X86-NEXT: fldt {{[0-9]+}}(%esp)
80+
; GISEL-X86-NEXT: fstpt (%esp)
81+
; GISEL-X86-NEXT: calll lroundl
82+
; GISEL-X86-NEXT: addl $12, %esp
83+
; GISEL-X86-NEXT: retl
84+
;
3785
; X64-LABEL: testmsll:
3886
; X64: # %bb.0: # %entry
3987
; X64-NEXT: jmp lroundl@PLT # TAILCALL
88+
;
89+
; GISEL-X64-LABEL: testmsll:
90+
; GISEL-X64: # %bb.0: # %entry
91+
; GISEL-X64-NEXT: subq $24, %rsp
92+
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
93+
; GISEL-X64-NEXT: fstpt (%rsp)
94+
; GISEL-X64-NEXT: callq lroundl
95+
; GISEL-X64-NEXT: addq $24, %rsp
96+
; GISEL-X64-NEXT: retq
4097
entry:
4198
%0 = tail call i32 @llvm.lround.i32.f80(x86_fp80 %x)
4299
ret i32 %0
43100
}
44-
45-
declare i32 @llvm.lround.i32.f32(float) nounwind readnone
46-
declare i32 @llvm.lround.i32.f64(double) nounwind readnone
47-
declare i32 @llvm.lround.i32.f80(x86_fp80) nounwind readnone

0 commit comments

Comments
 (0)