diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -328,38 +328,6 @@ {Intrinsic::round, MVT::nxv2f64, 10}, {Intrinsic::round, MVT::nxv4f64, 10}, {Intrinsic::round, MVT::nxv8f64, 10}, - {Intrinsic::fabs, MVT::v2f32, 1}, - {Intrinsic::fabs, MVT::v4f32, 1}, - {Intrinsic::fabs, MVT::v8f32, 1}, - {Intrinsic::fabs, MVT::v16f32, 1}, - {Intrinsic::fabs, MVT::nxv2f32, 1}, - {Intrinsic::fabs, MVT::nxv4f32, 1}, - {Intrinsic::fabs, MVT::nxv8f32, 1}, - {Intrinsic::fabs, MVT::nxv16f32, 1}, - {Intrinsic::fabs, MVT::v2f64, 1}, - {Intrinsic::fabs, MVT::v4f64, 1}, - {Intrinsic::fabs, MVT::v8f64, 1}, - {Intrinsic::fabs, MVT::v16f64, 1}, - {Intrinsic::fabs, MVT::nxv1f64, 1}, - {Intrinsic::fabs, MVT::nxv2f64, 1}, - {Intrinsic::fabs, MVT::nxv4f64, 1}, - {Intrinsic::fabs, MVT::nxv8f64, 1}, - {Intrinsic::sqrt, MVT::v2f32, 1}, - {Intrinsic::sqrt, MVT::v4f32, 1}, - {Intrinsic::sqrt, MVT::v8f32, 1}, - {Intrinsic::sqrt, MVT::v16f32, 1}, - {Intrinsic::sqrt, MVT::nxv2f32, 1}, - {Intrinsic::sqrt, MVT::nxv4f32, 1}, - {Intrinsic::sqrt, MVT::nxv8f32, 1}, - {Intrinsic::sqrt, MVT::nxv16f32, 1}, - {Intrinsic::sqrt, MVT::v2f64, 1}, - {Intrinsic::sqrt, MVT::v4f64, 1}, - {Intrinsic::sqrt, MVT::v8f64, 1}, - {Intrinsic::sqrt, MVT::v16f64, 1}, - {Intrinsic::sqrt, MVT::nxv1f64, 1}, - {Intrinsic::sqrt, MVT::nxv2f64, 1}, - {Intrinsic::sqrt, MVT::nxv4f64, 1}, - {Intrinsic::sqrt, MVT::nxv8f64, 1}, {Intrinsic::bswap, MVT::v2i16, 3}, {Intrinsic::bswap, MVT::v4i16, 3}, {Intrinsic::bswap, MVT::v8i16, 3}, @@ -582,7 +550,15 @@ case Intrinsic::smax: { auto LT = getTypeLegalizationCost(RetTy); if ((ST->hasVInstructions() && LT.second.isVector()) || - (LT.second.isScalarInteger() && ST->hasStdExtZbb())) + (ST->hasStdExtZbb() && LT.second.isScalarInteger())) + return LT.first; + break; + } + case Intrinsic::fabs: + case Intrinsic::sqrt: { + auto LT = getTypeLegalizationCost(RetTy); + if ((ST->hasVInstructions() || ST->hasVInstructionsF16()) && + LT.second.isVector()) return LT.first; break; } diff --git a/llvm/test/Analysis/CostModel/RISCV/fp-min-max-abs.ll b/llvm/test/Analysis/CostModel/RISCV/fp-min-max-abs.ll --- a/llvm/test/Analysis/CostModel/RISCV/fp-min-max-abs.ll +++ b/llvm/test/Analysis/CostModel/RISCV/fp-min-max-abs.ll @@ -1,33 +1,51 @@ ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py -; RUN: opt < %s -passes="print" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+f,+d -riscv-v-vector-bits-min=-1 | FileCheck %s +; RUN: opt < %s -passes="print" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+f,+d,+zfh,+experimental-zvfh -riscv-v-vector-bits-min=-1 | FileCheck %s define void @fabs() { ; CHECK-LABEL: 'fabs' ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %1 = call float @llvm.fabs.f32(float undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %2 = call <2 x float> @llvm.fabs.v2f32(<2 x float> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %3 = call <4 x float> @llvm.fabs.v4f32(<4 x float> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = call <8 x float> @llvm.fabs.v8f32(<8 x float> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %5 = call <16 x float> @llvm.fabs.v16f32(<16 x float> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = call @llvm.fabs.nxv2f32( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = call @llvm.fabs.nxv4f32( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %8 = call @llvm.fabs.nxv8f32( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %9 = call @llvm.fabs.nxv16f32( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %10 = call double @llvm.fabs.f64(double undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %11 = call <2 x double> @llvm.fabs.v2f64(<2 x double> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = call <4 x double> @llvm.fabs.v4f64(<4 x double> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %13 = call <8 x double> @llvm.fabs.v8f64(<8 x double> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %14 = call <16 x double> @llvm.fabs.v16f64(<16 x double> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %15 = call @llvm.fabs.nxv1f64( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %16 = call @llvm.fabs.nxv2f64( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %17 = call @llvm.fabs.nxv4f64( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %18 = call @llvm.fabs.nxv8f64( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %2 = call half @llvm.fabs.f16(half undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %3 = call <2 x half> @llvm.fabs.v2f16(<2 x half> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = call <4 x half> @llvm.fabs.v4f16(<4 x half> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %5 = call <8 x half> @llvm.fabs.v8f16(<8 x half> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = call <16 x half> @llvm.fabs.v16f16(<16 x half> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = call <2 x float> @llvm.fabs.v2f32(<2 x float> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %8 = call <4 x float> @llvm.fabs.v4f32(<4 x float> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %9 = call <8 x float> @llvm.fabs.v8f32(<8 x float> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %10 = call <16 x float> @llvm.fabs.v16f32(<16 x float> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %11 = call @llvm.fabs.nxv2f16( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = call @llvm.fabs.nxv4f16( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %13 = call @llvm.fabs.nxv8f16( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %14 = call @llvm.fabs.nxv16f16( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %15 = call @llvm.fabs.nxv2f32( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %16 = call @llvm.fabs.nxv4f32( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %17 = call @llvm.fabs.nxv8f32( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %18 = call @llvm.fabs.nxv16f32( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %19 = call double @llvm.fabs.f64(double undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %20 = call <2 x double> @llvm.fabs.v2f64(<2 x double> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %21 = call <4 x double> @llvm.fabs.v4f64(<4 x double> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %22 = call <8 x double> @llvm.fabs.v8f64(<8 x double> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %23 = call <16 x double> @llvm.fabs.v16f64(<16 x double> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %24 = call @llvm.fabs.nxv1f64( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %25 = call @llvm.fabs.nxv2f64( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %26 = call @llvm.fabs.nxv4f64( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %27 = call @llvm.fabs.nxv8f64( undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; call float @llvm.fabs.f32(float undef) + call half @llvm.fabs.f16(half undef) + call <2 x half> @llvm.fabs.v2f16(<2 x half> undef) + call <4 x half> @llvm.fabs.v4f16(<4 x half> undef) + call <8 x half> @llvm.fabs.v8f16(<8 x half> undef) + call <16 x half> @llvm.fabs.v16f16(<16 x half> undef) call <2 x float> @llvm.fabs.v2f32(<2 x float> undef) call <4 x float> @llvm.fabs.v4f32(<4 x float> undef) call <8 x float> @llvm.fabs.v8f32(<8 x float> undef) call <16 x float> @llvm.fabs.v16f32(<16 x float> undef) + call @llvm.fabs.nvx2f16( undef) + call @llvm.fabs.nvx4f16( undef) + call @llvm.fabs.nvx8f16( undef) + call @llvm.fabs.nvx16f16( undef) call @llvm.fabs.nvx2f32( undef) call @llvm.fabs.nvx4f32( undef) call @llvm.fabs.nvx8f32( undef) @@ -260,10 +278,19 @@ } declare float @llvm.fabs.f32(float) +declare half @llvm.fabs.f16(half) +declare <2 x half> @llvm.fabs.v2f16(<2 x half>) +declare <4 x half> @llvm.fabs.v4f16(<4 x half>) +declare <8 x half> @llvm.fabs.v8f16(<8 x half>) +declare <16 x half> @llvm.fabs.v16f16(<16 x half>) declare <2 x float> @llvm.fabs.v2f32(<2 x float>) declare <4 x float> @llvm.fabs.v4f32(<4 x float>) declare <8 x float> @llvm.fabs.v8f32(<8 x float>) declare <16 x float> @llvm.fabs.v16f32(<16 x float>) +declare @llvm.fabs.nvx2f16() +declare @llvm.fabs.nvx4f16() +declare @llvm.fabs.nvx8f16() +declare @llvm.fabs.nvx16f16() declare @llvm.fabs.nvx2f32() declare @llvm.fabs.nvx4f32() declare @llvm.fabs.nvx8f32() diff --git a/llvm/test/Analysis/CostModel/RISCV/fp-sqrt-pow.ll b/llvm/test/Analysis/CostModel/RISCV/fp-sqrt-pow.ll --- a/llvm/test/Analysis/CostModel/RISCV/fp-sqrt-pow.ll +++ b/llvm/test/Analysis/CostModel/RISCV/fp-sqrt-pow.ll @@ -1,33 +1,51 @@ ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py -; RUN: opt < %s -passes="print" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+f,+d -riscv-v-vector-bits-min=-1 | FileCheck %s +; RUN: opt < %s -passes="print" 2>&1 -disable-output -S -mtriple=riscv64 -mattr=+v,+f,+d,+zfh,+experimental-zvfh -riscv-v-vector-bits-min=-1 | FileCheck %s define void @sqrt() { ; CHECK-LABEL: 'sqrt' ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %1 = call float @llvm.sqrt.f32(float undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %2 = call <2 x float> @llvm.sqrt.v2f32(<2 x float> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %3 = call <4 x float> @llvm.sqrt.v4f32(<4 x float> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = call <8 x float> @llvm.sqrt.v8f32(<8 x float> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %5 = call <16 x float> @llvm.sqrt.v16f32(<16 x float> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = call @llvm.sqrt.nxv2f32( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = call @llvm.sqrt.nxv4f32( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %8 = call @llvm.sqrt.nxv8f32( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %9 = call @llvm.sqrt.nxv16f32( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %10 = call double @llvm.sqrt.f64(double undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %11 = call <2 x double> @llvm.sqrt.v2f64(<2 x double> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = call <4 x double> @llvm.sqrt.v4f64(<4 x double> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %13 = call <8 x double> @llvm.sqrt.v8f64(<8 x double> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %14 = call <16 x double> @llvm.sqrt.v16f64(<16 x double> undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %15 = call @llvm.sqrt.nxv1f64( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %16 = call @llvm.sqrt.nxv2f64( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %17 = call @llvm.sqrt.nxv4f64( undef) -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %18 = call @llvm.sqrt.nxv8f64( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %2 = call half @llvm.sqrt.f16(half undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %3 = call <2 x half> @llvm.sqrt.v2f16(<2 x half> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = call <4 x half> @llvm.sqrt.v4f16(<4 x half> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %5 = call <8 x half> @llvm.sqrt.v8f16(<8 x half> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = call <16 x half> @llvm.sqrt.v16f16(<16 x half> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = call <2 x float> @llvm.sqrt.v2f32(<2 x float> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %8 = call <4 x float> @llvm.sqrt.v4f32(<4 x float> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %9 = call <8 x float> @llvm.sqrt.v8f32(<8 x float> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %10 = call <16 x float> @llvm.sqrt.v16f32(<16 x float> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %11 = call @llvm.sqrt.nxv2f16( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %12 = call @llvm.sqrt.nxv4f16( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %13 = call @llvm.sqrt.nxv8f16( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %14 = call @llvm.sqrt.nxv16f16( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %15 = call @llvm.sqrt.nxv2f32( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %16 = call @llvm.sqrt.nxv4f32( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %17 = call @llvm.sqrt.nxv8f32( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %18 = call @llvm.sqrt.nxv16f32( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %19 = call double @llvm.sqrt.f64(double undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %20 = call <2 x double> @llvm.sqrt.v2f64(<2 x double> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %21 = call <4 x double> @llvm.sqrt.v4f64(<4 x double> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %22 = call <8 x double> @llvm.sqrt.v8f64(<8 x double> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %23 = call <16 x double> @llvm.sqrt.v16f64(<16 x double> undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %24 = call @llvm.sqrt.nxv1f64( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %25 = call @llvm.sqrt.nxv2f64( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %26 = call @llvm.sqrt.nxv4f64( undef) +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %27 = call @llvm.sqrt.nxv8f64( undef) ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void ; call float @llvm.sqrt.f32(float undef) + call half @llvm.sqrt.f16(half undef) + call <2 x half> @llvm.sqrt.v2f16(<2 x half> undef) + call <4 x half> @llvm.sqrt.v4f16(<4 x half> undef) + call <8 x half> @llvm.sqrt.v8f16(<8 x half> undef) + call <16 x half> @llvm.sqrt.v16f16(<16 x half> undef) call <2 x float> @llvm.sqrt.v2f32(<2 x float> undef) call <4 x float> @llvm.sqrt.v4f32(<4 x float> undef) call <8 x float> @llvm.sqrt.v8f32(<8 x float> undef) call <16 x float> @llvm.sqrt.v16f32(<16 x float> undef) + call @llvm.sqrt.nvx2f16( undef) + call @llvm.sqrt.nvx4f16( undef) + call @llvm.sqrt.nvx8f16( undef) + call @llvm.sqrt.nvx16f16( undef) call @llvm.sqrt.nvx2f32( undef) call @llvm.sqrt.nvx4f32( undef) call @llvm.sqrt.nvx8f32( undef) @@ -44,11 +62,20 @@ ret void } +declare half @llvm.sqrt.f16(half) declare float @llvm.sqrt.f32(float) +declare <2 x half> @llvm.sqrt.v2f16(<2 x half>) +declare <4 x half> @llvm.sqrt.v4f16(<4 x half>) +declare <8 x half> @llvm.sqrt.v8f16(<8 x half>) +declare <16 x half> @llvm.sqrt.v16f16(<16 x half>) declare <2 x float> @llvm.sqrt.v2f32(<2 x float>) declare <4 x float> @llvm.sqrt.v4f32(<4 x float>) declare <8 x float> @llvm.sqrt.v8f32(<8 x float>) declare <16 x float> @llvm.sqrt.v16f32(<16 x float>) +declare @llvm.sqrt.nvx2f16() +declare @llvm.sqrt.nvx4f16() +declare @llvm.sqrt.nvx8f16() +declare @llvm.sqrt.nvx16f16() declare @llvm.sqrt.nvx2f32() declare @llvm.sqrt.nvx4f32() declare @llvm.sqrt.nvx8f32()