diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZfbfmin.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZfbfmin.td index 8f0768f91c370..cdb43b11dd922 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZfbfmin.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZfbfmin.td @@ -70,3 +70,10 @@ def : Pat<(bf16 (fpround FPR64:$rs1)), def : Pat<(fpextend (bf16 FPR16:$rs1)), (FCVT_D_S (FCVT_S_BF16 FPR16:$rs1, FRM_DYN), FRM_RNE)>; } + +let Predicates = [HasStdExtZfhmin, HasStdExtZfbfmin] in { +// bf16 -> f16 +def : Pat<(f16 (bitconvert (bf16 FPR16:$src))), (f16 FPR16:$src)>; +// f16 -> bf16 +def : Pat<(bf16 (bitconvert (f16 FPR16:$src))), (bf16 FPR16:$src)>; +} diff --git a/llvm/test/CodeGen/RISCV/bfloat-convert-half.ll b/llvm/test/CodeGen/RISCV/bfloat-convert-half.ll new file mode 100644 index 0000000000000..79f12ed62f435 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/bfloat-convert-half.ll @@ -0,0 +1,29 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 +; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+zfhmin,+zfbfmin \ +; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=RV32 +; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+zfhmin,+zfbfmin \ +; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=RV64 + +define bfloat @fcvt_bf16_h(half %a) nounwind { +; RV32-LABEL: fcvt_bf16_h: +; RV32: # %bb.0: +; RV32-NEXT: ret +; +; RV64-LABEL: fcvt_bf16_h: +; RV64: # %bb.0: +; RV64-NEXT: ret + %r = bitcast half %a to bfloat + ret bfloat %r +} + +define half @test_h_bf16(bfloat %a) nounwind { +; RV32-LABEL: test_h_bf16: +; RV32: # %bb.0: +; RV32-NEXT: ret +; +; RV64-LABEL: test_h_bf16: +; RV64: # %bb.0: +; RV64-NEXT: ret + %r = bitcast bfloat %a to half + ret half %r +}