Skip to content

Commit 6a58699

Browse files
author
mattarde
committed
update fabs for f32 and f64
1 parent 8221bc6 commit 6a58699

File tree

5 files changed

+72
-31
lines changed

5 files changed

+72
-31
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

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

9434-
MI.eraseFromParent();
9434+
MI.eraseFromParent();
94359435
return Legalized;
94369436
}
94379437

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: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2-
; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse2,-sse | FileCheck %s --check-prefixes=X64
3-
; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse2,-sse -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X64
4-
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse | FileCheck %s --check-prefixes=X86
5-
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X86
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
68

79
define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
8-
; X64-LABEL: test_x86_fp80_abs:
9-
; X64: # %bb.0:
10-
; X64-NEXT: fldt {{[0-9]+}}(%rsp)
11-
; X64-NEXT: fabs
12-
; X64-NEXT: retq
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
1321
;
1422
; X86-LABEL: test_x86_fp80_abs:
1523
; X86: # %bb.0:
@@ -19,3 +27,7 @@ define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
1927
%abs = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %arg)
2028
ret x86_fp80 %abs
2129
}
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: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2-
; RUN: llc < %s -mtriple=x86_64-- -mattr=-x87 | FileCheck %s --check-prefixes=X64
3-
; RUN: llc < %s -mtriple=x86_64-- -mattr=-x87 -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X64
4-
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 -mattr=+x87,+sse,+sse2 -o - | FileCheck %s --check-prefix=X64
5-
; RUN: llc < %s -mtriple=i686-- -mattr=-x87 | FileCheck %s --check-prefixes=X86
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
66
; RUN: llc < %s -mtriple=i686-- -mattr=-x87 -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=FASTISEL-X86
7-
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=1 -mattr=+x87,+sse,+sse2 -o - | FileCheck %s -check-prefixes=GISEL
7+
; RUN: llc < %s -mtriple=i686-- -mattr=-x87 -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X86
88

99
define float @test_float_abs(float %arg) {
1010
; SDAG-X64-LABEL: test_float_abs:
@@ -18,17 +18,30 @@ define float @test_float_abs(float %arg) {
1818
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
1919
; X86-NEXT: retl
2020
;
21+
; GISEL-X64-LABEL: test_float_abs:
22+
; GISEL-X64: # %bb.0:
23+
; GISEL-X64-NEXT: movd %xmm0, %eax
24+
; GISEL-X64-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
25+
; GISEL-X64-NEXT: movd %eax, %xmm0
26+
; GISEL-X64-NEXT: retq
27+
;
28+
; SDAG-X86-LABEL: test_float_abs:
29+
; SDAG-X86: # %bb.0:
30+
; SDAG-X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
31+
; SDAG-X86-NEXT: andl {{[0-9]+}}(%esp), %eax
32+
; SDAG-X86-NEXT: retl
33+
;
2134
; FASTISEL-X86-LABEL: test_float_abs:
2235
; FASTISEL-X86: # %bb.0:
2336
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
2437
; FASTISEL-X86-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
2538
; FASTISEL-X86-NEXT: retl
26-
; GISEL-LABEL: test_float_abs:
27-
; GISEL: # %bb.0:
28-
; GISEL-NEXT: movd %xmm0, %eax
29-
; GISEL-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
30-
; GISEL-NEXT: movd %eax, %xmm0
31-
; GISEL-NEXT: retq
39+
;
40+
; GISEL-X86-LABEL: test_float_abs:
41+
; GISEL-X86: # %bb.0:
42+
; GISEL-X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
43+
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %eax
44+
; GISEL-X86-NEXT: retl
3245
%abs = tail call float @llvm.fabs.f32(float %arg)
3346
ret float %abs
3447
}
@@ -46,21 +59,35 @@ define double @test_double_abs(double %arg) {
4659
; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
4760
; X86-NEXT: retl
4861
;
62+
; GISEL-X64-LABEL: test_double_abs:
63+
; GISEL-X64: # %bb.0:
64+
; GISEL-X64-NEXT: movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
65+
; GISEL-X64-NEXT: movq %xmm0, %rcx
66+
; GISEL-X64-NEXT: andq %rax, %rcx
67+
; GISEL-X64-NEXT: movq %rcx, %xmm0
68+
; GISEL-X64-NEXT: retq
69+
;
70+
; SDAG-X86-LABEL: test_double_abs:
71+
; SDAG-X86: # %bb.0:
72+
; SDAG-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
73+
; SDAG-X86-NEXT: movl $2147483647, %edx # imm = 0x7FFFFFFF
74+
; SDAG-X86-NEXT: andl {{[0-9]+}}(%esp), %edx
75+
; SDAG-X86-NEXT: retl
76+
;
4977
; FASTISEL-X86-LABEL: test_double_abs:
5078
; FASTISEL-X86: # %bb.0:
5179
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %edx
5280
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
5381
; FASTISEL-X86-NEXT: andl $2147483647, %edx # imm = 0x7FFFFFFF
5482
; FASTISEL-X86-NEXT: retl
5583
;
56-
; GISEL-LABEL: test_double_abs:
57-
; GISEL: # %bb.0:
58-
; GISEL-NEXT: movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
59-
; GISEL-NEXT: movq %xmm0, %rcx
60-
; GISEL-NEXT: andq %rax, %rcx
61-
; GISEL-NEXT: movq %rcx, %xmm0
62-
; GISEL-NEXT: retq
84+
; GISEL-X86-LABEL: test_double_abs:
85+
; GISEL-X86: # %bb.0:
86+
; GISEL-X86-NEXT: movl $-1, %eax
87+
; GISEL-X86-NEXT: movl $2147483647, %edx # imm = 0x7FFFFFFF
88+
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %eax
89+
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %edx
90+
; GISEL-X86-NEXT: retl
6391
%abs = tail call double @llvm.fabs.f64(double %arg)
6492
ret double %abs
6593
}
66-

0 commit comments

Comments
 (0)