[llvm] [X86][GlobalIsel] support G_FABS for f80 (PR #136718)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 1 10:54:34 PDT 2025
https://github.com/mahesh-attarde updated https://github.com/llvm/llvm-project/pull/136718
>From ca462c87f62a61af14c4af634d0d1f5cfc02788d Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Tue, 22 Apr 2025 08:27:06 -0700
Subject: [PATCH 1/4] [X86][GlobalIsel] support fabs for f80
---
.../lib/Target/X86/GISel/X86LegalizerInfo.cpp | 5 +++++
.../CodeGen/X86/GlobalISel/fabs-scalar.ll | 20 +++++++++++++++++++
2 files changed, 25 insertions(+)
create mode 100644 llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index f008cb1bea839..d8c1fb5717df8 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -466,6 +466,11 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
(UseX87 && typeInSet(0, {s80})(Query));
});
+ //TODO: f32 and f64 FABS require xmm support
+ getActionDefinitionsBuilder(G_FABS)
+ .legalFor(UseX87, {s8, s80})
+ .lower();
+
// fp comparison
getActionDefinitionsBuilder(G_FCMP)
.legalFor(HasSSE1 || UseX87, {s8, s32})
diff --git a/llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll b/llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll
new file mode 100644
index 0000000000000..39ce3a492a33c
--- /dev/null
+++ b/llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=X64
+; RUN: llc < %s -mtriple=x86_64-linux -mattr=+x87,-sse,-sse2 | FileCheck %s -check-prefixes=X64
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel -mattr=+x87,-sse,-sse2 | FileCheck %s -check-prefixes=GISEL
+
+define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
+; X64-LABEL: test_x86_fp80_abs:
+; X64: # %bb.0:
+; X64-NEXT: fldt {{[0-9]+}}(%rsp)
+; X64-NEXT: fabs
+; X64-NEXT: retq
+;
+; GISEL-LABEL: test_x86_fp80_abs:
+; GISEL: # %bb.0:
+; GISEL-NEXT: fldt {{[0-9]+}}(%rsp)
+; GISEL-NEXT: fabs
+; GISEL-NEXT: retq
+ %abs = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %arg)
+ ret x86_fp80 %abs
+}
>From 8a805397619bfc6aecc5914211e12be5afdff49e Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Wed, 23 Apr 2025 22:40:23 -0700
Subject: [PATCH 2/4] add float and double
---
.../lib/Target/X86/GISel/X86LegalizerInfo.cpp | 5 +-
.../CodeGen/X86/GlobalISel/fabs-scalar.ll | 20 -------
llvm/test/CodeGen/X86/isel-fabs.ll | 52 +++++++++++++++++++
3 files changed, 53 insertions(+), 24 deletions(-)
delete mode 100644 llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll
create mode 100644 llvm/test/CodeGen/X86/isel-fabs.ll
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index d8c1fb5717df8..106b62d0e6169 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -466,10 +466,7 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
(UseX87 && typeInSet(0, {s80})(Query));
});
- //TODO: f32 and f64 FABS require xmm support
- getActionDefinitionsBuilder(G_FABS)
- .legalFor(UseX87, {s8, s80})
- .lower();
+ getActionDefinitionsBuilder(G_FABS).legalFor(UseX87, {s8, s80}).lower();
// fp comparison
getActionDefinitionsBuilder(G_FCMP)
diff --git a/llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll b/llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll
deleted file mode 100644
index 39ce3a492a33c..0000000000000
--- a/llvm/test/CodeGen/X86/GlobalISel/fabs-scalar.ll
+++ /dev/null
@@ -1,20 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=X64
-; RUN: llc < %s -mtriple=x86_64-linux -mattr=+x87,-sse,-sse2 | FileCheck %s -check-prefixes=X64
-; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel -mattr=+x87,-sse,-sse2 | FileCheck %s -check-prefixes=GISEL
-
-define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
-; X64-LABEL: test_x86_fp80_abs:
-; X64: # %bb.0:
-; X64-NEXT: fldt {{[0-9]+}}(%rsp)
-; X64-NEXT: fabs
-; X64-NEXT: retq
-;
-; GISEL-LABEL: test_x86_fp80_abs:
-; GISEL: # %bb.0:
-; GISEL-NEXT: fldt {{[0-9]+}}(%rsp)
-; GISEL-NEXT: fabs
-; GISEL-NEXT: retq
- %abs = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %arg)
- ret x86_fp80 %abs
-}
diff --git a/llvm/test/CodeGen/X86/isel-fabs.ll b/llvm/test/CodeGen/X86/isel-fabs.ll
new file mode 100644
index 0000000000000..59131ec3f1085
--- /dev/null
+++ b/llvm/test/CodeGen/X86/isel-fabs.ll
@@ -0,0 +1,52 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 -mattr=+x87,+sse,+sse2 -o - | FileCheck %s --check-prefix=X64
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=1 -mattr=+x87,+sse,+sse2 -o - | FileCheck %s -check-prefixes=GISEL
+
+define float @test_float_abs(float %arg) {
+; X64-LABEL: test_float_abs:
+; X64: # %bb.0:
+; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; X64-NEXT: retq
+;
+; GISEL-LABEL: test_float_abs:
+; GISEL: # %bb.0:
+; GISEL-NEXT: movd %xmm0, %eax
+; GISEL-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
+; GISEL-NEXT: movd %eax, %xmm0
+; GISEL-NEXT: retq
+ %abs = tail call float @llvm.fabs.f32(float %arg)
+ ret float %abs
+}
+
+define double @test_double_abs(double %arg) {
+; X64-LABEL: test_double_abs:
+; X64: # %bb.0:
+; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; X64-NEXT: retq
+;
+; GISEL-LABEL: test_double_abs:
+; GISEL: # %bb.0:
+; GISEL-NEXT: movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
+; GISEL-NEXT: movq %xmm0, %rcx
+; GISEL-NEXT: andq %rax, %rcx
+; GISEL-NEXT: movq %rcx, %xmm0
+; GISEL-NEXT: retq
+ %abs = tail call double @llvm.fabs.f64(double %arg)
+ ret double %abs
+}
+
+define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
+; X64-LABEL: test_x86_fp80_abs:
+; X64: # %bb.0:
+; X64-NEXT: fldt {{[0-9]+}}(%rsp)
+; X64-NEXT: fabs
+; X64-NEXT: retq
+;
+; GISEL-LABEL: test_x86_fp80_abs:
+; GISEL: # %bb.0:
+; GISEL-NEXT: fldt {{[0-9]+}}(%rsp)
+; GISEL-NEXT: fabs
+; GISEL-NEXT: retq
+ %abs = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %arg)
+ ret x86_fp80 %abs
+}
>From 3ccc01b28d775e5a507ada44fc956e2b39a944bd Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Thu, 1 May 2025 04:47:19 -0700
Subject: [PATCH 3/4] update test
---
llvm/test/CodeGen/X86/isel-fabs.ll | 66 ++++++++++++++++--------------
1 file changed, 35 insertions(+), 31 deletions(-)
diff --git a/llvm/test/CodeGen/X86/isel-fabs.ll b/llvm/test/CodeGen/X86/isel-fabs.ll
index 59131ec3f1085..1b5d990b7285d 100644
--- a/llvm/test/CodeGen/X86/isel-fabs.ll
+++ b/llvm/test/CodeGen/X86/isel-fabs.ll
@@ -1,36 +1,46 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=0 -mattr=+x87,+sse,+sse2 -o - | FileCheck %s --check-prefix=X64
-; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -global-isel=1 -mattr=+x87,+sse,+sse2 -o - | FileCheck %s -check-prefixes=GISEL
-
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefixes=X64,SDAG-X64
+; RUN: llc < %s -mtriple=x86_64-- -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X64,FASTISEL-X64
+; RUN: llc < %s -mtriple=x86_64-- -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X64,GISEL-X64
define float @test_float_abs(float %arg) {
-; X64-LABEL: test_float_abs:
-; X64: # %bb.0:
-; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
-; X64-NEXT: retq
+; SDAG-X64-LABEL: test_float_abs:
+; SDAG-X64: # %bb.0:
+; SDAG-X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; SDAG-X64-NEXT: retq
+;
+; FASTISEL-X64-LABEL: test_float_abs:
+; FASTISEL-X64: # %bb.0:
+; FASTISEL-X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; FASTISEL-X64-NEXT: retq
;
-; GISEL-LABEL: test_float_abs:
-; GISEL: # %bb.0:
-; GISEL-NEXT: movd %xmm0, %eax
-; GISEL-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
-; GISEL-NEXT: movd %eax, %xmm0
-; GISEL-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
%abs = tail call float @llvm.fabs.f32(float %arg)
ret float %abs
}
define double @test_double_abs(double %arg) {
-; X64-LABEL: test_double_abs:
-; X64: # %bb.0:
-; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
-; X64-NEXT: retq
+; SDAG-X64-LABEL: test_double_abs:
+; SDAG-X64: # %bb.0:
+; SDAG-X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; SDAG-X64-NEXT: retq
;
-; GISEL-LABEL: test_double_abs:
-; GISEL: # %bb.0:
-; GISEL-NEXT: movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
-; GISEL-NEXT: movq %xmm0, %rcx
-; GISEL-NEXT: andq %rax, %rcx
-; GISEL-NEXT: movq %rcx, %xmm0
-; GISEL-NEXT: retq
+; FASTISEL-X64-LABEL: test_double_abs:
+; FASTISEL-X64: # %bb.0:
+; FASTISEL-X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; FASTISEL-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
%abs = tail call double @llvm.fabs.f64(double %arg)
ret double %abs
}
@@ -41,12 +51,6 @@ define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) {
; X64-NEXT: fldt {{[0-9]+}}(%rsp)
; X64-NEXT: fabs
; X64-NEXT: retq
-;
-; GISEL-LABEL: test_x86_fp80_abs:
-; GISEL: # %bb.0:
-; GISEL-NEXT: fldt {{[0-9]+}}(%rsp)
-; GISEL-NEXT: fabs
-; GISEL-NEXT: retq
%abs = tail call x86_fp80 @llvm.fabs.f80(x86_fp80 %arg)
ret x86_fp80 %abs
}
>From 6f63c12d51200ab38508634e6838094d75a349af Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Thu, 1 May 2025 10:53:19 -0700
Subject: [PATCH 4/4] remove s8
---
llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index 106b62d0e6169..c583950cb535a 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -466,7 +466,7 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
(UseX87 && typeInSet(0, {s80})(Query));
});
- getActionDefinitionsBuilder(G_FABS).legalFor(UseX87, {s8, s80}).lower();
+ getActionDefinitionsBuilder(G_FABS).legalFor(UseX87, {s80}).lower();
// fp comparison
getActionDefinitionsBuilder(G_FCMP)
More information about the llvm-commits
mailing list