Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
(UseX87 && typeInSet(0, {s80})(Query));
});

getActionDefinitionsBuilder(G_FABS)
.legalFor(UseX87 && !HasSSE2 && !HasSSE1, {s32, s64, s80})
.lower();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does lower generate the selectable code? Then we probably can add tests for float and double as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+x87,-sse,-sse2 restricts SDAG Isel for float and double. It requires SSE.
exact message SSE register return with SSE disabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that error comes from the globalisel code, not sdag. You can also just stop testing with those features forced off

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use X87 with and without SSE for s80. So there is no need forcing -sse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that error comes from the globalisel code, not sdag. You can also just stop testing with those features forced off
@arsenm It appeared without gisel too.
https://godbolt.org/z/Goc3zs9qe
@e-kud I can drop using -sse 👍


// fp comparison
getActionDefinitionsBuilder(G_FCMP)
.legalFor(HasSSE1 || UseX87, {s8, s32})
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/CodeGen/X86/isel-fabs-x87.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse2,-sse | FileCheck %s --check-prefixes=X64
; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse2,-sse -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X64
; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse2,-sse -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X64
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse | FileCheck %s --check-prefixes=X86
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X86
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add f32/f64 test coverage here? otherwise we've lost all x87-only fabs tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is known issue, we discussed it earlier while submitting test review.
#142558 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can store the value instead of returning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably would be nice to see how we handle floats and double without SSE.

; X64-LABEL: test_x86_fp80_abs:
Expand Down
66 changes: 53 additions & 13 deletions llvm/test/CodeGen/X86/isel-fabs.ll
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=x86_64-- -mattr=-x87 | FileCheck %s --check-prefixes=X64
; RUN: llc < %s -mtriple=x86_64-- -mattr=-x87 -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X64
; RUN: llc < %s -mtriple=i686-- -mattr=-x87 | FileCheck %s --check-prefixes=X86
; RUN: llc < %s -mtriple=i686-- -mattr=-x87 -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=FASTISEL-X86
; RUN: llc < %s -mtriple=x86_64-- -mattr=-x87,+sse,+sse2 | FileCheck %s --check-prefixes=X64
; RUN: llc < %s -mtriple=x86_64-- -mattr=-x87,+sse,+sse2 -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X64
; RUN: llc < %s -mtriple=x86_64-- -mattr=-x87,+sse,+sse2 -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
; RUN: llc < %s -mtriple=i686-- -mattr=-x87,+sse,+sse2 | FileCheck %s --check-prefixes=X86
; RUN: llc < %s -mtriple=i686-- -mattr=-x87,+sse,+sse2 -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=FASTISEL-X86
; RUN: llc < %s -mtriple=i686-- -mattr=-x87,+sse,+sse2 -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X86


define float @test_float_abs(float %arg) {
define float @test_float_abs(float %arg) nounwind {
; X64-LABEL: test_float_abs:
; X64: # %bb.0:
; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; X64-NEXT: retq
;
; GISEL-X64-LABEL: test_float_abs:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: movd %xmm0, %eax
; GISEL-X64-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
; GISEL-X64-NEXT: movd %eax, %xmm0
; GISEL-X64-NEXT: retq
;
; X86-LABEL: test_float_abs:
; X86: # %bb.0:
; X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movd {{.*#+}} xmm0 = mem[0],zero,zero,zero
; X86-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
; X86-NEXT: movd %xmm0, %eax
; X86-NEXT: retl
;
; FASTISEL-X86-LABEL: test_float_abs:
; FASTISEL-X86: # %bb.0:
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; FASTISEL-X86-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
; FASTISEL-X86-NEXT: movd {{.*#+}} xmm0 = mem[0],zero,zero,zero
; FASTISEL-X86-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
; FASTISEL-X86-NEXT: movd %xmm0, %eax
; FASTISEL-X86-NEXT: retl
;
; GISEL-X86-LABEL: test_float_abs:
; GISEL-X86: # %bb.0:
; GISEL-X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: retl
%abs = tail call float @llvm.fabs.f32(float %arg)
ret float %abs
}

define double @test_double_abs(double %arg) {
define double @test_double_abs(double %arg) nounwind {
; X64-LABEL: test_double_abs:
; X64: # %bb.0:
; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; X64-NEXT: retq
;
; GISEL-X64-LABEL: test_double_abs:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
; GISEL-X64-NEXT: movq %xmm0, %rcx
; GISEL-X64-NEXT: andq %rax, %rcx
; GISEL-X64-NEXT: movq %rcx, %xmm0
; GISEL-X64-NEXT: retq
;
; X86-LABEL: test_double_abs:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
Expand All @@ -41,10 +65,26 @@ define double @test_double_abs(double %arg) {
;
; FASTISEL-X86-LABEL: test_double_abs:
; FASTISEL-X86: # %bb.0:
; FASTISEL-X86-NEXT: pushl %ebp
; FASTISEL-X86-NEXT: movl %esp, %ebp
; FASTISEL-X86-NEXT: andl $-8, %esp
; FASTISEL-X86-NEXT: subl $8, %esp
; FASTISEL-X86-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
; FASTISEL-X86-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
; FASTISEL-X86-NEXT: movlps %xmm0, (%esp)
; FASTISEL-X86-NEXT: movl (%esp), %eax
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %edx
; FASTISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; FASTISEL-X86-NEXT: andl $2147483647, %edx # imm = 0x7FFFFFFF
; FASTISEL-X86-NEXT: movl %ebp, %esp
; FASTISEL-X86-NEXT: popl %ebp
; FASTISEL-X86-NEXT: retl
;
; GISEL-X86-LABEL: test_double_abs:
; GISEL-X86: # %bb.0:
; GISEL-X86-NEXT: movl $-1, %eax
; GISEL-X86-NEXT: movl $2147483647, %edx # imm = 0x7FFFFFFF
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %eax
; GISEL-X86-NEXT: andl {{[0-9]+}}(%esp), %edx
; GISEL-X86-NEXT: retl
%abs = tail call double @llvm.fabs.f64(double %arg)
ret double %abs
}