[llvm] Enable Custom Lowering for fabs.v8f16 on AVX (PR #71730)
David Li via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 13 13:19:34 PST 2023
https://github.com/david-xl updated https://github.com/llvm/llvm-project/pull/71730
>From e36d5a5c63adeb915d516b96315d3882500500ca Mon Sep 17 00:00:00 2001
From: David Li <davidxl at google.com>
Date: Tue, 7 Nov 2023 23:29:44 -0800
Subject: [PATCH 1/5] Enable Custom Lowering for fabs.v8f16 on AVX
modified: llvm/lib/Target/X86/X86ISelLowering.cpp
modified: llvm/test/CodeGen/X86/vec_fabs.ll
---
llvm/lib/Target/X86/X86ISelLowering.cpp | 3 ++
llvm/test/CodeGen/X86/vec_fabs.ll | 39 +++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 3d44c50b44e6234..2b201d283404ff9 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -2238,6 +2238,9 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
}
}
+ if (Subtarget.hasAVX())
+ setOperationAction(ISD::FABS, MVT::v8f16, Custom);
+
if (!Subtarget.useSoftFloat() &&
(Subtarget.hasAVXNECONVERT() || Subtarget.hasBF16())) {
addRegisterClass(MVT::v8bf16, Subtarget.hasAVX512() ? &X86::VR128XRegClass
diff --git a/llvm/test/CodeGen/X86/vec_fabs.ll b/llvm/test/CodeGen/X86/vec_fabs.ll
index 8876d2f9b19928e..8a34c54b752e06c 100644
--- a/llvm/test/CodeGen/X86/vec_fabs.ll
+++ b/llvm/test/CodeGen/X86/vec_fabs.ll
@@ -137,6 +137,45 @@ define <4 x double> @fabs_v4f64(<4 x double> %p) {
}
declare <4 x double> @llvm.fabs.v4f64(<4 x double> %p)
+define <8 x half> @fabs_v8f16(ptr %p) {
+; X86-AVX-LABEL: fabs_v8f16:
+; X86-AVX: # %bb.0:
+; X86-AVX-NEXT: movl 4(%esp), [[ADDRREG:%.*]]
+; X86-AVX-NEXT: vmovaps ([[ADDRREG]]), %xmm0
+; X86-AVX-NEXT: vandps {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0, %xmm0
+; X86-AVX-NEXT: retl
+
+; X86-AVX2-LABEL: fabs_v8f16:
+; X86-AVX2: # %bb.0:
+; X86-AVX2-NEXT: movl 4(%esp), [[REG:%.*]]
+; X86-AVX2-NEXT: vpbroadcastw {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
+; X86-AVX2-NEXT: vpand ([[REG]]), %xmm0, %xmm0
+; X86-AVX2-NEXT: retl
+
+; X64-AVX512VL-LABEL: fabs_v8f16:
+; X64-AVX512VL: # %bb.0:
+; X64-AVX512VL-NEXT: vpbroadcastw {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; X64-AVX512VL-NEXT: vpand (%rdi), %xmm0, %xmm0
+; X64-AVX512VL-NEXT: retq
+
+; X64-AVX-LABEL: fabs_v8f16:
+; X64-AVX: # %bb.0:
+; X64-AVX-NEXT: vmovaps (%rdi), %xmm0
+; X64-AVX-NEXT: vandps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
+; X64-AVX-NEXT: retq
+
+; X64-AVX2-LABEL: fabs_v8f16:
+; X64-AVX2: # %bb.0:
+; X64-AVX2-NEXT: vpbroadcastw {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; X64-AVX2-NEXT: vpand (%rdi), %xmm0, %xmm0
+; X64-AVX2-NEXT: retq
+
+ %v = load <8 x half>, ptr %p, align 16
+ %nnv = call <8 x half> @llvm.fabs.v8f16(<8 x half> %v)
+ ret <8 x half> %nnv
+}
+declare <8 x half> @llvm.fabs.v8f16(<8 x half> %p)
+
define <8 x float> @fabs_v8f32(<8 x float> %p) {
; X86-AVX1-LABEL: fabs_v8f32:
; X86-AVX1: # %bb.0:
>From 634eab48ed9419912424cac2abd99b07e7626018 Mon Sep 17 00:00:00 2001
From: David Li <davidxl at google.com>
Date: Wed, 8 Nov 2023 11:05:15 -0800
Subject: [PATCH 2/5] Check softfloat setting for fabs.v8f16 custom lowering
---
llvm/lib/Target/X86/X86ISelLowering.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 2b201d283404ff9..ce9c58e0cf21060 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -2238,7 +2238,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
}
}
- if (Subtarget.hasAVX())
+ if (!Subtarget.useSoftFloat() && Subtarget.hasAVX())
setOperationAction(ISD::FABS, MVT::v8f16, Custom);
if (!Subtarget.useSoftFloat() &&
>From ef7677ed6bcca9af8ad3146630d6974af0e5bbde Mon Sep 17 00:00:00 2001
From: David Li <davidxl at google.com>
Date: Tue, 7 Nov 2023 23:29:44 -0800
Subject: [PATCH 3/5] Enable Custom Lowering for fabs.v8f16 on AVX
---
llvm/test/CodeGen/X86/vec_fabs.ll | 42 +++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/llvm/test/CodeGen/X86/vec_fabs.ll b/llvm/test/CodeGen/X86/vec_fabs.ll
index 8a34c54b752e06c..b933bb6ae2530df 100644
--- a/llvm/test/CodeGen/X86/vec_fabs.ll
+++ b/llvm/test/CodeGen/X86/vec_fabs.ll
@@ -139,6 +139,48 @@ declare <4 x double> @llvm.fabs.v4f64(<4 x double> %p)
define <8 x half> @fabs_v8f16(ptr %p) {
; X86-AVX-LABEL: fabs_v8f16:
+<<<<<<< HEAD
+=======
+; X86-AVX: # %bb.0:
+; X86-AVX-NEXT: movl 4(%esp), [[ADDRREG:%.*]]
+; X86-AVX-NEXT: vmovaps ([[ADDRREG]]), %xmm0
+; X86-AVX-NEXT: vandps {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0, %xmm0
+; X86-AVX-NEXT: retl
+
+; X86-AVX2-LABEL: fabs_v8f16:
+; X86-AVX2: # %bb.0:
+; X86-AVX2-NEXT: movl 4(%esp), [[REG:%.*]]
+; X86-AVX2-NEXT: vpbroadcastw {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
+; X86-AVX2-NEXT: vpand ([[REG]]), %xmm0, %xmm0
+; X86-AVX2-NEXT: retl
+
+; X64-AVX512VL-LABEL: fabs_v8f16:
+; X64-AVX512VL: # %bb.0:
+; X64-AVX512VL-NEXT: vpbroadcastw {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; X64-AVX512VL-NEXT: vpand (%rdi), %xmm0, %xmm0
+; X64-AVX512VL-NEXT: retq
+
+; X64-AVX-LABEL: fabs_v8f16:
+; X64-AVX: # %bb.0:
+; X64-AVX-NEXT: vmovaps (%rdi), %xmm0
+; X64-AVX-NEXT: vandps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
+; X64-AVX-NEXT: retq
+
+; X64-AVX2-LABEL: fabs_v8f16:
+; X64-AVX2: # %bb.0:
+; X64-AVX2-NEXT: vpbroadcastw {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; X64-AVX2-NEXT: vpand (%rdi), %xmm0, %xmm0
+; X64-AVX2-NEXT: retq
+
+ %v = load <8 x half>, ptr %p, align 16
+ %nnv = call <8 x half> @llvm.fabs.v8f16(<8 x half> %v)
+ ret <8 x half> %nnv
+}
+declare <8 x half> @llvm.fabs.v8f16(<8 x half> %p)
+
+define <8 x float> @fabs_v8f32(<8 x float> %p) {
+; X86-AVX-LABEL: fabs_v8f32:
+>>>>>>> 6032b965f854 (Enable Custom Lowering for fabs.v8f16 on AVX)
; X86-AVX: # %bb.0:
; X86-AVX-NEXT: movl 4(%esp), [[ADDRREG:%.*]]
; X86-AVX-NEXT: vmovaps ([[ADDRREG]]), %xmm0
>From c95cc76146b68f2bdc5764296ef7f66ef6e0c8f4 Mon Sep 17 00:00:00 2001
From: David Li <davidxl at google.com>
Date: Tue, 7 Nov 2023 23:29:44 -0800
Subject: [PATCH 4/5] Enable Custom Lowering for fabs.v8f16 on AVX
modified: llvm/test/CodeGen/X86/vec_fabs.ll
---
llvm/test/CodeGen/X86/vec_fabs.ll | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/test/CodeGen/X86/vec_fabs.ll b/llvm/test/CodeGen/X86/vec_fabs.ll
index b933bb6ae2530df..e30ae697f464ca7 100644
--- a/llvm/test/CodeGen/X86/vec_fabs.ll
+++ b/llvm/test/CodeGen/X86/vec_fabs.ll
@@ -140,7 +140,10 @@ declare <4 x double> @llvm.fabs.v4f64(<4 x double> %p)
define <8 x half> @fabs_v8f16(ptr %p) {
; X86-AVX-LABEL: fabs_v8f16:
<<<<<<< HEAD
+<<<<<<< HEAD
+=======
=======
+>>>>>>> f2f313666780 (Enable Custom Lowering for fabs.v8f16 on AVX)
; X86-AVX: # %bb.0:
; X86-AVX-NEXT: movl 4(%esp), [[ADDRREG:%.*]]
; X86-AVX-NEXT: vmovaps ([[ADDRREG]]), %xmm0
>From 4938b939232b456ddbbd4645165b6886d1f15cda Mon Sep 17 00:00:00 2001
From: David Li <davidxl at google.com>
Date: Tue, 7 Nov 2023 23:29:44 -0800
Subject: [PATCH 5/5] Enable Custom Lowering for fabs.v8f16 on AVX
---
llvm/test/CodeGen/X86/vec_fabs.ll | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/test/CodeGen/X86/vec_fabs.ll b/llvm/test/CodeGen/X86/vec_fabs.ll
index e30ae697f464ca7..1d374ec391e463d 100644
--- a/llvm/test/CodeGen/X86/vec_fabs.ll
+++ b/llvm/test/CodeGen/X86/vec_fabs.ll
@@ -141,9 +141,12 @@ define <8 x half> @fabs_v8f16(ptr %p) {
; X86-AVX-LABEL: fabs_v8f16:
<<<<<<< HEAD
<<<<<<< HEAD
+<<<<<<< HEAD
=======
=======
>>>>>>> f2f313666780 (Enable Custom Lowering for fabs.v8f16 on AVX)
+=======
+>>>>>>> 6032b965f854 (Enable Custom Lowering for fabs.v8f16 on AVX)
; X86-AVX: # %bb.0:
; X86-AVX-NEXT: movl 4(%esp), [[ADDRREG:%.*]]
; X86-AVX-NEXT: vmovaps ([[ADDRREG]]), %xmm0
More information about the llvm-commits
mailing list