Skip to content

Commit 75b3115

Browse files
author
mattarde
committed
add float and double
1 parent 92eef97 commit 75b3115

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,7 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
466466
(UseX87 && typeInSet(0, {s80})(Query));
467467
});
468468

469-
//TODO: f32 and f64 FABS require xmm support
470-
getActionDefinitionsBuilder(G_FABS)
471-
.legalFor(UseX87, {s8, s80})
472-
.lower();
469+
getActionDefinitionsBuilder(G_FABS).legalFor(UseX87, {s8, s80}).lower();
473470

474471
// fp comparison
475472
getActionDefinitionsBuilder(G_FCMP)

llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll

Lines changed: 0 additions & 20 deletions
This file was deleted.

llvm/test/CodeGen/X86/isel-fabs.ll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 -mattr=+x87,+sse,+sse2 -o - | FileCheck %s --check-prefix=X64
3+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=1 -mattr=+x87,+sse,+sse2 -o - | FileCheck %s -check-prefixes=GISEL
4+
5+
define float @test_float_abs(float %arg) {
6+
; X64-LABEL: test_float_abs:
7+
; X64: # %bb.0:
8+
; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
9+
; X64-NEXT: retq
10+
;
11+
; GISEL-LABEL: test_float_abs:
12+
; GISEL: # %bb.0:
13+
; GISEL-NEXT: movd %xmm0, %eax
14+
; GISEL-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
15+
; GISEL-NEXT: movd %eax, %xmm0
16+
; GISEL-NEXT: retq
17+
%abs = tail call float @llvm.fabs.f32(float %arg)
18+
ret float %abs
19+
}
20+
21+
define double @test_double_abs(double %arg) {
22+
; X64-LABEL: test_double_abs:
23+
; X64: # %bb.0:
24+
; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
25+
; X64-NEXT: retq
26+
;
27+
; GISEL-LABEL: test_double_abs:
28+
; GISEL: # %bb.0:
29+
; GISEL-NEXT: movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
30+
; GISEL-NEXT: movq %xmm0, %rcx
31+
; GISEL-NEXT: andq %rax, %rcx
32+
; GISEL-NEXT: movq %rcx, %xmm0
33+
; GISEL-NEXT: retq
34+
%abs = tail call double @llvm.fabs.f64(double %arg)
35+
ret double %abs
36+
}
37+
38+
define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
39+
; X64-LABEL: test_x86_fp80_abs:
40+
; X64: # %bb.0:
41+
; X64-NEXT: fldt {{[0-9]+}}(%rsp)
42+
; X64-NEXT: fabs
43+
; X64-NEXT: retq
44+
;
45+
; GISEL-LABEL: test_x86_fp80_abs:
46+
; GISEL: # %bb.0:
47+
; GISEL-NEXT: fldt {{[0-9]+}}(%rsp)
48+
; GISEL-NEXT: fabs
49+
; GISEL-NEXT: retq
50+
%abs = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %arg)
51+
ret x86_fp80 %abs
52+
}

0 commit comments

Comments
 (0)