diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -14047,6 +14047,8 @@ '``llvm.memset.*``', but the generated code is guaranteed not to call any external functions. +.. _int_sqrt: + '``llvm.sqrt.*``' Intrinsic ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19182,6 +19184,54 @@ %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef +.. _int_vp_sqrt: + +'``llvm.vp.sqrt.*``' Intrinsics +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Syntax: +""""""" +This is an overloaded intrinsic. + +:: + + declare <16 x float> @llvm.vp.sqrt.v16f32 (<16 x float> , <16 x i1> , i32 ) + declare @llvm.vp.sqrt.nxv4f32 ( , , i32 ) + declare <256 x double> @llvm.vp.sqrt.v256f64 (<256 x double> , <256 x i1> , i32 ) + +Overview: +""""""""" + +Predicated floating-point square root of a vector of floating-point values. + + +Arguments: +"""""""""" + +The first operand and the result have the same vector of floating-point type. +The second operand is the vector mask and has the same number of elements as the +result vector type. The third operand is the explicit vector length of the +operation. + +Semantics: +"""""""""" + +The '``llvm.vp.sqrt``' intrinsic performs floating-point absolute value +(:ref:`sqrt `) of the first vector operand on each enabled lane. The +result on disabled lanes is undefined. + +Examples: +""""""""" + +.. code-block:: llvm + + %r = call <4 x float> @llvm.vp.sqrt.v4f32(<4 x float> %a, <4 x i1> %mask, i32 %evl) + ;; For all lanes below %evl, %r is lane-wise equivalent to %also.r + + %t = call <4 x float> @llvm.sqrt.v4f32(<4 x float> %a) + %also.r = select <4 x i1> %mask, <4 x float> %t, <4 x float> undef + + .. _int_vp_fma: '``llvm.vp.fma.*``' Intrinsics diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td --- a/llvm/include/llvm/IR/Intrinsics.td +++ b/llvm/include/llvm/IR/Intrinsics.td @@ -1565,6 +1565,10 @@ [ LLVMMatchType<0>, LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_i32_ty]>; + def int_vp_sqrt : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ], + [ LLVMMatchType<0>, + LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, + llvm_i32_ty]>; def int_vp_fma : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ], [ LLVMMatchType<0>, LLVMMatchType<0>, diff --git a/llvm/include/llvm/IR/VPIntrinsics.def b/llvm/include/llvm/IR/VPIntrinsics.def --- a/llvm/include/llvm/IR/VPIntrinsics.def +++ b/llvm/include/llvm/IR/VPIntrinsics.def @@ -239,6 +239,10 @@ BEGIN_REGISTER_VP(vp_fabs, 1, 2, VP_FABS, -1) END_REGISTER_VP(vp_fabs, VP_FABS) +// llvm.vp.sqrt(x,mask,vlen) +BEGIN_REGISTER_VP(vp_sqrt, 1, 2, VP_SQRT, -1) +END_REGISTER_VP(vp_sqrt, VP_SQRT) + // llvm.vp.fma(x,y,z,mask,vlen) BEGIN_REGISTER_VP(vp_fma, 3, 4, VP_FMA, -1) VP_PROPERTY_CONSTRAINEDFP(1, 1, experimental_constrained_fma) diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -1043,7 +1043,7 @@ case ISD::FROUND: case ISD::FROUNDEVEN: case ISD::FSIN: - case ISD::FSQRT: + case ISD::FSQRT: case ISD::VP_SQRT: case ISD::FTRUNC: case ISD::SINT_TO_FP: case ISD::VP_SINT_TO_FP: @@ -4083,6 +4083,7 @@ case ISD::CTTZ_ZERO_UNDEF: case ISD::FNEG: case ISD::VP_FNEG: case ISD::VP_FABS: + case ISD::VP_SQRT: case ISD::FREEZE: case ISD::ARITH_FENCE: case ISD::FCANONICALIZE: diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -462,7 +462,8 @@ ISD::VP_FMA, ISD::VP_REDUCE_FADD, ISD::VP_REDUCE_SEQ_FADD, ISD::VP_REDUCE_FMIN, ISD::VP_REDUCE_FMAX, ISD::VP_MERGE, ISD::VP_SELECT, ISD::VP_SINT_TO_FP, ISD::VP_UINT_TO_FP, - ISD::VP_SETCC, ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}; + ISD::VP_SETCC, ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND, + ISD::VP_SQRT}; static const unsigned IntegerVecReduceOps[] = { ISD::VECREDUCE_ADD, ISD::VECREDUCE_AND, ISD::VECREDUCE_OR, @@ -3709,6 +3710,8 @@ return lowerVPOp(Op, DAG, RISCVISD::FNEG_VL); case ISD::VP_FABS: return lowerVPOp(Op, DAG, RISCVISD::FABS_VL); + case ISD::VP_SQRT: + return lowerVPOp(Op, DAG, RISCVISD::FSQRT_VL); case ISD::VP_FMA: return lowerVPOp(Op, DAG, RISCVISD::VFMADD_VL); case ISD::VP_SIGN_EXTEND: diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td @@ -1363,10 +1363,11 @@ foreach vti = AllFloatVectors in { // 14.8. Vector Floating-Point Square-Root Instruction - def : Pat<(riscv_fsqrt_vl (vti.Vector vti.RegClass:$rs2), (vti.Mask true_mask), + def : Pat<(riscv_fsqrt_vl (vti.Vector vti.RegClass:$rs2), (vti.Mask V0), VLOpFrag), - (!cast("PseudoVFSQRT_V_"# vti.LMul.MX) - vti.RegClass:$rs2, GPR:$vl, vti.Log2SEW)>; + (!cast("PseudoVFSQRT_V_"# vti.LMul.MX #"_MASK") + (vti.Vector (IMPLICIT_DEF)), vti.RegClass:$rs2, + (vti.Mask V0), GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>; // 14.12. Vector Floating-Point Sign-Injection Instructions def : Pat<(riscv_fabs_vl (vti.Vector vti.RegClass:$rs), (vti.Mask V0), diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfsqrt-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfsqrt-vp.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfsqrt-vp.ll @@ -0,0 +1,371 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv32 -mattr=+d,+zfh,+experimental-zvfh,+v -target-abi=ilp32d -riscv-v-vector-bits-min=128 \ +; RUN: -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=+d,+zfh,+experimental-zvfh,+v -target-abi=lp64d -riscv-v-vector-bits-min=128 \ +; RUN: -verify-machineinstrs < %s | FileCheck %s + +declare <2 x half> @llvm.vp.sqrt.v2f16(<2 x half>, <2 x i1>, i32) + +define <2 x half> @vfsqrt_vv_v2f16(<2 x half> %va, <2 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v2f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, mf4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <2 x half> @llvm.vp.sqrt.v2f16(<2 x half> %va, <2 x i1> %m, i32 %evl) + ret <2 x half> %v +} + +define <2 x half> @vfsqrt_vv_v2f16_unmasked(<2 x half> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v2f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, mf4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <2 x i1> poison, i1 true, i32 0 + %m = shufflevector <2 x i1> %head, <2 x i1> poison, <2 x i32> zeroinitializer + %v = call <2 x half> @llvm.vp.sqrt.v2f16(<2 x half> %va, <2 x i1> %m, i32 %evl) + ret <2 x half> %v +} + +declare <4 x half> @llvm.vp.sqrt.v4f16(<4 x half>, <4 x i1>, i32) + +define <4 x half> @vfsqrt_vv_v4f16(<4 x half> %va, <4 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v4f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, mf2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <4 x half> @llvm.vp.sqrt.v4f16(<4 x half> %va, <4 x i1> %m, i32 %evl) + ret <4 x half> %v +} + +define <4 x half> @vfsqrt_vv_v4f16_unmasked(<4 x half> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v4f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, mf2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <4 x i1> poison, i1 true, i32 0 + %m = shufflevector <4 x i1> %head, <4 x i1> poison, <4 x i32> zeroinitializer + %v = call <4 x half> @llvm.vp.sqrt.v4f16(<4 x half> %va, <4 x i1> %m, i32 %evl) + ret <4 x half> %v +} + +declare <8 x half> @llvm.vp.sqrt.v8f16(<8 x half>, <8 x i1>, i32) + +define <8 x half> @vfsqrt_vv_v8f16(<8 x half> %va, <8 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v8f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <8 x half> @llvm.vp.sqrt.v8f16(<8 x half> %va, <8 x i1> %m, i32 %evl) + ret <8 x half> %v +} + +define <8 x half> @vfsqrt_vv_v8f16_unmasked(<8 x half> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v8f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <8 x i1> poison, i1 true, i32 0 + %m = shufflevector <8 x i1> %head, <8 x i1> poison, <8 x i32> zeroinitializer + %v = call <8 x half> @llvm.vp.sqrt.v8f16(<8 x half> %va, <8 x i1> %m, i32 %evl) + ret <8 x half> %v +} + +declare <16 x half> @llvm.vp.sqrt.v16f16(<16 x half>, <16 x i1>, i32) + +define <16 x half> @vfsqrt_vv_v16f16(<16 x half> %va, <16 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v16f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <16 x half> @llvm.vp.sqrt.v16f16(<16 x half> %va, <16 x i1> %m, i32 %evl) + ret <16 x half> %v +} + +define <16 x half> @vfsqrt_vv_v16f16_unmasked(<16 x half> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v16f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <16 x i1> poison, i1 true, i32 0 + %m = shufflevector <16 x i1> %head, <16 x i1> poison, <16 x i32> zeroinitializer + %v = call <16 x half> @llvm.vp.sqrt.v16f16(<16 x half> %va, <16 x i1> %m, i32 %evl) + ret <16 x half> %v +} + +declare <2 x float> @llvm.vp.sqrt.v2f32(<2 x float>, <2 x i1>, i32) + +define <2 x float> @vfsqrt_vv_v2f32(<2 x float> %va, <2 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v2f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, mf2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <2 x float> @llvm.vp.sqrt.v2f32(<2 x float> %va, <2 x i1> %m, i32 %evl) + ret <2 x float> %v +} + +define <2 x float> @vfsqrt_vv_v2f32_unmasked(<2 x float> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v2f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, mf2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <2 x i1> poison, i1 true, i32 0 + %m = shufflevector <2 x i1> %head, <2 x i1> poison, <2 x i32> zeroinitializer + %v = call <2 x float> @llvm.vp.sqrt.v2f32(<2 x float> %va, <2 x i1> %m, i32 %evl) + ret <2 x float> %v +} + +declare <4 x float> @llvm.vp.sqrt.v4f32(<4 x float>, <4 x i1>, i32) + +define <4 x float> @vfsqrt_vv_v4f32(<4 x float> %va, <4 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v4f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <4 x float> @llvm.vp.sqrt.v4f32(<4 x float> %va, <4 x i1> %m, i32 %evl) + ret <4 x float> %v +} + +define <4 x float> @vfsqrt_vv_v4f32_unmasked(<4 x float> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v4f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <4 x i1> poison, i1 true, i32 0 + %m = shufflevector <4 x i1> %head, <4 x i1> poison, <4 x i32> zeroinitializer + %v = call <4 x float> @llvm.vp.sqrt.v4f32(<4 x float> %va, <4 x i1> %m, i32 %evl) + ret <4 x float> %v +} + +declare <8 x float> @llvm.vp.sqrt.v8f32(<8 x float>, <8 x i1>, i32) + +define <8 x float> @vfsqrt_vv_v8f32(<8 x float> %va, <8 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v8f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <8 x float> @llvm.vp.sqrt.v8f32(<8 x float> %va, <8 x i1> %m, i32 %evl) + ret <8 x float> %v +} + +define <8 x float> @vfsqrt_vv_v8f32_unmasked(<8 x float> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v8f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <8 x i1> poison, i1 true, i32 0 + %m = shufflevector <8 x i1> %head, <8 x i1> poison, <8 x i32> zeroinitializer + %v = call <8 x float> @llvm.vp.sqrt.v8f32(<8 x float> %va, <8 x i1> %m, i32 %evl) + ret <8 x float> %v +} + +declare <16 x float> @llvm.vp.sqrt.v16f32(<16 x float>, <16 x i1>, i32) + +define <16 x float> @vfsqrt_vv_v16f32(<16 x float> %va, <16 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v16f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <16 x float> @llvm.vp.sqrt.v16f32(<16 x float> %va, <16 x i1> %m, i32 %evl) + ret <16 x float> %v +} + +define <16 x float> @vfsqrt_vv_v16f32_unmasked(<16 x float> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v16f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <16 x i1> poison, i1 true, i32 0 + %m = shufflevector <16 x i1> %head, <16 x i1> poison, <16 x i32> zeroinitializer + %v = call <16 x float> @llvm.vp.sqrt.v16f32(<16 x float> %va, <16 x i1> %m, i32 %evl) + ret <16 x float> %v +} + +declare <2 x double> @llvm.vp.sqrt.v2f64(<2 x double>, <2 x i1>, i32) + +define <2 x double> @vfsqrt_vv_v2f64(<2 x double> %va, <2 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <2 x double> @llvm.vp.sqrt.v2f64(<2 x double> %va, <2 x i1> %m, i32 %evl) + ret <2 x double> %v +} + +define <2 x double> @vfsqrt_vv_v2f64_unmasked(<2 x double> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v2f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <2 x i1> poison, i1 true, i32 0 + %m = shufflevector <2 x i1> %head, <2 x i1> poison, <2 x i32> zeroinitializer + %v = call <2 x double> @llvm.vp.sqrt.v2f64(<2 x double> %va, <2 x i1> %m, i32 %evl) + ret <2 x double> %v +} + +declare <4 x double> @llvm.vp.sqrt.v4f64(<4 x double>, <4 x i1>, i32) + +define <4 x double> @vfsqrt_vv_v4f64(<4 x double> %va, <4 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <4 x double> @llvm.vp.sqrt.v4f64(<4 x double> %va, <4 x i1> %m, i32 %evl) + ret <4 x double> %v +} + +define <4 x double> @vfsqrt_vv_v4f64_unmasked(<4 x double> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v4f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <4 x i1> poison, i1 true, i32 0 + %m = shufflevector <4 x i1> %head, <4 x i1> poison, <4 x i32> zeroinitializer + %v = call <4 x double> @llvm.vp.sqrt.v4f64(<4 x double> %va, <4 x i1> %m, i32 %evl) + ret <4 x double> %v +} + +declare <8 x double> @llvm.vp.sqrt.v8f64(<8 x double>, <8 x i1>, i32) + +define <8 x double> @vfsqrt_vv_v8f64(<8 x double> %va, <8 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <8 x double> @llvm.vp.sqrt.v8f64(<8 x double> %va, <8 x i1> %m, i32 %evl) + ret <8 x double> %v +} + +define <8 x double> @vfsqrt_vv_v8f64_unmasked(<8 x double> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v8f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <8 x i1> poison, i1 true, i32 0 + %m = shufflevector <8 x i1> %head, <8 x i1> poison, <8 x i32> zeroinitializer + %v = call <8 x double> @llvm.vp.sqrt.v8f64(<8 x double> %va, <8 x i1> %m, i32 %evl) + ret <8 x double> %v +} + +declare <15 x double> @llvm.vp.sqrt.v15f64(<15 x double>, <15 x i1>, i32) + +define <15 x double> @vfsqrt_vv_v15f64(<15 x double> %va, <15 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v15f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <15 x double> @llvm.vp.sqrt.v15f64(<15 x double> %va, <15 x i1> %m, i32 %evl) + ret <15 x double> %v +} + +define <15 x double> @vfsqrt_vv_v15f64_unmasked(<15 x double> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v15f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <15 x i1> poison, i1 true, i32 0 + %m = shufflevector <15 x i1> %head, <15 x i1> poison, <15 x i32> zeroinitializer + %v = call <15 x double> @llvm.vp.sqrt.v15f64(<15 x double> %va, <15 x i1> %m, i32 %evl) + ret <15 x double> %v +} + +declare <16 x double> @llvm.vp.sqrt.v16f64(<16 x double>, <16 x i1>, i32) + +define <16 x double> @vfsqrt_vv_v16f64(<16 x double> %va, <16 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v16f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <16 x double> @llvm.vp.sqrt.v16f64(<16 x double> %va, <16 x i1> %m, i32 %evl) + ret <16 x double> %v +} + +define <16 x double> @vfsqrt_vv_v16f64_unmasked(<16 x double> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v16f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <16 x i1> poison, i1 true, i32 0 + %m = shufflevector <16 x i1> %head, <16 x i1> poison, <16 x i32> zeroinitializer + %v = call <16 x double> @llvm.vp.sqrt.v16f64(<16 x double> %va, <16 x i1> %m, i32 %evl) + ret <16 x double> %v +} + +declare <32 x double> @llvm.vp.sqrt.v32f64(<32 x double>, <32 x i1>, i32) + +define <32 x double> @vfsqrt_vv_v32f64(<32 x double> %va, <32 x i1> %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v32f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vmv1r.v v24, v0 +; CHECK-NEXT: li a1, 0 +; CHECK-NEXT: vsetivli zero, 2, e8, mf4, ta, mu +; CHECK-NEXT: addi a2, a0, -16 +; CHECK-NEXT: vslidedown.vi v0, v0, 2 +; CHECK-NEXT: bltu a0, a2, .LBB26_2 +; CHECK-NEXT: # %bb.1: +; CHECK-NEXT: mv a1, a2 +; CHECK-NEXT: .LBB26_2: +; CHECK-NEXT: vsetvli zero, a1, e64, m8, ta, mu +; CHECK-NEXT: li a1, 16 +; CHECK-NEXT: vfsqrt.v v16, v16, v0.t +; CHECK-NEXT: bltu a0, a1, .LBB26_4 +; CHECK-NEXT: # %bb.3: +; CHECK-NEXT: li a0, 16 +; CHECK-NEXT: .LBB26_4: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vmv1r.v v0, v24 +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call <32 x double> @llvm.vp.sqrt.v32f64(<32 x double> %va, <32 x i1> %m, i32 %evl) + ret <32 x double> %v +} + +define <32 x double> @vfsqrt_vv_v32f64_unmasked(<32 x double> %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_v32f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: addi a1, a0, -16 +; CHECK-NEXT: li a2, 0 +; CHECK-NEXT: bltu a0, a1, .LBB27_2 +; CHECK-NEXT: # %bb.1: +; CHECK-NEXT: mv a2, a1 +; CHECK-NEXT: .LBB27_2: +; CHECK-NEXT: vsetvli zero, a2, e64, m8, ta, mu +; CHECK-NEXT: li a1, 16 +; CHECK-NEXT: vfsqrt.v v16, v16 +; CHECK-NEXT: bltu a0, a1, .LBB27_4 +; CHECK-NEXT: # %bb.3: +; CHECK-NEXT: li a0, 16 +; CHECK-NEXT: .LBB27_4: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement <32 x i1> poison, i1 true, i32 0 + %m = shufflevector <32 x i1> %head, <32 x i1> poison, <32 x i32> zeroinitializer + %v = call <32 x double> @llvm.vp.sqrt.v32f64(<32 x double> %va, <32 x i1> %m, i32 %evl) + ret <32 x double> %v +} diff --git a/llvm/test/CodeGen/RISCV/rvv/vfsqrt-vp.ll b/llvm/test/CodeGen/RISCV/rvv/vfsqrt-vp.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/vfsqrt-vp.ll @@ -0,0 +1,446 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv32 -mattr=+d,+zfh,+experimental-zvfh,+v -target-abi=ilp32d \ +; RUN: -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=+d,+zfh,+experimental-zvfh,+v -target-abi=lp64d \ +; RUN: -verify-machineinstrs < %s | FileCheck %s + +declare @llvm.vp.sqrt.nxv1f16(, , i32) + +define @vfsqrt_vv_nxv1f16( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv1f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, mf4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv1f16( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv1f16_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv1f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, mf4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv1f16( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv2f16(, , i32) + +define @vfsqrt_vv_nxv2f16( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv2f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, mf2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv2f16( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv2f16_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv2f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, mf2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv2f16( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv4f16(, , i32) + +define @vfsqrt_vv_nxv4f16( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv4f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv4f16( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv4f16_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv4f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv4f16( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv8f16(, , i32) + +define @vfsqrt_vv_nxv8f16( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv8f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv8f16( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv8f16_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv8f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv8f16( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv16f16(, , i32) + +define @vfsqrt_vv_nxv16f16( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv16f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv16f16( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv16f16_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv16f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv16f16( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv32f16(, , i32) + +define @vfsqrt_vv_nxv32f16( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv32f16: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv32f16( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv32f16_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv32f16_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e16, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv32f16( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv1f32(, , i32) + +define @vfsqrt_vv_nxv1f32( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv1f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, mf2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv1f32( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv1f32_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv1f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, mf2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv1f32( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv2f32(, , i32) + +define @vfsqrt_vv_nxv2f32( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv2f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv2f32( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv2f32_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv2f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv2f32( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv4f32(, , i32) + +define @vfsqrt_vv_nxv4f32( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv4f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv4f32( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv4f32_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv4f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv4f32( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv8f32(, , i32) + +define @vfsqrt_vv_nxv8f32( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv8f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv8f32( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv8f32_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv8f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv8f32( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv16f32(, , i32) + +define @vfsqrt_vv_nxv16f32( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv16f32: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv16f32( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv16f32_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv16f32_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv16f32( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv1f64(, , i32) + +define @vfsqrt_vv_nxv1f64( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv1f64( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv1f64_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv1f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m1, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv1f64( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv2f64(, , i32) + +define @vfsqrt_vv_nxv2f64( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv2f64( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv2f64_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv2f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m2, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv2f64( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv4f64(, , i32) + +define @vfsqrt_vv_nxv4f64( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv4f64( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv4f64_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv4f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m4, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv4f64( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv7f64(, , i32) + +define @vfsqrt_vv_nxv7f64( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv7f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv7f64( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv7f64_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv7f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv7f64( %va, %m, i32 %evl) + ret %v +} + +declare @llvm.vp.sqrt.nxv8f64(, , i32) + +define @vfsqrt_vv_nxv8f64( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv8f64( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv8f64_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv8f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv8f64( %va, %m, i32 %evl) + ret %v +} + +; Test splitting. +declare @llvm.vp.sqrt.nxv16f64(, , i32) + +define @vfsqrt_vv_nxv16f64( %va, %m, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv16f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vmv1r.v v24, v0 +; CHECK-NEXT: li a2, 0 +; CHECK-NEXT: csrr a1, vlenb +; CHECK-NEXT: srli a4, a1, 3 +; CHECK-NEXT: vsetvli a3, zero, e8, mf4, ta, mu +; CHECK-NEXT: sub a3, a0, a1 +; CHECK-NEXT: vslidedown.vx v0, v0, a4 +; CHECK-NEXT: bltu a0, a3, .LBB32_2 +; CHECK-NEXT: # %bb.1: +; CHECK-NEXT: mv a2, a3 +; CHECK-NEXT: .LBB32_2: +; CHECK-NEXT: vsetvli zero, a2, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v16, v16, v0.t +; CHECK-NEXT: bltu a0, a1, .LBB32_4 +; CHECK-NEXT: # %bb.3: +; CHECK-NEXT: mv a0, a1 +; CHECK-NEXT: .LBB32_4: +; CHECK-NEXT: vsetvli zero, a0, e64, m8, ta, mu +; CHECK-NEXT: vmv1r.v v0, v24 +; CHECK-NEXT: vfsqrt.v v8, v8, v0.t +; CHECK-NEXT: ret + %v = call @llvm.vp.sqrt.nxv16f64( %va, %m, i32 %evl) + ret %v +} + +define @vfsqrt_vv_nxv16f64_unmasked( %va, i32 zeroext %evl) { +; CHECK-LABEL: vfsqrt_vv_nxv16f64_unmasked: +; CHECK: # %bb.0: +; CHECK-NEXT: csrr a1, vlenb +; CHECK-NEXT: mv a2, a0 +; CHECK-NEXT: bltu a0, a1, .LBB33_2 +; CHECK-NEXT: # %bb.1: +; CHECK-NEXT: mv a2, a1 +; CHECK-NEXT: .LBB33_2: +; CHECK-NEXT: li a3, 0 +; CHECK-NEXT: vsetvli zero, a2, e64, m8, ta, mu +; CHECK-NEXT: sub a1, a0, a1 +; CHECK-NEXT: vfsqrt.v v8, v8 +; CHECK-NEXT: bltu a0, a1, .LBB33_4 +; CHECK-NEXT: # %bb.3: +; CHECK-NEXT: mv a3, a1 +; CHECK-NEXT: .LBB33_4: +; CHECK-NEXT: vsetvli zero, a3, e64, m8, ta, mu +; CHECK-NEXT: vfsqrt.v v16, v16 +; CHECK-NEXT: ret + %head = insertelement poison, i1 true, i32 0 + %m = shufflevector %head, poison, zeroinitializer + %v = call @llvm.vp.sqrt.nxv16f64( %va, %m, i32 %evl) + ret %v +} diff --git a/llvm/unittests/IR/VPIntrinsicTest.cpp b/llvm/unittests/IR/VPIntrinsicTest.cpp --- a/llvm/unittests/IR/VPIntrinsicTest.cpp +++ b/llvm/unittests/IR/VPIntrinsicTest.cpp @@ -55,6 +55,8 @@ "i32)"; Str << " declare <8 x float> @llvm.vp.fabs.v8f32(<8 x float>, <8 x i1>, " "i32)"; + Str << " declare <8 x float> @llvm.vp.sqrt.v8f32(<8 x float>, <8 x i1>, " + "i32)"; Str << " declare <8 x float> @llvm.vp.fma.v8f32(<8 x float>, <8 x float>, " "<8 x float>, <8 x i1>, i32) ";