[llvm] [NVPTX] Implement llvm.fptrunc.round intrinsic (PR #223720)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 09:47:47 PDT 2026
https://github.com/peterbell10 updated https://github.com/llvm/llvm-project/pull/223720
>From afcd8aab8738be7ef7ff017e2f581509b3ccbb01 Mon Sep 17 00:00:00 2001
From: Peter Bell <peterbell10 at openai.com>
Date: Tue, 15 Sep 2026 13:25:45 +0100
Subject: [PATCH 1/4] [NVPTX] Implement llvm.fptrunc.round intrinsic
This patch implements hardware-dependent selection for llvm.fptrunc.round.
`round.tonearest` mode is canonicalized to `fpround`, and so is supported on all
hardware. Other rounding modes are conditionally supported depending on the SM
and PTX version e.g. bf16 support requires sm80 for rz and sm90 for rm or rp.
This also adds direct conversions between bfloat and half, so e.g.
```
fptrunc.round (fpextend x), "round.down"
```
will select `cvt.rm.f16.bf16` on sm90+
Assisted-by: GPT-6 Astra
---
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 45 +
llvm/lib/Target/NVPTX/NVPTXISelLowering.h | 1 +
llvm/lib/Target/NVPTX/NVPTXInstrInfo.td | 37 +
.../CodeGen/NVPTX/convert-fptrunc-round.ll | 891 ++++++++++++++++++
4 files changed, 974 insertions(+)
create mode 100644 llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index a21af472576cd..8e3b8e209892e 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -992,6 +992,9 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
}
}
+ // Expand nearest-even rounding and diagnose unsupported conversions.
+ setOperationAction(ISD::FPTRUNC_ROUND, {MVT::f16, MVT::bf16, MVT::f32}, Custom);
+
// Expand v2f32 = fp_extend
setOperationAction(ISD::FP_EXTEND, MVT::v2f32, Expand);
// Expand v2[b]f16 = fp_round v2f32
@@ -2431,6 +2434,46 @@ SDValue NVPTXTargetLowering::LowerFP_ROUND(SDValue Op,
return Op;
}
+SDValue NVPTXTargetLowering::LowerFPTRUNC_ROUND(SDValue Op,
+ SelectionDAG &DAG) const {
+ EVT SrcVT = Op.getOperand(0).getValueType();
+ EVT DstVT = Op.getValueType();
+ auto RM = static_cast<RoundingMode>(Op.getConstantOperandVal(1));
+ if (RM == RoundingMode::NearestTiesToEven) {
+ // Reuse the native selection and fallback expansion for ordinary fptrunc.
+ SDLoc DL(Op);
+ return DAG.getNode(ISD::FP_ROUND, DL, DstVT, Op.getOperand(0),
+ DAG.getIntPtrConstant(0, DL, /*isTarget=*/true),
+ Op.getNode()->getFlags());
+ }
+
+ bool RoundToInfinity = RM == RoundingMode::TowardNegative ||
+ RM == RoundingMode::TowardPositive;
+
+ StringRef Error;
+ if (RM != RoundingMode::TowardZero && !RoundToInfinity) {
+ Error = "is not supported on this target";
+ } else if (DstVT == MVT::bf16) {
+ if (SrcVT == MVT::f64 || RoundToInfinity) {
+ if (!STI.hasFeature(NVPTX::SM90))
+ Error = "requires sm_90 or higher";
+ } else if (!STI.hasFeature(NVPTX::SM80)) {
+ Error = "requires sm_80 or higher";
+ }
+ }
+
+ if (Error.empty())
+ return Op;
+
+ DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
+ DAG.getMachineFunction().getFunction(),
+ Twine("llvm.fptrunc.round from ") + SrcVT.getEVTString() + " to " +
+ DstVT.getEVTString() + " with rounding mode " +
+ *convertRoundingModeToStr(RM) + " " + Error,
+ SDLoc(Op).getDebugLoc()));
+ return DAG.getPOISON(DstVT);
+}
+
SDValue NVPTXTargetLowering::LowerFP_EXTEND(SDValue Op,
SelectionDAG &DAG) const {
SDValue Narrow = Op.getOperand(0);
@@ -3514,6 +3557,8 @@ NVPTXTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
return LowerFP_TO_INT(Op, DAG);
case ISD::FP_ROUND:
return LowerFP_ROUND(Op, DAG);
+ case ISD::FPTRUNC_ROUND:
+ return LowerFPTRUNC_ROUND(Op, DAG);
case ISD::FP_EXTEND:
return LowerFP_EXTEND(Op, DAG);
case ISD::VAARG:
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.h b/llvm/lib/Target/NVPTX/NVPTXISelLowering.h
index 4942408f6449b..53a65fc898c44 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.h
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.h
@@ -209,6 +209,7 @@ class NVPTXTargetLowering : public TargetLowering {
SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
+ SDValue LowerFPTRUNC_ROUND(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
diff --git a/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td b/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
index 03090c5aaf964..cb4a7802e1a5f 100644
--- a/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
+++ b/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
@@ -2550,6 +2550,43 @@ let hasSideEffects = false in {
}
}
+def : Pat<(f16 (fpround (f32 (fpextend bf16:$a)))),
+ (CVT_f16_bf16 $a, CvtRN)>, Requires<[SM90]>;
+def : Pat<(bf16 (fpround (f32 (fpextend f16:$a)))),
+ (CVT_bf16_f16 $a, CvtRN)>, Requires<[SM90]>;
+
+multiclass CVT_FPTRUNC_ROUND<string RoundMode, PatLeaf Mode, PatLeaf ModeFTZ,
+ bit RoundToInfinity> {
+ defvar Round = TImmLeaf<i32,
+ "return Imm == static_cast<int>(RoundingMode::" # RoundMode # ");">;
+
+ def : Pat<(f16 (fptrunc_round f32:$a, Round)),
+ (CVT_f16_f32 $a, Mode)>;
+ def : Pat<(bf16 (fptrunc_round f32:$a, Round)),
+ (CVT_bf16_f32 $a, Mode)>,
+ Requires<!if(RoundToInfinity, [SM90], [SM80])>;
+
+ def : Pat<(f16 (fptrunc_round f64:$a, Round)),
+ (CVT_f16_f64 $a, Mode)>;
+ def : Pat<(bf16 (fptrunc_round f64:$a, Round)),
+ (CVT_bf16_f64 $a, Mode)>, Requires<[SM90]>;
+ def : Pat<(f32 (fptrunc_round f64:$a, Round)),
+ (CVT_f32_f64 $a, ModeFTZ)>, Requires<[doF32FTZ]>;
+ def : Pat<(f32 (fptrunc_round f64:$a, Round)),
+ (CVT_f32_f64 $a, Mode)>;
+
+ // Flushing the intermediate f32 can change directed rounding to f16.
+ def : Pat<(f16 (fptrunc_round (f32 (fpextend bf16:$a)), Round)),
+ (CVT_f16_bf16 $a, Mode)>,
+ Requires<!if(RoundToInfinity, [SM90, doNoF32FTZ], [SM90])>;
+ def : Pat<(bf16 (fptrunc_round (f32 (fpextend f16:$a)), Round)),
+ (CVT_bf16_f16 $a, Mode)>, Requires<[SM90]>;
+}
+
+defm : CVT_FPTRUNC_ROUND<"TowardZero", CvtRZ, CvtRZ_FTZ, 0>;
+defm : CVT_FPTRUNC_ROUND<"TowardNegative", CvtRM, CvtRM_FTZ, 1>;
+defm : CVT_FPTRUNC_ROUND<"TowardPositive", CvtRP, CvtRP_FTZ, 1>;
+
// fpround f32 -> f16
def : Pat<(f16 (fpround f32:$a)), (CVT_f16_f32 $a, CvtRN)>;
diff --git a/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll b/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
new file mode 100644
index 0000000000000..37ae9153a2ae3
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
@@ -0,0 +1,891 @@
+; Split since some rounding modes are unsupported on older hardware.
+; RUN: split-file %s %t
+; RUN: cat %t/common.ll %t/sm80.ll > %t/all-sm80.ll
+; RUN: cat %t/common.ll %t/sm80.ll %t/sm90.ll > %t/all-sm90.ll
+; RUN: llc < %t/common.ll -mtriple=nvptx64 -mcpu=sm_70 -mattr=+ptx71 | FileCheck --check-prefixes=SM70,SM70-NOFTZ %s
+; RUN: %if ptxas-sm_70 && ptxas-isa-7.1 %{ llc < %t/common.ll -mtriple=nvptx64 -mcpu=sm_70 -mattr=+ptx71 | %ptxas-verify -arch=sm_70 %}
+; RUN: llc < %t/common.ll -mtriple=nvptx64 -mcpu=sm_70 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | FileCheck --check-prefixes=SM70,SM70-FTZ %s
+; RUN: %if ptxas-sm_70 && ptxas-isa-7.1 %{ llc < %t/common.ll -mtriple=nvptx64 -mcpu=sm_70 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | %ptxas-verify -arch=sm_70 %}
+; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | FileCheck --check-prefix=SM80-PTX70 %s
+; RUN: %if ptxas-sm_80 && ptxas-isa-7.0 %{ llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | %ptxas-verify -arch=sm_80 %}
+; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 | FileCheck --check-prefixes=SM80,SM80-NOFTZ %s
+; RUN: %if ptxas-sm_80 && ptxas-isa-7.1 %{ llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 | %ptxas-verify -arch=sm_80 %}
+; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | FileCheck --check-prefixes=SM80,SM80-FTZ %s
+; RUN: %if ptxas-sm_80 && ptxas-isa-7.1 %{ llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | %ptxas-verify -arch=sm_80 %}
+; RUN: llc < %t/all-sm90.ll -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx78 | FileCheck --check-prefixes=SM90,SM90-NOFTZ %s
+; RUN: %if ptxas-sm_90 && ptxas-isa-7.8 %{ llc < %t/all-sm90.ll -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx78 | %ptxas-verify -arch=sm_90 %}
+; RUN: llc < %t/all-sm90.ll -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx78 -denormal-fp-math-f32=preserve-sign | FileCheck --check-prefixes=SM90,SM90-FTZ %s
+; RUN: %if ptxas-sm_90 && ptxas-isa-7.8 %{ llc < %t/all-sm90.ll -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx78 -denormal-fp-math-f32=preserve-sign | %ptxas-verify -arch=sm_90 %}
+
+; RUN: not llc < %t/all-sm90.ll -mtriple=nvptx64 -mcpu=sm_70 -mattr=+ptx71 -o /dev/null 2>&1 | FileCheck --check-prefix=SM70-ERR %s
+; RUN: not llc < %t/all-sm90.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 -o /dev/null 2>&1 | FileCheck --check-prefix=SM80-ERR %s
+; RUN: not llc < %t/unsupported-rounding.ll -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx78 -o /dev/null 2>&1 | FileCheck --check-prefix=ROUND-ERR %s
+
+;--- common.ll
+declare half @llvm.fptrunc.round.f16.f32(float, metadata)
+declare bfloat @llvm.fptrunc.round.bf16.f32(float, metadata)
+declare half @llvm.fptrunc.round.f16.f64(double, metadata)
+declare float @llvm.fptrunc.round.f32.f64(double, metadata)
+declare bfloat @llvm.fptrunc.round.bf16.f64(double, metadata)
+
+define half @cvt_f16_bf16(bfloat %a) {
+; SM70-LABEL: cvt_f16_bf16(
+; SM70: ld.param.b16 [[A:%r[0-9]+]], [cvt_f16_bf16_param_0];
+; SM70-NEXT: shl.b32 [[EXT:%r[0-9]+]], [[A]], 16;
+; SM70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: cvt_f16_bf16(
+; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
+; SM80-PTX70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: cvt_f16_bf16(
+; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_f16_bf16_param_0];
+; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: cvt_f16_bf16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_f16_bf16_param_0];
+; SM90-NEXT: cvt.rn.f16.bf16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext bfloat %a to float
+ %res = fptrunc float %ext to half
+ ret half %res
+}
+
+define bfloat @cvt_bf16_f16(half %a) {
+; SM70-LABEL: cvt_bf16_f16(
+; SM70-NOFTZ: cvt.f32.f16 [[EXT:%r[0-9]+]], %rs{{[0-9]+}};
+; SM70-FTZ: cvt.ftz.f32.f16 [[EXT:%r[0-9]+]], %rs{{[0-9]+}};
+; SM70-NEXT: bfe.u32 {{%r[0-9]+}}, [[EXT]], 16, 1;
+; SM70: shr.u32 [[RES:%r[0-9]+]], {{%r[0-9]+}}, 16;
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: cvt_bf16_f16(
+; SM80-PTX70: ld.param.b16 [[A:%rs[0-9]+]], [cvt_bf16_f16_param_0];
+; SM80-PTX70-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: cvt_bf16_f16(
+; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_bf16_f16_param_0];
+; SM80-NOFTZ-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-FTZ-NEXT: cvt.ftz.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: cvt_bf16_f16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_bf16_f16_param_0];
+; SM90-NEXT: cvt.rn.bf16.f16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext half %a to float
+ %res = fptrunc float %ext to bfloat
+ ret bfloat %res
+}
+
+define half @cvt_rn_f16_bf16(bfloat %a) {
+; SM70-LABEL: cvt_rn_f16_bf16(
+; SM70: ld.param.b16 [[A:%r[0-9]+]], [cvt_rn_f16_bf16_param_0];
+; SM70-NEXT: shl.b32 [[EXT:%r[0-9]+]], [[A]], 16;
+; SM70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: cvt_rn_f16_bf16(
+; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
+; SM80-PTX70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: cvt_rn_f16_bf16(
+; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_f16_bf16_param_0];
+; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: cvt_rn_f16_bf16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_f16_bf16_param_0];
+; SM90-NEXT: cvt.rn.f16.bf16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext bfloat %a to float
+ %res = call half @llvm.fptrunc.round.f16.f32(float %ext, metadata !"round.tonearest")
+ ret half %res
+}
+
+define half @cvt_rz_f16_bf16(bfloat %a) {
+; SM70-LABEL: cvt_rz_f16_bf16(
+; SM70: ld.param.b16 [[A:%r[0-9]+]], [cvt_rz_f16_bf16_param_0];
+; SM70-NEXT: shl.b32 [[EXT:%r[0-9]+]], [[A]], 16;
+; SM70-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: cvt_rz_f16_bf16(
+; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
+; SM80-PTX70-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: cvt_rz_f16_bf16(
+; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_f16_bf16_param_0];
+; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: cvt_rz_f16_bf16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_f16_bf16_param_0];
+; SM90-NEXT: cvt.rz.f16.bf16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext bfloat %a to float
+ %res = call half @llvm.fptrunc.round.f16.f32(float %ext, metadata !"round.towardzero")
+ ret half %res
+}
+
+define half @cvt_rm_f16_bf16(bfloat %a) {
+; SM70-LABEL: cvt_rm_f16_bf16(
+; SM70: ld.param.b16 [[A:%r[0-9]+]], [cvt_rm_f16_bf16_param_0];
+; SM70-NEXT: shl.b32 [[EXT:%r[0-9]+]], [[A]], 16;
+; SM70-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: cvt_rm_f16_bf16(
+; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
+; SM80-PTX70-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: cvt_rm_f16_bf16(
+; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rm_f16_bf16_param_0];
+; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: cvt_rm_f16_bf16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rm_f16_bf16_param_0];
+; SM90-NOFTZ-NEXT: cvt.rm.f16.bf16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-FTZ-NEXT: cvt.ftz.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM90-FTZ-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext bfloat %a to float
+ %res = call half @llvm.fptrunc.round.f16.f32(float %ext, metadata !"round.downward")
+ ret half %res
+}
+
+define half @cvt_rp_f16_bf16(bfloat %a) {
+; SM70-LABEL: cvt_rp_f16_bf16(
+; SM70: ld.param.b16 [[A:%r[0-9]+]], [cvt_rp_f16_bf16_param_0];
+; SM70-NEXT: shl.b32 [[EXT:%r[0-9]+]], [[A]], 16;
+; SM70-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: cvt_rp_f16_bf16(
+; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
+; SM80-PTX70-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: cvt_rp_f16_bf16(
+; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rp_f16_bf16_param_0];
+; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: cvt_rp_f16_bf16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rp_f16_bf16_param_0];
+; SM90-NOFTZ-NEXT: cvt.rp.f16.bf16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-FTZ-NEXT: cvt.ftz.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM90-FTZ-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext bfloat %a to float
+ %res = call half @llvm.fptrunc.round.f16.f32(float %ext, metadata !"round.upward")
+ ret half %res
+}
+
+define half @fptrunc_rn_f16_f32(float %a) {
+; SM70-LABEL: fptrunc_rn_f16_f32(
+; SM70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_f16_f32_param_0];
+; SM70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rn_f16_f32(
+; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_f16_f32_param_0];
+; SM80-PTX70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rn_f16_f32(
+; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_f16_f32_param_0];
+; SM80-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rn_f16_f32(
+; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_f16_f32_param_0];
+; SM90-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call half @llvm.fptrunc.round.f16.f32(float %a, metadata !"round.tonearest")
+ ret half %res
+}
+
+define half @fptrunc_rz_f16_f32(float %a) {
+; SM70-LABEL: fptrunc_rz_f16_f32(
+; SM70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_f16_f32_param_0];
+; SM70-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rz_f16_f32(
+; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_f16_f32_param_0];
+; SM80-PTX70-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rz_f16_f32(
+; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_f16_f32_param_0];
+; SM80-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rz_f16_f32(
+; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_f16_f32_param_0];
+; SM90-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call half @llvm.fptrunc.round.f16.f32(float %a, metadata !"round.towardzero")
+ ret half %res
+}
+
+define half @fptrunc_rm_f16_f32(float %a) {
+; SM70-LABEL: fptrunc_rm_f16_f32(
+; SM70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rm_f16_f32_param_0];
+; SM70-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rm_f16_f32(
+; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rm_f16_f32_param_0];
+; SM80-PTX70-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rm_f16_f32(
+; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rm_f16_f32_param_0];
+; SM80-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rm_f16_f32(
+; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rm_f16_f32_param_0];
+; SM90-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call half @llvm.fptrunc.round.f16.f32(float %a, metadata !"round.downward")
+ ret half %res
+}
+
+define half @fptrunc_rp_f16_f32(float %a) {
+; SM70-LABEL: fptrunc_rp_f16_f32(
+; SM70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rp_f16_f32_param_0];
+; SM70-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rp_f16_f32(
+; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rp_f16_f32_param_0];
+; SM80-PTX70-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rp_f16_f32(
+; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rp_f16_f32_param_0];
+; SM80-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rp_f16_f32(
+; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rp_f16_f32_param_0];
+; SM90-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call half @llvm.fptrunc.round.f16.f32(float %a, metadata !"round.upward")
+ ret half %res
+}
+
+define half @fptrunc_rn_f16_f64(double %a) {
+; SM70-LABEL: fptrunc_rn_f16_f64(
+; SM70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f16_f64_param_0];
+; SM70-NEXT: cvt.rn.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rn_f16_f64(
+; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f16_f64_param_0];
+; SM80-PTX70-NEXT: cvt.rn.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rn_f16_f64(
+; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f16_f64_param_0];
+; SM80-NEXT: cvt.rn.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rn_f16_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f16_f64_param_0];
+; SM90-NEXT: cvt.rn.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call half @llvm.fptrunc.round.f16.f64(double %a, metadata !"round.tonearest")
+ ret half %res
+}
+
+define half @fptrunc_rz_f16_f64(double %a) {
+; SM70-LABEL: fptrunc_rz_f16_f64(
+; SM70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f16_f64_param_0];
+; SM70-NEXT: cvt.rz.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rz_f16_f64(
+; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f16_f64_param_0];
+; SM80-PTX70-NEXT: cvt.rz.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rz_f16_f64(
+; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f16_f64_param_0];
+; SM80-NEXT: cvt.rz.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rz_f16_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f16_f64_param_0];
+; SM90-NEXT: cvt.rz.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call half @llvm.fptrunc.round.f16.f64(double %a, metadata !"round.towardzero")
+ ret half %res
+}
+
+define half @fptrunc_rm_f16_f64(double %a) {
+; SM70-LABEL: fptrunc_rm_f16_f64(
+; SM70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f16_f64_param_0];
+; SM70-NEXT: cvt.rm.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rm_f16_f64(
+; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f16_f64_param_0];
+; SM80-PTX70-NEXT: cvt.rm.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rm_f16_f64(
+; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f16_f64_param_0];
+; SM80-NEXT: cvt.rm.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rm_f16_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f16_f64_param_0];
+; SM90-NEXT: cvt.rm.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call half @llvm.fptrunc.round.f16.f64(double %a, metadata !"round.downward")
+ ret half %res
+}
+
+define half @fptrunc_rp_f16_f64(double %a) {
+; SM70-LABEL: fptrunc_rp_f16_f64(
+; SM70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f16_f64_param_0];
+; SM70-NEXT: cvt.rp.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rp_f16_f64(
+; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f16_f64_param_0];
+; SM80-PTX70-NEXT: cvt.rp.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rp_f16_f64(
+; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f16_f64_param_0];
+; SM80-NEXT: cvt.rp.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rp_f16_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f16_f64_param_0];
+; SM90-NEXT: cvt.rp.f16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call half @llvm.fptrunc.round.f16.f64(double %a, metadata !"round.upward")
+ ret half %res
+}
+
+define float @fptrunc_rn_f32_f64(double %a) {
+; SM70-LABEL: fptrunc_rn_f32_f64(
+; SM70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f32_f64_param_0];
+; SM70-NOFTZ-NEXT: cvt.rn.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM70-FTZ-NEXT: cvt.rn.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rn_f32_f64(
+; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f32_f64_param_0];
+; SM80-PTX70-NEXT: cvt.rn.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rn_f32_f64(
+; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f32_f64_param_0];
+; SM80-NOFTZ-NEXT: cvt.rn.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-FTZ-NEXT: cvt.rn.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rn_f32_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f32_f64_param_0];
+; SM90-NOFTZ-NEXT: cvt.rn.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM90-FTZ-NEXT: cvt.rn.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call float @llvm.fptrunc.round.f32.f64(double %a, metadata !"round.tonearest")
+ ret float %res
+}
+
+define float @fptrunc_rz_f32_f64(double %a) {
+; SM70-LABEL: fptrunc_rz_f32_f64(
+; SM70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f32_f64_param_0];
+; SM70-NOFTZ-NEXT: cvt.rz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM70-FTZ-NEXT: cvt.rz.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rz_f32_f64(
+; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f32_f64_param_0];
+; SM80-PTX70-NEXT: cvt.rz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rz_f32_f64(
+; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f32_f64_param_0];
+; SM80-NOFTZ-NEXT: cvt.rz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-FTZ-NEXT: cvt.rz.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rz_f32_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f32_f64_param_0];
+; SM90-NOFTZ-NEXT: cvt.rz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM90-FTZ-NEXT: cvt.rz.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call float @llvm.fptrunc.round.f32.f64(double %a, metadata !"round.towardzero")
+ ret float %res
+}
+
+define float @fptrunc_rm_f32_f64(double %a) {
+; SM70-LABEL: fptrunc_rm_f32_f64(
+; SM70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f32_f64_param_0];
+; SM70-NOFTZ-NEXT: cvt.rm.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM70-FTZ-NEXT: cvt.rm.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rm_f32_f64(
+; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f32_f64_param_0];
+; SM80-PTX70-NEXT: cvt.rm.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rm_f32_f64(
+; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f32_f64_param_0];
+; SM80-NOFTZ-NEXT: cvt.rm.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-FTZ-NEXT: cvt.rm.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rm_f32_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f32_f64_param_0];
+; SM90-NOFTZ-NEXT: cvt.rm.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM90-FTZ-NEXT: cvt.rm.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call float @llvm.fptrunc.round.f32.f64(double %a, metadata !"round.downward")
+ ret float %res
+}
+
+define float @fptrunc_rp_f32_f64(double %a) {
+; SM70-LABEL: fptrunc_rp_f32_f64(
+; SM70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f32_f64_param_0];
+; SM70-NOFTZ-NEXT: cvt.rp.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM70-FTZ-NEXT: cvt.rp.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM70-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rp_f32_f64(
+; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f32_f64_param_0];
+; SM80-PTX70-NEXT: cvt.rp.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rp_f32_f64(
+; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f32_f64_param_0];
+; SM80-NOFTZ-NEXT: cvt.rp.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-FTZ-NEXT: cvt.rp.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rp_f32_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f32_f64_param_0];
+; SM90-NOFTZ-NEXT: cvt.rp.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM90-FTZ-NEXT: cvt.rp.ftz.f32.f64 [[RES:%r[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b32 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call float @llvm.fptrunc.round.f32.f64(double %a, metadata !"round.upward")
+ ret float %res
+}
+
+define bfloat @cvt_rn_bf16_f16(half %a) {
+; SM70-LABEL: cvt_rn_bf16_f16(
+; SM70: ld.param.b16 [[RS1:%rs[0-9]+]], [cvt_rn_bf16_f16_param_0];
+; SM70-NOFTZ-NEXT: cvt.f32.f16 [[R1:%r[0-9]+]], [[RS1]];
+; SM70-FTZ-NEXT: cvt.ftz.f32.f16 [[R1:%r[0-9]+]], [[RS1]];
+; SM70-NEXT: bfe.u32 [[R2:%r[0-9]+]], [[R1]], 16, 1;
+; SM70-NEXT: add.s32 [[R3:%r[0-9]+]], [[R2]], [[R1]];
+; SM70-NEXT: add.s32 [[R4:%r[0-9]+]], [[R3]], 32767;
+; SM70-NOFTZ-NEXT: setp.nan.f32 [[P1:%p[0-9]+]], [[R1]], [[R1]];
+; SM70-FTZ-NEXT: setp.nan.ftz.f32 [[P1:%p[0-9]+]], [[R1]], [[R1]];
+; SM70-NEXT: or.b32 [[R5:%r[0-9]+]], [[R1]], 4194304;
+; SM70-NEXT: selp.b32 [[R6:%r[0-9]+]], [[R5]], [[R4]], [[P1]];
+; SM70-NEXT: shr.u32 [[R7:%r[0-9]+]], [[R6]], 16;
+; SM70-NEXT: st.param.b16 [func_retval0], [[R7]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: cvt_rn_bf16_f16(
+; SM80-PTX70: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_bf16_f16_param_0];
+; SM80-PTX70-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: cvt_rn_bf16_f16(
+; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_bf16_f16_param_0];
+; SM80-NOFTZ-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-FTZ-NEXT: cvt.ftz.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: cvt_rn_bf16_f16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_bf16_f16_param_0];
+; SM90-NEXT: cvt.rn.bf16.f16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext half %a to float
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %ext, metadata !"round.tonearest")
+ ret bfloat %res
+}
+
+define bfloat @fptrunc_rn_bf16_f32(float %a) {
+; SM70-LABEL: fptrunc_rn_bf16_f32(
+; SM70: ld.param.b32 [[R1:%r[0-9]+]], [fptrunc_rn_bf16_f32_param_0];
+; SM70-NEXT: bfe.u32 [[R2:%r[0-9]+]], [[R1]], 16, 1;
+; SM70-NEXT: add.s32 [[R3:%r[0-9]+]], [[R2]], [[R1]];
+; SM70-NEXT: add.s32 [[R4:%r[0-9]+]], [[R3]], 32767;
+; SM70-NOFTZ-NEXT: setp.nan.f32 [[P1:%p[0-9]+]], [[R1]], [[R1]];
+; SM70-FTZ-NEXT: setp.nan.ftz.f32 [[P1:%p[0-9]+]], [[R1]], [[R1]];
+; SM70-NEXT: or.b32 [[R5:%r[0-9]+]], [[R1]], 4194304;
+; SM70-NEXT: selp.b32 [[R6:%r[0-9]+]], [[R5]], [[R4]], [[P1]];
+; SM70-NEXT: shr.u32 [[R7:%r[0-9]+]], [[R6]], 16;
+; SM70-NEXT: st.param.b16 [func_retval0], [[R7]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rn_bf16_f32(
+; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_bf16_f32_param_0];
+; SM80-PTX70-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rn_bf16_f32(
+; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_bf16_f32_param_0];
+; SM80-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rn_bf16_f32(
+; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_bf16_f32_param_0];
+; SM90-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %a, metadata !"round.tonearest")
+ ret bfloat %res
+}
+
+define bfloat @fptrunc_rn_bf16_f64(double %a) {
+; SM70-LABEL: fptrunc_rn_bf16_f64(
+; SM70: ld.param.b64 [[RD1:%rd[0-9]+]], [fptrunc_rn_bf16_f64_param_0];
+; SM70-NEXT: abs.f64 [[RD2:%rd[0-9]+]], [[RD1]];
+; SM70-NOFTZ-NEXT: cvt.rn.f32.f64 [[R1:%r[0-9]+]], [[RD1]];
+; SM70-NOFTZ-NEXT: cvt.f64.f32 [[RD3:%rd[0-9]+]], [[R1]];
+; SM70-FTZ-NEXT: cvt.rn.ftz.f32.f64 [[R1:%r[0-9]+]], [[RD1]];
+; SM70-FTZ-NEXT: cvt.ftz.f64.f32 [[RD3:%rd[0-9]+]], [[R1]];
+; SM70-NEXT: abs.f64 [[RD4:%rd[0-9]+]], [[RD3]];
+; SM70-NEXT: setp.gt.f64 [[P1:%p[0-9]+]], [[RD2]], [[RD4]];
+; SM70-NEXT: selp.b32 [[R2:%r[0-9]+]], 1, -1, [[P1]];
+; SM70-NEXT: add.s32 [[R3:%r[0-9]+]], [[R1]], [[R2]];
+; SM70-NEXT: and.b32 [[R4:%r[0-9]+]], [[R1]], 1;
+; SM70-NEXT: setp.ne.b32 [[P2:%p[0-9]+]], [[R4]], 0;
+; SM70-NEXT: selp.b32 [[R5:%r[0-9]+]], [[R1]], [[R3]], [[P2]];
+; SM70-NEXT: setp.equ.f64 [[P3:%p[0-9]+]], [[RD1]], [[RD3]];
+; SM70-NEXT: selp.b32 [[R6:%r[0-9]+]], [[R1]], [[R5]], [[P3]];
+; SM70-NEXT: bfe.u32 [[R7:%r[0-9]+]], [[R6]], 16, 1;
+; SM70-NEXT: add.s32 [[R8:%r[0-9]+]], [[R7]], [[R6]];
+; SM70-NEXT: add.s32 [[R9:%r[0-9]+]], [[R8]], 32767;
+; SM70-NEXT: or.b32 [[R10:%r[0-9]+]], [[R6]], 4194304;
+; SM70-NEXT: setp.nan.f64 [[P4:%p[0-9]+]], [[RD1]], [[RD1]];
+; SM70-NEXT: selp.b32 [[R11:%r[0-9]+]], [[R10]], [[R9]], [[P4]];
+; SM70-NEXT: shr.u32 [[R12:%r[0-9]+]], [[R11]], 16;
+; SM70-NEXT: st.param.b16 [func_retval0], [[R12]];
+; SM70-NEXT: ret;
+;
+; SM80-PTX70-LABEL: fptrunc_rn_bf16_f64(
+; SM80-PTX70: ld.param.b64 [[RD1:%rd[0-9]+]], [fptrunc_rn_bf16_f64_param_0];
+; SM80-PTX70-NEXT: abs.f64 [[RD2:%rd[0-9]+]], [[RD1]];
+; SM80-PTX70-NEXT: cvt.rn.f32.f64 [[R1:%r[0-9]+]], [[RD1]];
+; SM80-PTX70-NEXT: cvt.f64.f32 [[RD3:%rd[0-9]+]], [[R1]];
+; SM80-PTX70-NEXT: abs.f64 [[RD4:%rd[0-9]+]], [[RD3]];
+; SM80-PTX70-NEXT: setp.gt.f64 [[P1:%p[0-9]+]], [[RD2]], [[RD4]];
+; SM80-PTX70-NEXT: selp.b32 [[R2:%r[0-9]+]], 1, -1, [[P1]];
+; SM80-PTX70-NEXT: add.s32 [[R3:%r[0-9]+]], [[R1]], [[R2]];
+; SM80-PTX70-NEXT: and.b32 [[R4:%r[0-9]+]], [[R1]], 1;
+; SM80-PTX70-NEXT: setp.ne.b32 [[P2:%p[0-9]+]], [[R4]], 0;
+; SM80-PTX70-NEXT: selp.b32 [[R5:%r[0-9]+]], [[R1]], [[R3]], [[P2]];
+; SM80-PTX70-NEXT: setp.equ.f64 [[P3:%p[0-9]+]], [[RD1]], [[RD3]];
+; SM80-PTX70-NEXT: selp.b32 [[R6:%r[0-9]+]], [[R1]], [[R5]], [[P3]];
+; SM80-PTX70-NEXT: cvt.rn.bf16.f32 [[RS1:%rs[0-9]+]], [[R6]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RS1]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rn_bf16_f64(
+; SM80: ld.param.b64 [[RD1:%rd[0-9]+]], [fptrunc_rn_bf16_f64_param_0];
+; SM80-NEXT: abs.f64 [[RD2:%rd[0-9]+]], [[RD1]];
+; SM80-NOFTZ-NEXT: cvt.rn.f32.f64 [[R1:%r[0-9]+]], [[RD1]];
+; SM80-NOFTZ-NEXT: cvt.f64.f32 [[RD3:%rd[0-9]+]], [[R1]];
+; SM80-FTZ-NEXT: cvt.rn.ftz.f32.f64 [[R1:%r[0-9]+]], [[RD1]];
+; SM80-FTZ-NEXT: cvt.ftz.f64.f32 [[RD3:%rd[0-9]+]], [[R1]];
+; SM80-NEXT: abs.f64 [[RD4:%rd[0-9]+]], [[RD3]];
+; SM80-NEXT: setp.gt.f64 [[P1:%p[0-9]+]], [[RD2]], [[RD4]];
+; SM80-NEXT: selp.b32 [[R2:%r[0-9]+]], 1, -1, [[P1]];
+; SM80-NEXT: add.s32 [[R3:%r[0-9]+]], [[R1]], [[R2]];
+; SM80-NEXT: and.b32 [[R4:%r[0-9]+]], [[R1]], 1;
+; SM80-NEXT: setp.ne.b32 [[P2:%p[0-9]+]], [[R4]], 0;
+; SM80-NEXT: selp.b32 [[R5:%r[0-9]+]], [[R1]], [[R3]], [[P2]];
+; SM80-NEXT: setp.equ.f64 [[P3:%p[0-9]+]], [[RD1]], [[RD3]];
+; SM80-NEXT: selp.b32 [[R6:%r[0-9]+]], [[R1]], [[R5]], [[P3]];
+; SM80-NEXT: cvt.rn.bf16.f32 [[RS1:%rs[0-9]+]], [[R6]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RS1]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rn_bf16_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_bf16_f64_param_0];
+; SM90-NEXT: cvt.rn.bf16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call bfloat @llvm.fptrunc.round.bf16.f64(double %a, metadata !"round.tonearest")
+ ret bfloat %res
+}
+
+;--- sm80.ll
+
+define bfloat @cvt_rz_bf16_f16(half %a) {
+; SM70-ERR: error: {{.*}}in function cvt_rz_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.towardzero requires sm_80 or higher
+;
+; SM80-PTX70-LABEL: cvt_rz_bf16_f16(
+; SM80-PTX70: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_bf16_f16_param_0];
+; SM80-PTX70-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: cvt.rz.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: cvt_rz_bf16_f16(
+; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_bf16_f16_param_0];
+; SM80-NOFTZ-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-FTZ-NEXT: cvt.ftz.f32.f16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rz.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: cvt_rz_bf16_f16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_bf16_f16_param_0];
+; SM90-NEXT: cvt.rz.bf16.f16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext half %a to float
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %ext, metadata !"round.towardzero")
+ ret bfloat %res
+}
+
+define bfloat @fptrunc_rz_bf16_f32(float %a) {
+; SM70-ERR: error: {{.*}}in function fptrunc_rz_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.towardzero requires sm_80 or higher
+;
+; SM80-PTX70-LABEL: fptrunc_rz_bf16_f32(
+; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_bf16_f32_param_0];
+; SM80-PTX70-NEXT: cvt.rz.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-PTX70-NEXT: ret;
+;
+; SM80-LABEL: fptrunc_rz_bf16_f32(
+; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_bf16_f32_param_0];
+; SM80-NEXT: cvt.rz.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
+;
+; SM90-LABEL: fptrunc_rz_bf16_f32(
+; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_bf16_f32_param_0];
+; SM90-NEXT: cvt.rz.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %a, metadata !"round.towardzero")
+ ret bfloat %res
+}
+
+;--- sm90.ll
+define bfloat @cvt_rm_bf16_f16(half %a) {
+; SM70-ERR: error: {{.*}}in function cvt_rm_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.downward requires sm_90 or higher
+; SM80-ERR: error: {{.*}}in function cvt_rm_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.downward requires sm_90 or higher
+;
+; SM90-LABEL: cvt_rm_bf16_f16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rm_bf16_f16_param_0];
+; SM90-NEXT: cvt.rm.bf16.f16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext half %a to float
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %ext, metadata !"round.downward")
+ ret bfloat %res
+}
+
+define bfloat @cvt_rp_bf16_f16(half %a) {
+; SM70-ERR: error: {{.*}}in function cvt_rp_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.upward requires sm_90 or higher
+; SM80-ERR: error: {{.*}}in function cvt_rp_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.upward requires sm_90 or higher
+;
+; SM90-LABEL: cvt_rp_bf16_f16(
+; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rp_bf16_f16_param_0];
+; SM90-NEXT: cvt.rp.bf16.f16 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %ext = fpext half %a to float
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %ext, metadata !"round.upward")
+ ret bfloat %res
+}
+
+define bfloat @fptrunc_rm_bf16_f32(float %a) {
+; SM70-ERR: error: {{.*}}in function fptrunc_rm_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.downward requires sm_90 or higher
+; SM80-ERR: error: {{.*}}in function fptrunc_rm_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.downward requires sm_90 or higher
+;
+; SM90-LABEL: fptrunc_rm_bf16_f32(
+; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rm_bf16_f32_param_0];
+; SM90-NEXT: cvt.rm.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %a, metadata !"round.downward")
+ ret bfloat %res
+}
+
+define bfloat @fptrunc_rp_bf16_f32(float %a) {
+; SM70-ERR: error: {{.*}}in function fptrunc_rp_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.upward requires sm_90 or higher
+; SM80-ERR: error: {{.*}}in function fptrunc_rp_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.upward requires sm_90 or higher
+;
+; SM90-LABEL: fptrunc_rp_bf16_f32(
+; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rp_bf16_f32_param_0];
+; SM90-NEXT: cvt.rp.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %a, metadata !"round.upward")
+ ret bfloat %res
+}
+
+define bfloat @fptrunc_rz_bf16_f64(double %a) {
+; SM70-ERR: error: {{.*}}in function fptrunc_rz_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.towardzero requires sm_90 or higher
+; SM80-ERR: error: {{.*}}in function fptrunc_rz_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.towardzero requires sm_90 or higher
+;
+; SM90-LABEL: fptrunc_rz_bf16_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_bf16_f64_param_0];
+; SM90-NEXT: cvt.rz.bf16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call bfloat @llvm.fptrunc.round.bf16.f64(double %a, metadata !"round.towardzero")
+ ret bfloat %res
+}
+
+define bfloat @fptrunc_rm_bf16_f64(double %a) {
+; SM70-ERR: error: {{.*}}in function fptrunc_rm_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.downward requires sm_90 or higher
+; SM80-ERR: error: {{.*}}in function fptrunc_rm_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.downward requires sm_90 or higher
+;
+; SM90-LABEL: fptrunc_rm_bf16_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_bf16_f64_param_0];
+; SM90-NEXT: cvt.rm.bf16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call bfloat @llvm.fptrunc.round.bf16.f64(double %a, metadata !"round.downward")
+ ret bfloat %res
+}
+
+define bfloat @fptrunc_rp_bf16_f64(double %a) {
+; SM70-ERR: error: {{.*}}in function fptrunc_rp_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.upward requires sm_90 or higher
+; SM80-ERR: error: {{.*}}in function fptrunc_rp_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.upward requires sm_90 or higher
+;
+; SM90-LABEL: fptrunc_rp_bf16_f64(
+; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_bf16_f64_param_0];
+; SM90-NEXT: cvt.rp.bf16.f64 [[RES:%rs[0-9]+]], [[A]];
+; SM90-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM90-NEXT: ret;
+ %res = call bfloat @llvm.fptrunc.round.bf16.f64(double %a, metadata !"round.upward")
+ ret bfloat %res
+}
+
+;--- unsupported-rounding.ll
+declare half @llvm.fptrunc.round.f16.f32(float, metadata)
+declare bfloat @llvm.fptrunc.round.bf16.f32(float, metadata)
+declare float @llvm.fptrunc.round.f32.f64(double, metadata)
+
+define half @fptrunc_rna_f16_f32(float %a) {
+; ROUND-ERR: error: {{.*}}in function fptrunc_rna_f16_f32{{.*}}llvm.fptrunc.round from f32 to f16 with rounding mode round.tonearestaway is not supported on this target
+ %res = call half @llvm.fptrunc.round.f16.f32(float %a, metadata !"round.tonearestaway")
+ ret half %res
+}
+
+define bfloat @fptrunc_rna_bf16_f32(float %a) {
+; ROUND-ERR: error: {{.*}}in function fptrunc_rna_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.tonearestaway is not supported on this target
+ %res = call bfloat @llvm.fptrunc.round.bf16.f32(float %a, metadata !"round.tonearestaway")
+ ret bfloat %res
+}
+
+define float @fptrunc_rna_f32_f64(double %a) {
+; ROUND-ERR: error: {{.*}}in function fptrunc_rna_f32_f64{{.*}}llvm.fptrunc.round from f64 to f32 with rounding mode round.tonearestaway is not supported on this target
+ %res = call float @llvm.fptrunc.round.f32.f64(double %a, metadata !"round.tonearestaway")
+ ret float %res
+}
>From 57d074ff38c09cf0aabdc33f0bbcb340e34558e7 Mon Sep 17 00:00:00 2001
From: Peter Bell <peterbell10 at openai.com>
Date: Tue, 15 Sep 2026 15:49:52 +0100
Subject: [PATCH 2/4] Lint
---
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index 8e3b8e209892e..27e6f2150a921 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -993,7 +993,8 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
}
// Expand nearest-even rounding and diagnose unsupported conversions.
- setOperationAction(ISD::FPTRUNC_ROUND, {MVT::f16, MVT::bf16, MVT::f32}, Custom);
+ setOperationAction(ISD::FPTRUNC_ROUND, {MVT::f16, MVT::bf16, MVT::f32},
+ Custom);
// Expand v2f32 = fp_extend
setOperationAction(ISD::FP_EXTEND, MVT::v2f32, Expand);
@@ -2435,7 +2436,7 @@ SDValue NVPTXTargetLowering::LowerFP_ROUND(SDValue Op,
}
SDValue NVPTXTargetLowering::LowerFPTRUNC_ROUND(SDValue Op,
- SelectionDAG &DAG) const {
+ SelectionDAG &DAG) const {
EVT SrcVT = Op.getOperand(0).getValueType();
EVT DstVT = Op.getValueType();
auto RM = static_cast<RoundingMode>(Op.getConstantOperandVal(1));
@@ -2447,8 +2448,8 @@ SDValue NVPTXTargetLowering::LowerFPTRUNC_ROUND(SDValue Op,
Op.getNode()->getFlags());
}
- bool RoundToInfinity = RM == RoundingMode::TowardNegative ||
- RM == RoundingMode::TowardPositive;
+ bool RoundToInfinity =
+ RM == RoundingMode::TowardNegative || RM == RoundingMode::TowardPositive;
StringRef Error;
if (RM != RoundingMode::TowardZero && !RoundToInfinity) {
>From 1f247fbf165b81c4318066ec5259a66626a1ae7e Mon Sep 17 00:00:00 2001
From: Peter Bell <peterbell10 at openai.com>
Date: Tue, 15 Sep 2026 15:54:19 +0100
Subject: [PATCH 3/4] Remove explicit PTX70 checks when it makes no difference
---
.../CodeGen/NVPTX/convert-fptrunc-round.ll | 214 +++---------------
1 file changed, 33 insertions(+), 181 deletions(-)
diff --git a/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll b/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
index 37ae9153a2ae3..54c40b7bff6b0 100644
--- a/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
+++ b/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
@@ -6,11 +6,11 @@
; RUN: %if ptxas-sm_70 && ptxas-isa-7.1 %{ llc < %t/common.ll -mtriple=nvptx64 -mcpu=sm_70 -mattr=+ptx71 | %ptxas-verify -arch=sm_70 %}
; RUN: llc < %t/common.ll -mtriple=nvptx64 -mcpu=sm_70 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | FileCheck --check-prefixes=SM70,SM70-FTZ %s
; RUN: %if ptxas-sm_70 && ptxas-isa-7.1 %{ llc < %t/common.ll -mtriple=nvptx64 -mcpu=sm_70 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | %ptxas-verify -arch=sm_70 %}
-; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | FileCheck --check-prefix=SM80-PTX70 %s
+; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | FileCheck --check-prefixes=SM80,SM80-NOFTZ,SM80-PTX70 %s
; RUN: %if ptxas-sm_80 && ptxas-isa-7.0 %{ llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | %ptxas-verify -arch=sm_80 %}
-; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 | FileCheck --check-prefixes=SM80,SM80-NOFTZ %s
+; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 | FileCheck --check-prefixes=SM80,SM80-NOFTZ,SM80-PTX71 %s
; RUN: %if ptxas-sm_80 && ptxas-isa-7.1 %{ llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 | %ptxas-verify -arch=sm_80 %}
-; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | FileCheck --check-prefixes=SM80,SM80-FTZ %s
+; RUN: llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | FileCheck --check-prefixes=SM80,SM80-FTZ,SM80-PTX71 %s
; RUN: %if ptxas-sm_80 && ptxas-isa-7.1 %{ llc < %t/all-sm80.ll -mtriple=nvptx64 -mcpu=sm_80 -mattr=+ptx71 -denormal-fp-math-f32=preserve-sign | %ptxas-verify -arch=sm_80 %}
; RUN: llc < %t/all-sm90.ll -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx78 | FileCheck --check-prefixes=SM90,SM90-NOFTZ %s
; RUN: %if ptxas-sm_90 && ptxas-isa-7.8 %{ llc < %t/all-sm90.ll -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx78 | %ptxas-verify -arch=sm_90 %}
@@ -36,18 +36,13 @@ define half @cvt_f16_bf16(bfloat %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: cvt_f16_bf16(
+; SM80-LABEL: cvt_f16_bf16(
; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
-; SM80-PTX70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
-; SM80-LABEL: cvt_f16_bf16(
-; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_f16_bf16_param_0];
-; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
-; SM80-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-NEXT: ret;
+; SM80-PTX71: ld.param.b16 [[A:%rs[0-9]+]], [cvt_f16_bf16_param_0];
+; SM80-PTX71-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
;
; SM90-LABEL: cvt_f16_bf16(
; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_f16_bf16_param_0];
@@ -68,13 +63,6 @@ define bfloat @cvt_bf16_f16(half %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: cvt_bf16_f16(
-; SM80-PTX70: ld.param.b16 [[A:%rs[0-9]+]], [cvt_bf16_f16_param_0];
-; SM80-PTX70-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: cvt_bf16_f16(
; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_bf16_f16_param_0];
; SM80-NOFTZ-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
@@ -101,18 +89,13 @@ define half @cvt_rn_f16_bf16(bfloat %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: cvt_rn_f16_bf16(
+; SM80-LABEL: cvt_rn_f16_bf16(
; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
-; SM80-PTX70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
-; SM80-LABEL: cvt_rn_f16_bf16(
-; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_f16_bf16_param_0];
-; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
-; SM80-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-NEXT: ret;
+; SM80-PTX71: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_f16_bf16_param_0];
+; SM80-PTX71-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
;
; SM90-LABEL: cvt_rn_f16_bf16(
; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_f16_bf16_param_0];
@@ -132,18 +115,13 @@ define half @cvt_rz_f16_bf16(bfloat %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: cvt_rz_f16_bf16(
+; SM80-LABEL: cvt_rz_f16_bf16(
; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
-; SM80-PTX70-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
-; SM80-LABEL: cvt_rz_f16_bf16(
-; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_f16_bf16_param_0];
-; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
-; SM80-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-NEXT: ret;
+; SM80-PTX71: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_f16_bf16_param_0];
+; SM80-PTX71-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
;
; SM90-LABEL: cvt_rz_f16_bf16(
; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_f16_bf16_param_0];
@@ -163,18 +141,13 @@ define half @cvt_rm_f16_bf16(bfloat %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: cvt_rm_f16_bf16(
+; SM80-LABEL: cvt_rm_f16_bf16(
; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
-; SM80-PTX70-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
-; SM80-LABEL: cvt_rm_f16_bf16(
-; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rm_f16_bf16_param_0];
-; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
-; SM80-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-NEXT: ret;
+; SM80-PTX71: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rm_f16_bf16_param_0];
+; SM80-PTX71-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
;
; SM90-LABEL: cvt_rm_f16_bf16(
; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rm_f16_bf16_param_0];
@@ -196,18 +169,13 @@ define half @cvt_rp_f16_bf16(bfloat %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: cvt_rp_f16_bf16(
+; SM80-LABEL: cvt_rp_f16_bf16(
; SM80-PTX70: shl.b32 [[EXT:%r[0-9]+]], {{%r[0-9]+}}, 16;
-; SM80-PTX70-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
-; SM80-LABEL: cvt_rp_f16_bf16(
-; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rp_f16_bf16_param_0];
-; SM80-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
-; SM80-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-NEXT: ret;
+; SM80-PTX71: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rp_f16_bf16_param_0];
+; SM80-PTX71-NEXT: cvt.f32.bf16 [[EXT:%r[0-9]+]], [[A]];
+; SM80-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[EXT]];
+; SM80-NEXT: st.param.b16 [func_retval0], [[RES]];
+; SM80-NEXT: ret;
;
; SM90-LABEL: cvt_rp_f16_bf16(
; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rp_f16_bf16_param_0];
@@ -228,12 +196,6 @@ define half @fptrunc_rn_f16_f32(float %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rn_f16_f32(
-; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_f16_f32_param_0];
-; SM80-PTX70-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rn_f16_f32(
; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_f16_f32_param_0];
; SM80-NEXT: cvt.rn.f16.f32 [[RES:%rs[0-9]+]], [[A]];
@@ -256,12 +218,6 @@ define half @fptrunc_rz_f16_f32(float %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rz_f16_f32(
-; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_f16_f32_param_0];
-; SM80-PTX70-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rz_f16_f32(
; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_f16_f32_param_0];
; SM80-NEXT: cvt.rz.f16.f32 [[RES:%rs[0-9]+]], [[A]];
@@ -284,12 +240,6 @@ define half @fptrunc_rm_f16_f32(float %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rm_f16_f32(
-; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rm_f16_f32_param_0];
-; SM80-PTX70-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rm_f16_f32(
; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rm_f16_f32_param_0];
; SM80-NEXT: cvt.rm.f16.f32 [[RES:%rs[0-9]+]], [[A]];
@@ -312,12 +262,6 @@ define half @fptrunc_rp_f16_f32(float %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rp_f16_f32(
-; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rp_f16_f32_param_0];
-; SM80-PTX70-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rp_f16_f32(
; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rp_f16_f32_param_0];
; SM80-NEXT: cvt.rp.f16.f32 [[RES:%rs[0-9]+]], [[A]];
@@ -340,12 +284,6 @@ define half @fptrunc_rn_f16_f64(double %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rn_f16_f64(
-; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f16_f64_param_0];
-; SM80-PTX70-NEXT: cvt.rn.f16.f64 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rn_f16_f64(
; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f16_f64_param_0];
; SM80-NEXT: cvt.rn.f16.f64 [[RES:%rs[0-9]+]], [[A]];
@@ -368,12 +306,6 @@ define half @fptrunc_rz_f16_f64(double %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rz_f16_f64(
-; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f16_f64_param_0];
-; SM80-PTX70-NEXT: cvt.rz.f16.f64 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rz_f16_f64(
; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f16_f64_param_0];
; SM80-NEXT: cvt.rz.f16.f64 [[RES:%rs[0-9]+]], [[A]];
@@ -396,12 +328,6 @@ define half @fptrunc_rm_f16_f64(double %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rm_f16_f64(
-; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f16_f64_param_0];
-; SM80-PTX70-NEXT: cvt.rm.f16.f64 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rm_f16_f64(
; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f16_f64_param_0];
; SM80-NEXT: cvt.rm.f16.f64 [[RES:%rs[0-9]+]], [[A]];
@@ -424,12 +350,6 @@ define half @fptrunc_rp_f16_f64(double %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rp_f16_f64(
-; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f16_f64_param_0];
-; SM80-PTX70-NEXT: cvt.rp.f16.f64 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rp_f16_f64(
; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f16_f64_param_0];
; SM80-NEXT: cvt.rp.f16.f64 [[RES:%rs[0-9]+]], [[A]];
@@ -453,12 +373,6 @@ define float @fptrunc_rn_f32_f64(double %a) {
; SM70-NEXT: st.param.b32 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rn_f32_f64(
-; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f32_f64_param_0];
-; SM80-PTX70-NEXT: cvt.rn.f32.f64 [[RES:%r[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b32 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rn_f32_f64(
; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rn_f32_f64_param_0];
; SM80-NOFTZ-NEXT: cvt.rn.f32.f64 [[RES:%r[0-9]+]], [[A]];
@@ -484,12 +398,6 @@ define float @fptrunc_rz_f32_f64(double %a) {
; SM70-NEXT: st.param.b32 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rz_f32_f64(
-; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f32_f64_param_0];
-; SM80-PTX70-NEXT: cvt.rz.f32.f64 [[RES:%r[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b32 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rz_f32_f64(
; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_f32_f64_param_0];
; SM80-NOFTZ-NEXT: cvt.rz.f32.f64 [[RES:%r[0-9]+]], [[A]];
@@ -515,12 +423,6 @@ define float @fptrunc_rm_f32_f64(double %a) {
; SM70-NEXT: st.param.b32 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rm_f32_f64(
-; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f32_f64_param_0];
-; SM80-PTX70-NEXT: cvt.rm.f32.f64 [[RES:%r[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b32 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rm_f32_f64(
; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_f32_f64_param_0];
; SM80-NOFTZ-NEXT: cvt.rm.f32.f64 [[RES:%r[0-9]+]], [[A]];
@@ -546,12 +448,6 @@ define float @fptrunc_rp_f32_f64(double %a) {
; SM70-NEXT: st.param.b32 [func_retval0], [[RES]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rp_f32_f64(
-; SM80-PTX70: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f32_f64_param_0];
-; SM80-PTX70-NEXT: cvt.rp.f32.f64 [[RES:%r[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b32 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rp_f32_f64(
; SM80: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_f32_f64_param_0];
; SM80-NOFTZ-NEXT: cvt.rp.f32.f64 [[RES:%r[0-9]+]], [[A]];
@@ -585,13 +481,6 @@ define bfloat @cvt_rn_bf16_f16(half %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[R7]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: cvt_rn_bf16_f16(
-; SM80-PTX70: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_bf16_f16_param_0];
-; SM80-PTX70-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: cvt_rn_bf16_f16(
; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rn_bf16_f16_param_0];
; SM80-NOFTZ-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
@@ -624,12 +513,6 @@ define bfloat @fptrunc_rn_bf16_f32(float %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[R7]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rn_bf16_f32(
-; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_bf16_f32_param_0];
-; SM80-PTX70-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rn_bf16_f32(
; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rn_bf16_f32_param_0];
; SM80-NEXT: cvt.rn.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
@@ -672,24 +555,6 @@ define bfloat @fptrunc_rn_bf16_f64(double %a) {
; SM70-NEXT: st.param.b16 [func_retval0], [[R12]];
; SM70-NEXT: ret;
;
-; SM80-PTX70-LABEL: fptrunc_rn_bf16_f64(
-; SM80-PTX70: ld.param.b64 [[RD1:%rd[0-9]+]], [fptrunc_rn_bf16_f64_param_0];
-; SM80-PTX70-NEXT: abs.f64 [[RD2:%rd[0-9]+]], [[RD1]];
-; SM80-PTX70-NEXT: cvt.rn.f32.f64 [[R1:%r[0-9]+]], [[RD1]];
-; SM80-PTX70-NEXT: cvt.f64.f32 [[RD3:%rd[0-9]+]], [[R1]];
-; SM80-PTX70-NEXT: abs.f64 [[RD4:%rd[0-9]+]], [[RD3]];
-; SM80-PTX70-NEXT: setp.gt.f64 [[P1:%p[0-9]+]], [[RD2]], [[RD4]];
-; SM80-PTX70-NEXT: selp.b32 [[R2:%r[0-9]+]], 1, -1, [[P1]];
-; SM80-PTX70-NEXT: add.s32 [[R3:%r[0-9]+]], [[R1]], [[R2]];
-; SM80-PTX70-NEXT: and.b32 [[R4:%r[0-9]+]], [[R1]], 1;
-; SM80-PTX70-NEXT: setp.ne.b32 [[P2:%p[0-9]+]], [[R4]], 0;
-; SM80-PTX70-NEXT: selp.b32 [[R5:%r[0-9]+]], [[R1]], [[R3]], [[P2]];
-; SM80-PTX70-NEXT: setp.equ.f64 [[P3:%p[0-9]+]], [[RD1]], [[RD3]];
-; SM80-PTX70-NEXT: selp.b32 [[R6:%r[0-9]+]], [[R1]], [[R5]], [[P3]];
-; SM80-PTX70-NEXT: cvt.rn.bf16.f32 [[RS1:%rs[0-9]+]], [[R6]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RS1]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rn_bf16_f64(
; SM80: ld.param.b64 [[RD1:%rd[0-9]+]], [fptrunc_rn_bf16_f64_param_0];
; SM80-NEXT: abs.f64 [[RD2:%rd[0-9]+]], [[RD1]];
@@ -724,13 +589,6 @@ define bfloat @fptrunc_rn_bf16_f64(double %a) {
define bfloat @cvt_rz_bf16_f16(half %a) {
; SM70-ERR: error: {{.*}}in function cvt_rz_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.towardzero requires sm_80 or higher
;
-; SM80-PTX70-LABEL: cvt_rz_bf16_f16(
-; SM80-PTX70: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_bf16_f16_param_0];
-; SM80-PTX70-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: cvt.rz.bf16.f32 [[RES:%rs[0-9]+]], [[EXT]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: cvt_rz_bf16_f16(
; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_bf16_f16_param_0];
; SM80-NOFTZ-NEXT: cvt.f32.f16 [[EXT:%r[0-9]+]], [[A]];
@@ -752,12 +610,6 @@ define bfloat @cvt_rz_bf16_f16(half %a) {
define bfloat @fptrunc_rz_bf16_f32(float %a) {
; SM70-ERR: error: {{.*}}in function fptrunc_rz_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.towardzero requires sm_80 or higher
;
-; SM80-PTX70-LABEL: fptrunc_rz_bf16_f32(
-; SM80-PTX70: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_bf16_f32_param_0];
-; SM80-PTX70-NEXT: cvt.rz.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
-; SM80-PTX70-NEXT: st.param.b16 [func_retval0], [[RES]];
-; SM80-PTX70-NEXT: ret;
-;
; SM80-LABEL: fptrunc_rz_bf16_f32(
; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_bf16_f32_param_0];
; SM80-NEXT: cvt.rz.bf16.f32 [[RES:%rs[0-9]+]], [[A]];
>From 85d58aae0733eded78c6cf9b3b49e92b303a57a7 Mon Sep 17 00:00:00 2001
From: Peter Bell <peterbell10 at openai.com>
Date: Mon, 5 Oct 2026 17:12:33 +0100
Subject: [PATCH 4/4] Address review feedback
---
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 28 ++++++--------
llvm/lib/Target/NVPTX/NVPTXISelLowering.h | 1 -
.../CodeGen/NVPTX/convert-fptrunc-round.ll | 38 +++++++++----------
3 files changed, 30 insertions(+), 37 deletions(-)
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index 27e6f2150a921..6c503051aee4d 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -2435,8 +2435,8 @@ SDValue NVPTXTargetLowering::LowerFP_ROUND(SDValue Op,
return Op;
}
-SDValue NVPTXTargetLowering::LowerFPTRUNC_ROUND(SDValue Op,
- SelectionDAG &DAG) const {
+static SDValue lowerFPTRUNC_ROUND(SDValue Op, SelectionDAG &DAG,
+ const NVPTXSubtarget &STI) {
EVT SrcVT = Op.getOperand(0).getValueType();
EVT DstVT = Op.getValueType();
auto RM = static_cast<RoundingMode>(Op.getConstantOperandVal(1));
@@ -2451,26 +2451,20 @@ SDValue NVPTXTargetLowering::LowerFPTRUNC_ROUND(SDValue Op,
bool RoundToInfinity =
RM == RoundingMode::TowardNegative || RM == RoundingMode::TowardPositive;
- StringRef Error;
- if (RM != RoundingMode::TowardZero && !RoundToInfinity) {
- Error = "is not supported on this target";
- } else if (DstVT == MVT::bf16) {
- if (SrcVT == MVT::f64 || RoundToInfinity) {
- if (!STI.hasFeature(NVPTX::SM90))
- Error = "requires sm_90 or higher";
- } else if (!STI.hasFeature(NVPTX::SM80)) {
- Error = "requires sm_80 or higher";
- }
+ bool Supported = RM == RoundingMode::TowardZero || RoundToInfinity;
+ if (DstVT == MVT::bf16) {
+ if (SrcVT == MVT::f64 || RoundToInfinity)
+ Supported &= STI.hasFeature(NVPTX::SM90);
+ else
+ Supported &= STI.hasFeature(NVPTX::SM80);
}
- if (Error.empty())
+ if (Supported)
return Op;
DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
DAG.getMachineFunction().getFunction(),
- Twine("llvm.fptrunc.round from ") + SrcVT.getEVTString() + " to " +
- DstVT.getEVTString() + " with rounding mode " +
- *convertRoundingModeToStr(RM) + " " + Error,
+ "unsupported conversion or rounding mode for llvm.fptrunc.round",
SDLoc(Op).getDebugLoc()));
return DAG.getPOISON(DstVT);
}
@@ -3559,7 +3553,7 @@ NVPTXTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
case ISD::FP_ROUND:
return LowerFP_ROUND(Op, DAG);
case ISD::FPTRUNC_ROUND:
- return LowerFPTRUNC_ROUND(Op, DAG);
+ return lowerFPTRUNC_ROUND(Op, DAG, STI);
case ISD::FP_EXTEND:
return LowerFP_EXTEND(Op, DAG);
case ISD::VAARG:
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.h b/llvm/lib/Target/NVPTX/NVPTXISelLowering.h
index 53a65fc898c44..4942408f6449b 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.h
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.h
@@ -209,7 +209,6 @@ class NVPTXTargetLowering : public TargetLowering {
SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
- SDValue LowerFPTRUNC_ROUND(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
diff --git a/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll b/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
index 54c40b7bff6b0..2166e5288a549 100644
--- a/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
+++ b/llvm/test/CodeGen/NVPTX/convert-fptrunc-round.ll
@@ -587,7 +587,7 @@ define bfloat @fptrunc_rn_bf16_f64(double %a) {
;--- sm80.ll
define bfloat @cvt_rz_bf16_f16(half %a) {
-; SM70-ERR: error: {{.*}}in function cvt_rz_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.towardzero requires sm_80 or higher
+; SM70-ERR: error: {{.*}}in function cvt_rz_bf16_f16{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM80-LABEL: cvt_rz_bf16_f16(
; SM80: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rz_bf16_f16_param_0];
@@ -608,7 +608,7 @@ define bfloat @cvt_rz_bf16_f16(half %a) {
}
define bfloat @fptrunc_rz_bf16_f32(float %a) {
-; SM70-ERR: error: {{.*}}in function fptrunc_rz_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.towardzero requires sm_80 or higher
+; SM70-ERR: error: {{.*}}in function fptrunc_rz_bf16_f32{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM80-LABEL: fptrunc_rz_bf16_f32(
; SM80: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rz_bf16_f32_param_0];
@@ -627,8 +627,8 @@ define bfloat @fptrunc_rz_bf16_f32(float %a) {
;--- sm90.ll
define bfloat @cvt_rm_bf16_f16(half %a) {
-; SM70-ERR: error: {{.*}}in function cvt_rm_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.downward requires sm_90 or higher
-; SM80-ERR: error: {{.*}}in function cvt_rm_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.downward requires sm_90 or higher
+; SM70-ERR: error: {{.*}}in function cvt_rm_bf16_f16{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
+; SM80-ERR: error: {{.*}}in function cvt_rm_bf16_f16{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM90-LABEL: cvt_rm_bf16_f16(
; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rm_bf16_f16_param_0];
@@ -641,8 +641,8 @@ define bfloat @cvt_rm_bf16_f16(half %a) {
}
define bfloat @cvt_rp_bf16_f16(half %a) {
-; SM70-ERR: error: {{.*}}in function cvt_rp_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.upward requires sm_90 or higher
-; SM80-ERR: error: {{.*}}in function cvt_rp_bf16_f16{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.upward requires sm_90 or higher
+; SM70-ERR: error: {{.*}}in function cvt_rp_bf16_f16{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
+; SM80-ERR: error: {{.*}}in function cvt_rp_bf16_f16{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM90-LABEL: cvt_rp_bf16_f16(
; SM90: ld.param.b16 [[A:%rs[0-9]+]], [cvt_rp_bf16_f16_param_0];
@@ -655,8 +655,8 @@ define bfloat @cvt_rp_bf16_f16(half %a) {
}
define bfloat @fptrunc_rm_bf16_f32(float %a) {
-; SM70-ERR: error: {{.*}}in function fptrunc_rm_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.downward requires sm_90 or higher
-; SM80-ERR: error: {{.*}}in function fptrunc_rm_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.downward requires sm_90 or higher
+; SM70-ERR: error: {{.*}}in function fptrunc_rm_bf16_f32{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
+; SM80-ERR: error: {{.*}}in function fptrunc_rm_bf16_f32{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM90-LABEL: fptrunc_rm_bf16_f32(
; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rm_bf16_f32_param_0];
@@ -668,8 +668,8 @@ define bfloat @fptrunc_rm_bf16_f32(float %a) {
}
define bfloat @fptrunc_rp_bf16_f32(float %a) {
-; SM70-ERR: error: {{.*}}in function fptrunc_rp_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.upward requires sm_90 or higher
-; SM80-ERR: error: {{.*}}in function fptrunc_rp_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.upward requires sm_90 or higher
+; SM70-ERR: error: {{.*}}in function fptrunc_rp_bf16_f32{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
+; SM80-ERR: error: {{.*}}in function fptrunc_rp_bf16_f32{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM90-LABEL: fptrunc_rp_bf16_f32(
; SM90: ld.param.b32 [[A:%r[0-9]+]], [fptrunc_rp_bf16_f32_param_0];
@@ -681,8 +681,8 @@ define bfloat @fptrunc_rp_bf16_f32(float %a) {
}
define bfloat @fptrunc_rz_bf16_f64(double %a) {
-; SM70-ERR: error: {{.*}}in function fptrunc_rz_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.towardzero requires sm_90 or higher
-; SM80-ERR: error: {{.*}}in function fptrunc_rz_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.towardzero requires sm_90 or higher
+; SM70-ERR: error: {{.*}}in function fptrunc_rz_bf16_f64{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
+; SM80-ERR: error: {{.*}}in function fptrunc_rz_bf16_f64{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM90-LABEL: fptrunc_rz_bf16_f64(
; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rz_bf16_f64_param_0];
@@ -694,8 +694,8 @@ define bfloat @fptrunc_rz_bf16_f64(double %a) {
}
define bfloat @fptrunc_rm_bf16_f64(double %a) {
-; SM70-ERR: error: {{.*}}in function fptrunc_rm_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.downward requires sm_90 or higher
-; SM80-ERR: error: {{.*}}in function fptrunc_rm_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.downward requires sm_90 or higher
+; SM70-ERR: error: {{.*}}in function fptrunc_rm_bf16_f64{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
+; SM80-ERR: error: {{.*}}in function fptrunc_rm_bf16_f64{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM90-LABEL: fptrunc_rm_bf16_f64(
; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rm_bf16_f64_param_0];
@@ -707,8 +707,8 @@ define bfloat @fptrunc_rm_bf16_f64(double %a) {
}
define bfloat @fptrunc_rp_bf16_f64(double %a) {
-; SM70-ERR: error: {{.*}}in function fptrunc_rp_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.upward requires sm_90 or higher
-; SM80-ERR: error: {{.*}}in function fptrunc_rp_bf16_f64{{.*}}llvm.fptrunc.round from f64 to bf16 with rounding mode round.upward requires sm_90 or higher
+; SM70-ERR: error: {{.*}}in function fptrunc_rp_bf16_f64{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
+; SM80-ERR: error: {{.*}}in function fptrunc_rp_bf16_f64{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
;
; SM90-LABEL: fptrunc_rp_bf16_f64(
; SM90: ld.param.b64 [[A:%rd[0-9]+]], [fptrunc_rp_bf16_f64_param_0];
@@ -725,19 +725,19 @@ declare bfloat @llvm.fptrunc.round.bf16.f32(float, metadata)
declare float @llvm.fptrunc.round.f32.f64(double, metadata)
define half @fptrunc_rna_f16_f32(float %a) {
-; ROUND-ERR: error: {{.*}}in function fptrunc_rna_f16_f32{{.*}}llvm.fptrunc.round from f32 to f16 with rounding mode round.tonearestaway is not supported on this target
+; ROUND-ERR: error: {{.*}}in function fptrunc_rna_f16_f32{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
%res = call half @llvm.fptrunc.round.f16.f32(float %a, metadata !"round.tonearestaway")
ret half %res
}
define bfloat @fptrunc_rna_bf16_f32(float %a) {
-; ROUND-ERR: error: {{.*}}in function fptrunc_rna_bf16_f32{{.*}}llvm.fptrunc.round from f32 to bf16 with rounding mode round.tonearestaway is not supported on this target
+; ROUND-ERR: error: {{.*}}in function fptrunc_rna_bf16_f32{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
%res = call bfloat @llvm.fptrunc.round.bf16.f32(float %a, metadata !"round.tonearestaway")
ret bfloat %res
}
define float @fptrunc_rna_f32_f64(double %a) {
-; ROUND-ERR: error: {{.*}}in function fptrunc_rna_f32_f64{{.*}}llvm.fptrunc.round from f64 to f32 with rounding mode round.tonearestaway is not supported on this target
+; ROUND-ERR: error: {{.*}}in function fptrunc_rna_f32_f64{{.*}}unsupported conversion or rounding mode for llvm.fptrunc.round
%res = call float @llvm.fptrunc.round.f32.f64(double %a, metadata !"round.tonearestaway")
ret float %res
}
More information about the llvm-commits
mailing list