diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td @@ -585,9 +585,14 @@ fvti.AVL, fvti.SEW)>; } -// 14.10. Vector Floating-Point Sign-Injection Instructions -// Handle fneg with VFSGNJN using the same input for both operands. foreach vti = AllFloatVectors in { + // 14.8. Vector Floating-Point Square-Root Instruction + def : Pat<(fsqrt (vti.Vector vti.RegClass:$rs2)), + (!cast("PseudoVFSQRT_V_"# vti.LMul.MX) + vti.RegClass:$rs2, vti.AVL, vti.SEW)>; + + // 14.10. Vector Floating-Point Sign-Injection Instructions + // Handle fneg with VFSGNJN using the same input for both operands. def : Pat<(fneg (vti.Vector vti.RegClass:$rs)), (!cast("PseudoVFSGNJN_VV_"# vti.LMul.MX) vti.RegClass:$rs, vti.RegClass:$rs, vti.AVL, vti.SEW)>; diff --git a/llvm/test/CodeGen/RISCV/rvv/vfsqrt-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/vfsqrt-sdnode.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/vfsqrt-sdnode.ll @@ -0,0 +1,185 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv32 -mattr=+d,+experimental-zfh,+experimental-v -target-abi=ilp32d \ +; RUN: -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=+d,+experimental-zfh,+experimental-v -target-abi=lp64d \ +; RUN: -verify-machineinstrs < %s | FileCheck %s + +declare @llvm.sqrt.nxv1f16() + +define @vfsqrt_nxv1f16( %v) { +; CHECK-LABEL: vfsqrt_nxv1f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e16,mf4,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv1f16( %v) + ret %r +} + +declare @llvm.sqrt.nxv2f16() + +define @vfsqrt_nxv2f16( %v) { +; CHECK-LABEL: vfsqrt_nxv2f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e16,mf2,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv2f16( %v) + ret %r +} + +declare @llvm.sqrt.nxv4f16() + +define @vfsqrt_nxv4f16( %v) { +; CHECK-LABEL: vfsqrt_nxv4f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e16,m1,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv4f16( %v) + ret %r +} + +declare @llvm.sqrt.nxv8f16() + +define @vfsqrt_nxv8f16( %v) { +; CHECK-LABEL: vfsqrt_nxv8f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e16,m2,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv8f16( %v) + ret %r +} + +declare @llvm.sqrt.nxv16f16() + +define @vfsqrt_nxv16f16( %v) { +; CHECK-LABEL: vfsqrt_nxv16f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e16,m4,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv16f16( %v) + ret %r +} + +declare @llvm.sqrt.nxv32f16() + +define @vfsqrt_nxv32f16( %v) { +; CHECK-LABEL: vfsqrt_nxv32f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e16,m8,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv32f16( %v) + ret %r +} + +declare @llvm.sqrt.nxv1f32() + +define @vfsqrt_nxv1f32( %v) { +; CHECK-LABEL: vfsqrt_nxv1f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32,mf2,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv1f32( %v) + ret %r +} + +declare @llvm.sqrt.nxv2f32() + +define @vfsqrt_nxv2f32( %v) { +; CHECK-LABEL: vfsqrt_nxv2f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32,m1,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv2f32( %v) + ret %r +} + +declare @llvm.sqrt.nxv4f32() + +define @vfsqrt_nxv4f32( %v) { +; CHECK-LABEL: vfsqrt_nxv4f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32,m2,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv4f32( %v) + ret %r +} + +declare @llvm.sqrt.nxv8f32() + +define @vfsqrt_nxv8f32( %v) { +; CHECK-LABEL: vfsqrt_nxv8f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32,m4,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv8f32( %v) + ret %r +} + +declare @llvm.sqrt.nxv16f32() + +define @vfsqrt_nxv16f32( %v) { +; CHECK-LABEL: vfsqrt_nxv16f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32,m8,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv16f32( %v) + ret %r +} + +declare @llvm.sqrt.nxv1f64() + +define @vfsqrt_nxv1f64( %v) { +; CHECK-LABEL: vfsqrt_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e64,m1,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv1f64( %v) + ret %r +} + +declare @llvm.sqrt.nxv2f64() + +define @vfsqrt_nxv2f64( %v) { +; CHECK-LABEL: vfsqrt_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e64,m2,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv2f64( %v) + ret %r +} + +declare @llvm.sqrt.nxv4f64() + +define @vfsqrt_nxv4f64( %v) { +; CHECK-LABEL: vfsqrt_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e64,m4,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv4f64( %v) + ret %r +} + +declare @llvm.sqrt.nxv8f64() + +define @vfsqrt_nxv8f64( %v) { +; CHECK-LABEL: vfsqrt_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e64,m8,ta,mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %r = call @llvm.sqrt.nxv8f64( %v) + ret %r +}