[llvm] a8c502a - [RISCV] Add bf16 to isFPImmLegal.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 08:30:43 PDT 2023
Author: Craig Topper
Date: 2023-08-03T08:27:38-07:00
New Revision: a8c502a589391277302fe9b60607b65e2fbbb1ea
URL: https://github.com/llvm/llvm-project/commit/a8c502a589391277302fe9b60607b65e2fbbb1ea
DIFF: https://github.com/llvm/llvm-project/commit/a8c502a589391277302fe9b60607b65e2fbbb1ea.diff
LOG: [RISCV] Add bf16 to isFPImmLegal.
Part of this test file was stolen from D156895. We should merge them
when committing.
Reviewed By: asb
Differential Revision: https://reviews.llvm.org/D156926
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/bfloat-imm.ll
llvm/test/CodeGen/RISCV/bfloat-select-icmp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index 1b077712794636..2a13c4820f3890 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -876,6 +876,10 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
switch (VT.SimpleTy) {
default:
llvm_unreachable("Unexpected size");
+ case MVT::bf16:
+ assert(Subtarget->hasStdExtZfbfmin());
+ Opc = RISCV::FMV_H_X;
+ break;
case MVT::f16:
Opc =
Subtarget->hasStdExtZhinxOrZhinxmin() ? RISCV::COPY : RISCV::FMV_H_X;
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 2b6c5d8caeaa35..c1407a186f20ab 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1909,6 +1909,8 @@ bool RISCVTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
IsLegalVT = Subtarget.hasStdExtFOrZfinx();
else if (VT == MVT::f64)
IsLegalVT = Subtarget.hasStdExtDOrZdinx();
+ else if (VT == MVT::bf16)
+ IsLegalVT = Subtarget.hasStdExtZfbfmin();
if (!IsLegalVT)
return false;
diff --git a/llvm/test/CodeGen/RISCV/bfloat-imm.ll b/llvm/test/CodeGen/RISCV/bfloat-imm.ll
index e05372428c7726..cd4e960b5a062a 100644
--- a/llvm/test/CodeGen/RISCV/bfloat-imm.ll
+++ b/llvm/test/CodeGen/RISCV/bfloat-imm.ll
@@ -29,8 +29,7 @@ define bfloat @bfloat_imm_op(bfloat %a) nounwind {
define bfloat @bfloat_zero() nounwind {
; CHECK-LABEL: bfloat_zero:
; CHECK: # %bb.0:
-; CHECK-NEXT: lui a0, %hi(.LCPI2_0)
-; CHECK-NEXT: flh fa0, %lo(.LCPI2_0)(a0)
+; CHECK-NEXT: fmv.h.x fa0, zero
; CHECK-NEXT: ret
ret bfloat 0.0
}
@@ -38,8 +37,8 @@ define bfloat @bfloat_zero() nounwind {
define bfloat @bfloat_negative_zero() nounwind {
; CHECK-LABEL: bfloat_negative_zero:
; CHECK: # %bb.0:
-; CHECK-NEXT: lui a0, %hi(.LCPI3_0)
-; CHECK-NEXT: flh fa0, %lo(.LCPI3_0)(a0)
+; CHECK-NEXT: lui a0, 1048568
+; CHECK-NEXT: fmv.h.x fa0, a0
; CHECK-NEXT: ret
ret bfloat -0.0
}
diff --git a/llvm/test/CodeGen/RISCV/bfloat-select-icmp.ll b/llvm/test/CodeGen/RISCV/bfloat-select-icmp.ll
index 5009468b4e2b51..976631221f5aec 100644
--- a/llvm/test/CodeGen/RISCV/bfloat-select-icmp.ll
+++ b/llvm/test/CodeGen/RISCV/bfloat-select-icmp.ll
@@ -178,11 +178,8 @@ define bfloat @select_icmp_slt_one(i32 signext %a) {
; CHECK-LABEL: select_icmp_slt_one:
; CHECK: # %bb.0:
; CHECK-NEXT: slti a0, a0, 1
-; CHECK-NEXT: slli a0, a0, 1
-; CHECK-NEXT: lui a1, %hi(.LCPI10_0)
-; CHECK-NEXT: addi a1, a1, %lo(.LCPI10_0)
-; CHECK-NEXT: add a0, a1, a0
-; CHECK-NEXT: flh fa0, 0(a0)
+; CHECK-NEXT: fcvt.s.w fa5, a0
+; CHECK-NEXT: fcvt.bf16.s fa0, fa5
; CHECK-NEXT: ret
%1 = icmp slt i32 %a, 1
%2 = select i1 %1, bfloat 1.000000e+00, bfloat 0.000000e+00
@@ -192,12 +189,9 @@ define bfloat @select_icmp_slt_one(i32 signext %a) {
define bfloat @select_icmp_sgt_zero(i32 signext %a) {
; CHECK-LABEL: select_icmp_sgt_zero:
; CHECK: # %bb.0:
-; CHECK-NEXT: sgtz a0, a0
-; CHECK-NEXT: slli a0, a0, 1
-; CHECK-NEXT: lui a1, %hi(.LCPI11_0)
-; CHECK-NEXT: addi a1, a1, %lo(.LCPI11_0)
-; CHECK-NEXT: add a0, a1, a0
-; CHECK-NEXT: flh fa0, 0(a0)
+; CHECK-NEXT: slti a0, a0, 1
+; CHECK-NEXT: fcvt.s.w fa5, a0
+; CHECK-NEXT: fcvt.bf16.s fa0, fa5
; CHECK-NEXT: ret
%1 = icmp sgt i32 %a, 0
%2 = select i1 %1, bfloat 0.000000e+00, bfloat 1.000000e+00
More information about the llvm-commits
mailing list