Skip to content

[RISCV] Support LLVM IR intrinsics for XAndesVPackFPH #139860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/IR/IntrinsicsRISCV.td
Original file line number Diff line number Diff line change
Expand Up @@ -1891,3 +1891,4 @@ let TargetPrefix = "riscv" in {
include "llvm/IR/IntrinsicsRISCVXTHead.td"
include "llvm/IR/IntrinsicsRISCVXsf.td"
include "llvm/IR/IntrinsicsRISCVXCV.td"
include "llvm/IR/IntrinsicsRISCVXAndes.td"
17 changes: 17 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsRISCVXAndes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===- IntrinsicsRISCVXAndes.td - Andes intrinsics ---------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines all of the Andes vendor intrinsics for RISC-V.
//
//===----------------------------------------------------------------------===//

let TargetPrefix = "riscv" in {
// Andes Vector Packed FP16 Extension
defm nds_vfpmadt : RISCVBinaryAAXRoundingMode;
defm nds_vfpmadb : RISCVBinaryAAXRoundingMode;
}
40 changes: 39 additions & 1 deletion llvm/lib/Target/RISCV/RISCVInstrInfoXAndes.td
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,33 @@ class NDSRVInstVFPMAD<bits<6> funct6, string opcodestr>
let RVVConstraint = VMConstraint;
}

//===----------------------------------------------------------------------===//
// Multiclass
//===----------------------------------------------------------------------===//

let fprclass = !cast<RegisterClass>("FPR32") in
def SCALAR_F16_FPR32 : FPR_Info<16>;

let hasSideEffects = 0 in
multiclass VPseudoVFPMAD_VF_RM {
foreach m = SCALAR_F16_FPR32.MxList in {
defm "" : VPseudoBinaryV_VF_RM<m, SCALAR_F16_FPR32, 0>,
SchedBinary<"WriteVFMulAddF", "ReadVFMulAddV", "ReadVFMulAddF",
m.MX, SCALAR_F16_FPR32.SEW, forcePassthruRead=true>;
}
}

multiclass VPatVFPMADBinaryV_VX_RM<string intrinsic, string instruction,
list<VTypeInfo> vtilist> {
foreach vti = vtilist in {
defvar kind = "V"#vti.ScalarSuffix;
defm : VPatBinaryRoundingMode<intrinsic, instruction#"_"#kind#"_"#vti.LMul.MX,
vti.Vector, vti.Vector, f32, vti.Mask,
vti.Log2SEW, vti.RegClass,
vti.RegClass, FPR32>;
}
}

//===----------------------------------------------------------------------===//
// XAndesPerf
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -400,7 +427,9 @@ def NDS_VFPMADB_VF : NDSRVInstVFPMAD<0b000011, "nds.vfpmadb">;
}
} // DecoderNamespace = "XAndes"

// Patterns
//===----------------------------------------------------------------------===//
// Pseudo-instructions and codegen patterns
//===----------------------------------------------------------------------===//

let Predicates = [HasVendorXAndesPerf] in {

Expand Down Expand Up @@ -428,3 +457,12 @@ def : Sh1AddPat<NDS_LEA_H_ZE>;
def : Sh2AddPat<NDS_LEA_W_ZE>;
def : Sh3AddPat<NDS_LEA_D_ZE>;
} // Predicates = [HasVendorXAndesPerf, IsRV64]

let Predicates = [HasVendorXAndesVPackFPH],
mayRaiseFPException = true in {
defm PseudoNDS_VFPMADT : VPseudoVFPMAD_VF_RM;
defm PseudoNDS_VFPMADB : VPseudoVFPMAD_VF_RM;
} // Predicates = [HasVendorXAndesVPackFPH]

defm : VPatVFPMADBinaryV_VX_RM<"int_riscv_nds_vfpmadt", "PseudoNDS_VFPMADT", AllFP16Vectors>;
defm : VPatVFPMADBinaryV_VX_RM<"int_riscv_nds_vfpmadb", "PseudoNDS_VFPMADB", AllFP16Vectors>;
299 changes: 299 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/xandesvpackfph-vfpmadb.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+zve64x,+xandesvpackfph \
; RUN: -verify-machineinstrs -target-abi=ilp32f | FileCheck %s
; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+zve64x,+xandesvpackfph \
; RUN: -verify-machineinstrs -target-abi=lp64f | FileCheck %s

declare <vscale x 1 x half> @llvm.riscv.nds.vfpmadb.nxv1f16.f32(
<vscale x 1 x half>,
<vscale x 1 x half>,
float,
iXLen, iXLen);

define <vscale x 1 x half> @intrinsic_vfpmadb_vf_nxv1f16_nxv1f16_f32(<vscale x 1 x half> %0, float %1, iXLen %2) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_vf_nxv1f16_nxv1f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, mf4, ta, ma
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v8
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 1 x half> @llvm.riscv.nds.vfpmadb.nxv1f16.f32(
<vscale x 1 x half> undef,
<vscale x 1 x half> %0,
float %1, iXLen 0, iXLen %2)

ret <vscale x 1 x half> %a
}

declare <vscale x 1 x half> @llvm.riscv.nds.vfpmadb.mask.nxv1f16.f32(
<vscale x 1 x half>,
<vscale x 1 x half>,
float,
<vscale x 1 x i1>,
iXLen, iXLen, iXLen);

define <vscale x 1 x half> @intrinsic_vfpmadb_mask_vf_nxv1f16_nxv1f16_f32(<vscale x 1 x half> %0, <vscale x 1 x half> %1, float %2, <vscale x 1 x i1> %3, iXLen %4) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_mask_vf_nxv1f16_nxv1f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, mf4, ta, mu
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v9, v0.t
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 1 x half> @llvm.riscv.nds.vfpmadb.mask.nxv1f16.f32(
<vscale x 1 x half> %0,
<vscale x 1 x half> %1,
float %2,
<vscale x 1 x i1> %3,
iXLen 0, iXLen %4, iXLen 1)

ret <vscale x 1 x half> %a
}

declare <vscale x 2 x half> @llvm.riscv.nds.vfpmadb.nxv2f16.f32(
<vscale x 2 x half>,
<vscale x 2 x half>,
float,
iXLen, iXLen);

define <vscale x 2 x half> @intrinsic_vfpmadb_vf_nxv2f16_nxv2f16_f32(<vscale x 2 x half> %0, float %1, iXLen %2) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_vf_nxv2f16_nxv2f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, mf2, ta, ma
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v8
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 2 x half> @llvm.riscv.nds.vfpmadb.nxv2f16.f32(
<vscale x 2 x half> undef,
<vscale x 2 x half> %0,
float %1, iXLen 0, iXLen %2)

ret <vscale x 2 x half> %a
}

declare <vscale x 2 x half> @llvm.riscv.nds.vfpmadb.mask.nxv2f16.f32(
<vscale x 2 x half>,
<vscale x 2 x half>,
float,
<vscale x 2 x i1>,
iXLen, iXLen, iXLen);

define <vscale x 2 x half> @intrinsic_vfpmadb_mask_vf_nxv2f16_nxv2f16_f32(<vscale x 2 x half> %0, <vscale x 2 x half> %1, float %2, <vscale x 2 x i1> %3, iXLen %4) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_mask_vf_nxv2f16_nxv2f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, mf2, ta, mu
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v9, v0.t
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 2 x half> @llvm.riscv.nds.vfpmadb.mask.nxv2f16.f32(
<vscale x 2 x half> %0,
<vscale x 2 x half> %1,
float %2,
<vscale x 2 x i1> %3,
iXLen 0, iXLen %4, iXLen 1)

ret <vscale x 2 x half> %a
}

declare <vscale x 4 x half> @llvm.riscv.nds.vfpmadb.nxv4f16.f32(
<vscale x 4 x half>,
<vscale x 4 x half>,
float,
iXLen, iXLen);

define <vscale x 4 x half> @intrinsic_vfpmadb_vf_nxv4f16_nxv4f16_f32(<vscale x 4 x half> %0, float %1, iXLen %2) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_vf_nxv4f16_nxv4f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, m1, ta, ma
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v8
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 4 x half> @llvm.riscv.nds.vfpmadb.nxv4f16.f32(
<vscale x 4 x half> undef,
<vscale x 4 x half> %0,
float %1, iXLen 0, iXLen %2)

ret <vscale x 4 x half> %a
}

declare <vscale x 4 x half> @llvm.riscv.nds.vfpmadb.mask.nxv4f16.f32(
<vscale x 4 x half>,
<vscale x 4 x half>,
float,
<vscale x 4 x i1>,
iXLen, iXLen, iXLen);

define <vscale x 4 x half> @intrinsic_vfpmadb_mask_vf_nxv4f16_nxv4f16_f32(<vscale x 4 x half> %0, <vscale x 4 x half> %1, float %2, <vscale x 4 x i1> %3, iXLen %4) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_mask_vf_nxv4f16_nxv4f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, m1, ta, mu
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v9, v0.t
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 4 x half> @llvm.riscv.nds.vfpmadb.mask.nxv4f16.f32(
<vscale x 4 x half> %0,
<vscale x 4 x half> %1,
float %2,
<vscale x 4 x i1> %3,
iXLen 0, iXLen %4, iXLen 1)

ret <vscale x 4 x half> %a
}

declare <vscale x 8 x half> @llvm.riscv.nds.vfpmadb.nxv8f16.f32(
<vscale x 8 x half>,
<vscale x 8 x half>,
float,
iXLen, iXLen);

define <vscale x 8 x half> @intrinsic_vfpmadb_vf_nxv8f16_nxv8f16_f32(<vscale x 8 x half> %0, float %1, iXLen %2) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_vf_nxv8f16_nxv8f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, m2, ta, ma
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v8
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 8 x half> @llvm.riscv.nds.vfpmadb.nxv8f16.f32(
<vscale x 8 x half> undef,
<vscale x 8 x half> %0,
float %1, iXLen 0, iXLen %2)

ret <vscale x 8 x half> %a
}

declare <vscale x 8 x half> @llvm.riscv.nds.vfpmadb.mask.nxv8f16.f32(
<vscale x 8 x half>,
<vscale x 8 x half>,
float,
<vscale x 8 x i1>,
iXLen, iXLen, iXLen);

define <vscale x 8 x half> @intrinsic_vfpmadb_mask_vf_nxv8f16_nxv8f16_f32(<vscale x 8 x half> %0, <vscale x 8 x half> %1, float %2, <vscale x 8 x i1> %3, iXLen %4) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_mask_vf_nxv8f16_nxv8f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, m2, ta, mu
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v10, v0.t
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 8 x half> @llvm.riscv.nds.vfpmadb.mask.nxv8f16.f32(
<vscale x 8 x half> %0,
<vscale x 8 x half> %1,
float %2,
<vscale x 8 x i1> %3,
iXLen 0, iXLen %4, iXLen 1)

ret <vscale x 8 x half> %a
}

declare <vscale x 16 x half> @llvm.riscv.nds.vfpmadb.nxv16f16.f32(
<vscale x 16 x half>,
<vscale x 16 x half>,
float,
iXLen, iXLen);

define <vscale x 16 x half> @intrinsic_vfpmadb_vf_nxv16f16_nxv16f16_f32(<vscale x 16 x half> %0, float %1, iXLen %2) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_vf_nxv16f16_nxv16f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, m4, ta, ma
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v8
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 16 x half> @llvm.riscv.nds.vfpmadb.nxv16f16.f32(
<vscale x 16 x half> undef,
<vscale x 16 x half> %0,
float %1, iXLen 0, iXLen %2)

ret <vscale x 16 x half> %a
}

declare <vscale x 16 x half> @llvm.riscv.nds.vfpmadb.mask.nxv16f16.f32(
<vscale x 16 x half>,
<vscale x 16 x half>,
float,
<vscale x 16 x i1>,
iXLen, iXLen, iXLen);

define <vscale x 16 x half> @intrinsic_vfpmadb_mask_vf_nxv16f16_nxv16f16_f32(<vscale x 16 x half> %0, <vscale x 16 x half> %1, float %2, <vscale x 16 x i1> %3, iXLen %4) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_mask_vf_nxv16f16_nxv16f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, m4, ta, mu
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v12, v0.t
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 16 x half> @llvm.riscv.nds.vfpmadb.mask.nxv16f16.f32(
<vscale x 16 x half> %0,
<vscale x 16 x half> %1,
float %2,
<vscale x 16 x i1> %3,
iXLen 0, iXLen %4, iXLen 1)

ret <vscale x 16 x half> %a
}

declare <vscale x 32 x half> @llvm.riscv.nds.vfpmadb.nxv32f16.f32(
<vscale x 32 x half>,
<vscale x 32 x half>,
float,
iXLen, iXLen);

define <vscale x 32 x half> @intrinsic_vfpmadb_vf_nxv32f16_nxv32f16_f32(<vscale x 32 x half> %0, float %1, iXLen %2) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_vf_nxv32f16_nxv32f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, m8, ta, ma
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v8
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 32 x half> @llvm.riscv.nds.vfpmadb.nxv32f16.f32(
<vscale x 32 x half> undef,
<vscale x 32 x half> %0,
float %1, iXLen 0, iXLen %2)

ret <vscale x 32 x half> %a
}

declare <vscale x 32 x half> @llvm.riscv.nds.vfpmadb.mask.nxv32f16.f32(
<vscale x 32 x half>,
<vscale x 32 x half>,
float,
<vscale x 32 x i1>,
iXLen, iXLen, iXLen);

define <vscale x 32 x half> @intrinsic_vfpmadb_mask_vf_nxv32f16_nxv32f16_f32(<vscale x 32 x half> %0, <vscale x 32 x half> %1, float %2, <vscale x 32 x i1> %3, iXLen %4) nounwind {
; CHECK-LABEL: intrinsic_vfpmadb_mask_vf_nxv32f16_nxv32f16_f32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: fsrmi a1, 0
; CHECK-NEXT: vsetvli zero, a0, e16, m8, ta, mu
; CHECK-NEXT: nds.vfpmadb.vf v8, fa0, v16, v0.t
; CHECK-NEXT: fsrm a1
; CHECK-NEXT: ret
entry:
%a = tail call <vscale x 32 x half> @llvm.riscv.nds.vfpmadb.mask.nxv32f16.f32(
<vscale x 32 x half> %0,
<vscale x 32 x half> %1,
float %2,
<vscale x 32 x i1> %3,
iXLen 0, iXLen %4, iXLen 1)

ret <vscale x 32 x half> %a
}
Loading
Loading