diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -1631,6 +1631,7 @@ case ISD::VP_SETCC: case ISD::SETCC: Res = PromoteIntOp_SETCC(N, OpNo); break; case ISD::SIGN_EXTEND: Res = PromoteIntOp_SIGN_EXTEND(N); break; + case ISD::VP_SITOFP: case ISD::SINT_TO_FP: Res = PromoteIntOp_SINT_TO_FP(N); break; case ISD::STRICT_SINT_TO_FP: Res = PromoteIntOp_STRICT_SINT_TO_FP(N); break; case ISD::STORE: Res = PromoteIntOp_STORE(cast(N), @@ -1646,6 +1647,7 @@ case ISD::VP_TRUNCATE: case ISD::TRUNCATE: Res = PromoteIntOp_TRUNCATE(N); break; case ISD::FP16_TO_FP: + case ISD::VP_UITOFP: case ISD::UINT_TO_FP: Res = PromoteIntOp_UINT_TO_FP(N); break; case ISD::STRICT_UINT_TO_FP: Res = PromoteIntOp_STRICT_UINT_TO_FP(N); break; case ISD::ZERO_EXTEND: Res = PromoteIntOp_ZERO_EXTEND(N); break; @@ -1977,6 +1979,11 @@ } SDValue DAGTypeLegalizer::PromoteIntOp_SINT_TO_FP(SDNode *N) { + if (N->getOpcode() == ISD::VP_SITOFP) + return SDValue(DAG.UpdateNodeOperands(N, + SExtPromotedInteger(N->getOperand(0)), + N->getOperand(1), N->getOperand(2)), + 0); return SDValue(DAG.UpdateNodeOperands(N, SExtPromotedInteger(N->getOperand(0))), 0); } @@ -2101,6 +2108,11 @@ } SDValue DAGTypeLegalizer::PromoteIntOp_UINT_TO_FP(SDNode *N) { + if (N->getOpcode() == ISD::VP_UITOFP) + return SDValue(DAG.UpdateNodeOperands(N, + SExtPromotedInteger(N->getOperand(0)), + N->getOperand(1), N->getOperand(2)), + 0); return SDValue(DAG.UpdateNodeOperands(N, ZExtPromotedInteger(N->getOperand(0))), 0); } diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-i2fp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-i2fp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-i2fp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-i2fp.ll @@ -44,6 +44,34 @@ ret <2 x float> %z } +define <2 x float> @si2fp_v2i7_v2f32(<2 x i7> %x) { +; CHECK-LABEL: si2fp_v2i7_v2f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetivli zero, 2, e8, mf8, ta, mu +; CHECK-NEXT: vadd.vv v8, v8, v8 +; CHECK-NEXT: vsra.vi v8, v8, 1 +; CHECK-NEXT: vsetvli zero, zero, e32, mf2, ta, mu +; CHECK-NEXT: vsext.vf4 v9, v8 +; CHECK-NEXT: vfcvt.f.x.v v8, v9 +; CHECK-NEXT: ret + %z = sitofp <2 x i7> %x to <2 x float> + ret <2 x float> %z +} + +define <2 x float> @ui2fp_v2i7_v2f32(<2 x i7> %x) { +; CHECK-LABEL: ui2fp_v2i7_v2f32: +; CHECK: # %bb.0: +; CHECK-NEXT: li a0, 127 +; CHECK-NEXT: vsetivli zero, 2, e8, mf8, ta, mu +; CHECK-NEXT: vand.vx v8, v8, a0 +; CHECK-NEXT: vsetvli zero, zero, e32, mf2, ta, mu +; CHECK-NEXT: vzext.vf4 v9, v8 +; CHECK-NEXT: vfcvt.f.xu.v v8, v9 +; CHECK-NEXT: ret + %z = uitofp <2 x i7> %x to <2 x float> + ret <2 x float> %z +} + define <2 x float> @ui2fp_v2i1_v2f32(<2 x i1> %x) { ; CHECK-LABEL: ui2fp_v2i1_v2f32: ; CHECK: # %bb.0: diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-sitofp-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-sitofp-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-sitofp-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-sitofp-vp.ll @@ -4,6 +4,21 @@ ; RUN: llc -mtriple=riscv64 -mattr=+m,+v,+zfh,+experimental-zvfh \ ; RUN: -riscv-v-vector-bits-min=128 < %s | FileCheck %s +declare <4 x half> @llvm.vp.sitofp.v4f16.v4i7(<4 x i7>, <4 x i1>, i32) + +define <4 x half> @vsitofp_v4f16_v4i7(<4 x i7> %va, <4 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vsitofp_v4f16_v4i7: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, mu +; CHECK-NEXT: vadd.vv v8, v8, v8 +; CHECK-NEXT: vsra.vi v9, v8, 1 +; CHECK-NEXT: vsetvli zero, a0, e8, mf4, ta, mu +; CHECK-NEXT: vfwcvt.f.x.v v8, v9, v0.t +; CHECK-NEXT: ret + %v = call <4 x half> @llvm.vp.sitofp.v4f16.v4i7(<4 x i7> %va, <4 x i1> %m, i32 %evl) + ret <4 x half> %v +} + declare <4 x half> @llvm.vp.sitofp.v4f16.v4i8(<4 x i8>, <4 x i1>, i32) define <4 x half> @vsitofp_v4f16_v4i8(<4 x i8> %va, <4 x i1> %m, i32 zeroext %evl) { diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-uitofp-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-uitofp-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-uitofp-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-uitofp-vp.ll @@ -4,6 +4,21 @@ ; RUN: llc -mtriple=riscv64 -mattr=+m,+v,+zfh,+experimental-zvfh \ ; RUN: -riscv-v-vector-bits-min=128 < %s | FileCheck %s +declare <4 x half> @llvm.vp.uitofp.v4f16.v4i7(<4 x i7>, <4 x i1>, i32) + +define <4 x half> @vuitofp_v4f16_v4i7(<4 x i7> %va, <4 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vuitofp_v4f16_v4i7: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, mu +; CHECK-NEXT: vadd.vv v8, v8, v8 +; CHECK-NEXT: vsra.vi v9, v8, 1 +; CHECK-NEXT: vsetvli zero, a0, e8, mf4, ta, mu +; CHECK-NEXT: vfwcvt.f.xu.v v8, v9, v0.t +; CHECK-NEXT: ret + %v = call <4 x half> @llvm.vp.uitofp.v4f16.v4i7(<4 x i7> %va, <4 x i1> %m, i32 %evl) + ret <4 x half> %v +} + declare <4 x half> @llvm.vp.uitofp.v4f16.v4i8(<4 x i8>, <4 x i1>, i32) define <4 x half> @vuitofp_v4f16_v4i8(<4 x i8> %va, <4 x i1> %m, i32 zeroext %evl) { diff --git a/llvm/test/CodeGen/RISCV/rvv/vitofp-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/vitofp-sdnode.ll --- a/llvm/test/CodeGen/RISCV/rvv/vitofp-sdnode.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vitofp-sdnode.ll @@ -375,6 +375,30 @@ ret %evec } +define @vsitofp_nxv1i7_nxv1f16( %va) { +; CHECK-LABEL: vsitofp_nxv1i7_nxv1f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e8, mf8, ta, mu +; CHECK-NEXT: vadd.vv v8, v8, v8 +; CHECK-NEXT: vsra.vi v9, v8, 1 +; CHECK-NEXT: vfwcvt.f.x.v v8, v9 +; CHECK-NEXT: ret + %evec = sitofp %va to + ret %evec +} + +define @vuitofp_nxv1i7_nxv1f16( %va) { +; CHECK-LABEL: vuitofp_nxv1i7_nxv1f16: +; CHECK: # %bb.0: +; CHECK-NEXT: li a0, 127 +; CHECK-NEXT: vsetvli a1, zero, e8, mf8, ta, mu +; CHECK-NEXT: vand.vx v9, v8, a0 +; CHECK-NEXT: vfwcvt.f.xu.v v8, v9 +; CHECK-NEXT: ret + %evec = uitofp %va to + ret %evec +} + define @vuitofp_nxv1i8_nxv1f16( %va) { ; CHECK-LABEL: vuitofp_nxv1i8_nxv1f16: ; CHECK: # %bb.0: diff --git a/llvm/test/CodeGen/RISCV/rvv/vsitofp-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vsitofp-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/vsitofp-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vsitofp-vp.ll @@ -2,6 +2,21 @@ ; RUN: llc -mtriple=riscv32 -mattr=+m,+v,+zfh,+experimental-zvfh < %s | FileCheck %s ; RUN: llc -mtriple=riscv64 -mattr=+m,+v,+zfh,+experimental-zvfh < %s | FileCheck %s +declare @llvm.vp.sitofp.nxv2f16.nxv2i7(, , i32) + +define @vsitofp_nxv2f16_nxv2i7( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vsitofp_nxv2f16_nxv2i7: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e8, mf4, ta, mu +; CHECK-NEXT: vadd.vv v8, v8, v8 +; CHECK-NEXT: vsra.vi v9, v8, 1 +; CHECK-NEXT: vsetvli zero, a0, e8, mf4, ta, mu +; CHECK-NEXT: vfwcvt.f.x.v v8, v9, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sitofp.nxv2f16.nxv2i7( %va, %m, i32 %evl) + ret %v +} + declare @llvm.vp.sitofp.nxv2f16.nxv2i8(, , i32) define @vsitofp_nxv2f16_nxv2i8( %va, %m, i32 zeroext %evl) { diff --git a/llvm/test/CodeGen/RISCV/rvv/vuitofp-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vuitofp-vp.ll --- a/llvm/test/CodeGen/RISCV/rvv/vuitofp-vp.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vuitofp-vp.ll @@ -2,6 +2,21 @@ ; RUN: llc -mtriple=riscv32 -mattr=+m,+v,+zfh,+experimental-zvfh < %s | FileCheck %s ; RUN: llc -mtriple=riscv64 -mattr=+m,+v,+zfh,+experimental-zvfh < %s | FileCheck %s +declare @llvm.vp.uitofp.nxv2f16.nxv2i7(, , i32) + +define @vuitofp_nxv2f16_nxv2i7( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vuitofp_nxv2f16_nxv2i7: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e8, mf4, ta, mu +; CHECK-NEXT: vadd.vv v8, v8, v8 +; CHECK-NEXT: vsra.vi v9, v8, 1 +; CHECK-NEXT: vsetvli zero, a0, e8, mf4, ta, mu +; CHECK-NEXT: vfwcvt.f.xu.v v8, v9, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.uitofp.nxv2f16.nxv2i7( %va, %m, i32 %evl) + ret %v +} + declare @llvm.vp.uitofp.nxv2f16.nxv2i8(, , i32) define @vuitofp_nxv2f16_nxv2i8( %va, %m, i32 zeroext %evl) {