Skip to content

Commit 40806b7

Browse files
author
mattarde
committed
update fabs for f32 and f64
1 parent 6f63c12 commit 40806b7

File tree

5 files changed

+85
-16
lines changed

5 files changed

+85
-16
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9394,7 +9394,7 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerFAbs(MachineInstr &MI) {
93949394
MIRBuilder.buildConstant(
93959395
Ty, APInt::getSignedMaxValue(Ty.getScalarSizeInBits())));
93969396

9397-
MI.eraseFromParent();
9397+
MI.eraseFromParent();
93989398
return Legalized;
93999399
}
94009400

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class X86InstructionSelector : public InstructionSelector {
9494
bool selectCmp(MachineInstr &I, MachineRegisterInfo &MRI,
9595
MachineFunction &MF) const;
9696
bool selectFCmp(MachineInstr &I, MachineRegisterInfo &MRI,
97-
MachineFunction &MF) const;
97+
MachineFunction &MF) const;
9898
bool selectUAddSub(MachineInstr &I, MachineRegisterInfo &MRI,
9999
MachineFunction &MF) const;
100100
bool selectDebugInstr(MachineInstr &I, MachineRegisterInfo &MRI) const;

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

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

469-
getActionDefinitionsBuilder(G_FABS).legalFor(UseX87, {s80}).lower();
469+
getActionDefinitionsBuilder(G_FABS)
470+
.legalFor(UseX87 && !HasSSE2, {s32, s64, s80})
471+
.lower();
470472

471473
// fp comparison
472474
getActionDefinitionsBuilder(G_FCMP)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefixes=SDAG-X64
3+
; RUN: llc < %s -mtriple=x86_64-- -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=FASTISEL-X64
4+
; RUN: llc < %s -mtriple=x86_64-- -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
5+
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse | FileCheck %s --check-prefixes=X86,SDAG-X86
6+
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X86,FASTISEL-X86
7+
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86,GISEL-X86
8+
9+
define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
10+
; SDAG-X64-LABEL: test_x86_fp80_abs:
11+
; SDAG-X64: # %bb.0:
12+
; SDAG-X64-NEXT: fldt {{[0-9]+}}(%rsp)
13+
; SDAG-X64-NEXT: fabs
14+
; SDAG-X64-NEXT: retq
15+
;
16+
; FASTISEL-X64-LABEL: test_x86_fp80_abs:
17+
; FASTISEL-X64: # %bb.0:
18+
; FASTISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
19+
; FASTISEL-X64-NEXT: fabs
20+
; FASTISEL-X64-NEXT: retq
21+
;
22+
; X86-LABEL: test_x86_fp80_abs:
23+
; X86: # %bb.0:
24+
; X86-NEXT: fldt {{[0-9]+}}(%esp)
25+
; X86-NEXT: fabs
26+
; X86-NEXT: retl
27+
%abs = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %arg)
28+
ret x86_fp80 %abs
29+
}
30+
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
31+
; FASTISEL-X86: {{.*}}
32+
; GISEL-X86: {{.*}}
33+
; SDAG-X86: {{.*}}

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

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2-
; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefixes=X64,SDAG-X64
3-
; RUN: llc < %s -mtriple=x86_64-- -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X64,FASTISEL-X64
4-
; RUN: llc < %s -mtriple=x86_64-- -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X64,GISEL-X64
2+
; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefixes=SDAG-X64
3+
; RUN: llc < %s -mtriple=x86_64-- -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=FASTISEL-X64
4+
; RUN: llc < %s -mtriple=x86_64-- -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
5+
; RUN: llc < %s -mtriple=i686-- -mattr=-x87 | FileCheck %s --check-prefixes=SDAG-X86
6+
; RUN: llc < %s -mtriple=i686-- -mattr=-x87 -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=FASTISEL-X86
7+
; RUN: llc < %s -mtriple=i686-- -mattr=-x87 -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X86
8+
59
define float @test_float_abs(float %arg) {
610
; SDAG-X64-LABEL: test_float_abs:
711
; SDAG-X64: # %bb.0:
@@ -19,6 +23,24 @@ define float @test_float_abs(float %arg) {
1923
; GISEL-X64-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
2024
; GISEL-X64-NEXT: movd %eax, %xmm0
2125
; GISEL-X64-NEXT: retq
26+
;
27+
; SDAG-X86-LABEL: test_float_abs:
28+
; SDAG-X86: # %bb.0:
29+
; SDAG-X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
30+
; SDAG-X86-NEXT: andl {{[0-9]+}}(%esp), %eax
31+
; SDAG-X86-NEXT: retl
32+
;
33+
; FASTISEL-X86-LABEL: test_float_abs:
34+
; FASTISEL-X86: # %bb.0:
35+
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
36+
; FASTISEL-X86-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
37+
; FASTISEL-X86-NEXT: retl
38+
;
39+
; GISEL-X86-LABEL: test_float_abs:
40+
; GISEL-X86: # %bb.0:
41+
; GISEL-X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
42+
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %eax
43+
; GISEL-X86-NEXT: retl
2244
%abs = tail call float @llvm.fabs.f32(float %arg)
2345
ret float %abs
2446
}
@@ -41,16 +63,28 @@ define double @test_double_abs(double %arg) {
4163
; GISEL-X64-NEXT: andq %rax, %rcx
4264
; GISEL-X64-NEXT: movq %rcx, %xmm0
4365
; GISEL-X64-NEXT: retq
66+
;
67+
; SDAG-X86-LABEL: test_double_abs:
68+
; SDAG-X86: # %bb.0:
69+
; SDAG-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
70+
; SDAG-X86-NEXT: movl $2147483647, %edx # imm = 0x7FFFFFFF
71+
; SDAG-X86-NEXT: andl {{[0-9]+}}(%esp), %edx
72+
; SDAG-X86-NEXT: retl
73+
;
74+
; FASTISEL-X86-LABEL: test_double_abs:
75+
; FASTISEL-X86: # %bb.0:
76+
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %edx
77+
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
78+
; FASTISEL-X86-NEXT: andl $2147483647, %edx # imm = 0x7FFFFFFF
79+
; FASTISEL-X86-NEXT: retl
80+
;
81+
; GISEL-X86-LABEL: test_double_abs:
82+
; GISEL-X86: # %bb.0:
83+
; GISEL-X86-NEXT: movl $-1, %eax
84+
; GISEL-X86-NEXT: movl $2147483647, %edx # imm = 0x7FFFFFFF
85+
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %eax
86+
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %edx
87+
; GISEL-X86-NEXT: retl
4488
%abs = tail call double @llvm.fabs.f64(double %arg)
4589
ret double %abs
4690
}
47-
48-
define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
49-
; X64-LABEL: test_x86_fp80_abs:
50-
; X64: # %bb.0:
51-
; X64-NEXT: fldt {{[0-9]+}}(%rsp)
52-
; X64-NEXT: fabs
53-
; X64-NEXT: retq
54-
%abs = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %arg)
55-
ret x86_fp80 %abs
56-
}

0 commit comments

Comments
 (0)