From d0969e485c16bf8415c87b6d0375a88e738c9679 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 10 Mar 2022 17:56:17 -0800 Subject: [PATCH] [RISCV] Optimize vfmv.s.f intrinsic with scalar 0.0 to vmv.s.x with x0. We already do this for RISCVISD::VFMV_S_F_VL and the vfmv.v.f intrinsic. Reviewed By: kito-cheng Differential Revision: https://reviews.llvm.org/D121429 --- llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td | 5 + llvm/test/CodeGen/RISCV/rvv/vfmv.s.f.ll | 165 ++++++++++++++++++++++++ 2 files changed, 170 insertions(+) diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td index 8fa833c..3c8ed92 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td @@ -5413,6 +5413,11 @@ foreach fvti = AllFloatVectors in { (fvti.Vector $rs1), (fvti.Scalar fvti.ScalarRegClass:$rs2), GPR:$vl, fvti.Log2SEW)>; + + def : Pat<(fvti.Vector (int_riscv_vfmv_s_f (fvti.Vector fvti.RegClass:$rs1), + (fvti.Scalar (fpimm0)), VLOpFrag)), + (!cast("PseudoVMV_S_X_" # fvti.LMul.MX) + (fvti.Vector $rs1), X0, GPR:$vl, fvti.Log2SEW)>; } } // Predicates = [HasVInstructionsAnyF] diff --git a/llvm/test/CodeGen/RISCV/rvv/vfmv.s.f.ll b/llvm/test/CodeGen/RISCV/rvv/vfmv.s.f.ll index 8464dc2..4e03c5c 100644 --- a/llvm/test/CodeGen/RISCV/rvv/vfmv.s.f.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vfmv.s.f.ll @@ -198,3 +198,168 @@ entry: %a = call @llvm.riscv.vfmv.s.f.nxv8f64( %0, double %1, iXLen %2) ret %a } + +define @intrinsic_vfmv.s.f_f_zero_nxv1f16( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv1f16: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e16, mf4, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv1f16( %0, half 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv2f16( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv2f16: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e16, mf2, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv2f16( %0, half 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv4f16( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv4f16: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e16, m1, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv4f16( %0, half 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv8f16( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv8f16: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e16, m2, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv8f16( %0, half 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv16f16( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv16f16: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e16, m4, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv16f16( %0, half 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv32f16( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv32f16: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e16, m8, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv32f16( %0, half 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv1f32( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv1f32: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e32, mf2, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv1f32( %0, float 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv2f32( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv2f32: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e32, m1, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv2f32( %0, float 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv4f32( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv4f32: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e32, m2, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv4f32( %0, float 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv8f32( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv8f32: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e32, m4, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv8f32( %0, float 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv16f32( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv16f32: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e32, m8, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv16f32( %0, float 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv1f64( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv1f64: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e64, m1, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv1f64( %0, double 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv2f64( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv2f64: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e64, m2, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv2f64( %0, double 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv4f64( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv4f64: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e64, m4, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv4f64( %0, double 0.0, iXLen %1) + ret %a +} + +define @intrinsic_vfmv.s.f_f_zero_nxv8f64( %0, iXLen %1) nounwind { +; CHECK-LABEL: intrinsic_vfmv.s.f_f_zero_nxv8f64: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: vsetvli zero, a0, e64, m8, tu, mu +; CHECK-NEXT: vmv.s.x v8, zero +; CHECK-NEXT: ret +entry: + %a = call @llvm.riscv.vfmv.s.f.nxv8f64( %0, double 0.0, iXLen %1) + ret %a +} -- 2.7.4