[PATCH] D156926: [RISCV] Add bf16 to isFPImmLegal.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 2 11:21:03 PDT 2023
craig.topper updated this revision to Diff 546557.
craig.topper added a comment.
Add test file
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156926/new/
https://reviews.llvm.org/D156926
Files:
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/bfloat-imm.ll
Index: llvm/test/CodeGen/RISCV/bfloat-imm.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/bfloat-imm.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin -verify-machineinstrs \
+; RUN: -target-abi ilp32f < %s | FileCheck %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfbfmin -verify-machineinstrs \
+; RUN: -target-abi lp64f < %s | FileCheck %s
+
+define bfloat @bfloat_imm() nounwind {
+; CHECK-LABEL: bfloat_imm:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lui a0, %hi(.LCPI0_0)
+; CHECK-NEXT: flh fa0, %lo(.LCPI0_0)(a0)
+; CHECK-NEXT: ret
+ ret bfloat 3.0
+}
+
+define bfloat @bfloat_zero() nounwind {
+; CHECK-LABEL: bfloat_zero:
+; CHECK: # %bb.0:
+; CHECK-NEXT: fmv.h.x fa0, zero
+; CHECK-NEXT: ret
+ ret bfloat 0.0
+}
+
+define bfloat @bfloat_negative_zero() nounwind {
+; CHECK-LABEL: bfloat_negative_zero:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lui a0, 1048568
+; CHECK-NEXT: fmv.h.x fa0, a0
+; CHECK-NEXT: ret
+ ret bfloat -0.0
+}
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1899,6 +1899,8 @@
IsLegalVT = Subtarget.hasStdExtFOrZfinx();
else if (VT == MVT::f64)
IsLegalVT = Subtarget.hasStdExtDOrZdinx();
+ else if (VT == MVT::bf16)
+ IsLegalVT = Subtarget.hasStdExtZfbfmin();
if (!IsLegalVT)
return false;
Index: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -876,6 +876,10 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156926.546557.patch
Type: text/x-patch
Size: 2197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230802/81f9839a/attachment.bin>
More information about the llvm-commits
mailing list