diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h @@ -97,6 +97,10 @@ return 31; } + using BaseT::getIntrinsicInstrCost; + unsigned getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, + TTI::TargetCostKind CostKind); + unsigned getRegisterBitWidth(bool Vector) const { if (Vector) { if (ST->hasSVE()) diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -210,6 +210,28 @@ return TTI::PSK_Software; } +unsigned +AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, + TTI::TargetCostKind CostKind) { + auto *RetTy = ICA.getReturnType(); + switch (ICA.getID()) { + case Intrinsic::smin: + case Intrinsic::umin: + case Intrinsic::smax: + case Intrinsic::umax: { + static const auto ValidMinMaxTys = {MVT::v8i8, MVT::v16i8, MVT::v8i16, + MVT::v2i32, MVT::v4i32}; + std::pair LT = TLI->getTypeLegalizationCost(DL, RetTy); + if (any_of(ValidMinMaxTys, [<](MVT M) { return M == LT.second; })) + return LT.first; + break; + } + default: + break; + } + return BaseT::getIntrinsicInstrCost(ICA, CostKind); +} + bool AArch64TTIImpl::isWideningInstruction(Type *DstTy, unsigned Opcode, ArrayRef Args) { diff --git a/llvm/test/Analysis/CostModel/AArch64/min-max.ll b/llvm/test/Analysis/CostModel/AArch64/min-max.ll --- a/llvm/test/Analysis/CostModel/AArch64/min-max.ll +++ b/llvm/test/Analysis/CostModel/AArch64/min-max.ll @@ -2,7 +2,7 @@ ; RUN: llc < %s -mtriple=aarch64--linux-gnu | FileCheck %s --check-prefix=CODE ; COST-LABEL: umin.v8i8 -; COST-NEXT: Cost Model: Found an estimated cost of 30 for instruction: %res = call <8 x i8> @llvm.umin.v8i8(<8 x i8> %v0, <8 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <8 x i8> @llvm.umin.v8i8(<8 x i8> %v0, <8 x i8> %v1) ; CODE-LABEL: umin.v8i8 ; CODE: bb.0 @@ -16,7 +16,7 @@ } ; COST-LABEL: umin.v9i8 -; COST-NEXT: Cost Model: Found an estimated cost of 34 for instruction: %res = call <9 x i8> @llvm.umin.v9i8(<9 x i8> %v0, <9 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <9 x i8> @llvm.umin.v9i8(<9 x i8> %v0, <9 x i8> %v1) ; CODE-LABEL: umin.v9i8 ; CODE: bb.0 @@ -30,7 +30,7 @@ } ; COST-LABEL: umin.v16i8 -; COST-NEXT: Cost Model: Found an estimated cost of 62 for instruction: %res = call <16 x i8> @llvm.umin.v16i8(<16 x i8> %v0, <16 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <16 x i8> @llvm.umin.v16i8(<16 x i8> %v0, <16 x i8> %v1) ; CODE-LABEL: umin.v16i8 ; CODE: bb.0 @@ -44,7 +44,7 @@ } ; COST-LABEL: umin.v8i16 -; COST-NEXT: Cost Model: Found an estimated cost of 30 for instruction: %res = call <8 x i16> @llvm.umin.v8i16(<8 x i16> %v0, <8 x i16> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <8 x i16> @llvm.umin.v8i16(<8 x i16> %v0, <8 x i16> %v1) ; CODE-LABEL: umin.v8i16 ; CODE: bb.0 @@ -58,7 +58,7 @@ } ; COST-LABEL: umin.v4i32 -; COST-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %res = call <4 x i32> @llvm.umin.v4i32(<4 x i32> %v0, <4 x i32> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <4 x i32> @llvm.umin.v4i32(<4 x i32> %v0, <4 x i32> %v1) ; CODE-LABEL: umin.v4i32 ; CODE: bb.0 @@ -72,7 +72,7 @@ } ; COST-LABEL: umin.v8i32 -; COST-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %res = call <8 x i32> @llvm.umin.v8i32(<8 x i32> %v0, <8 x i32> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %res = call <8 x i32> @llvm.umin.v8i32(<8 x i32> %v0, <8 x i32> %v1) ; CODE-LABEL: umin.v8i32 ; CODE: bb.0 @@ -101,7 +101,7 @@ } ; COST-LABEL: smin.v8i8 -; COST-NEXT: Cost Model: Found an estimated cost of 30 for instruction: %res = call <8 x i8> @llvm.smin.v8i8(<8 x i8> %v0, <8 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <8 x i8> @llvm.smin.v8i8(<8 x i8> %v0, <8 x i8> %v1) ; CODE-LABEL: smin.v8i8 ; CODE: bb.0 @@ -115,7 +115,7 @@ } ; COST-LABEL: smin.v9i8 -; COST-NEXT: Cost Model: Found an estimated cost of 34 for instruction: %res = call <9 x i8> @llvm.smin.v9i8(<9 x i8> %v0, <9 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <9 x i8> @llvm.smin.v9i8(<9 x i8> %v0, <9 x i8> %v1) ; CODE-LABEL: smin.v9i8 ; CODE: bb.0 @@ -129,7 +129,7 @@ } ; COST-LABEL: smin.v16i8 -; COST-NEXT: Cost Model: Found an estimated cost of 62 for instruction: %res = call <16 x i8> @llvm.smin.v16i8(<16 x i8> %v0, <16 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <16 x i8> @llvm.smin.v16i8(<16 x i8> %v0, <16 x i8> %v1) ; CODE-LABEL: smin.v16i8 ; CODE: bb.0 @@ -143,7 +143,7 @@ } ; COST-LABEL: smin.v8i16 -; COST-NEXT: Cost Model: Found an estimated cost of 30 for instruction: %res = call <8 x i16> @llvm.smin.v8i16(<8 x i16> %v0, <8 x i16> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <8 x i16> @llvm.smin.v8i16(<8 x i16> %v0, <8 x i16> %v1) ; CODE-LABEL: smin.v8i16 ; CODE: bb.0 @@ -157,7 +157,7 @@ } ; COST-LABEL: smin.v4i32 -; COST-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %res = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %v0, <4 x i32> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %v0, <4 x i32> %v1) ; CODE-LABEL: smin.v4i32 ; CODE: bb.0 @@ -171,7 +171,7 @@ } ; COST-LABEL: smin.v8i32 -; COST-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %res = call <8 x i32> @llvm.smin.v8i32(<8 x i32> %v0, <8 x i32> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %res = call <8 x i32> @llvm.smin.v8i32(<8 x i32> %v0, <8 x i32> %v1) ; CODE-LABEL: smin.v8i32 ; CODE: bb.0 @@ -200,7 +200,7 @@ } ; COST-LABEL: umax.v8i8 -; COST-NEXT: Cost Model: Found an estimated cost of 30 for instruction: %res = call <8 x i8> @llvm.umax.v8i8(<8 x i8> %v0, <8 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <8 x i8> @llvm.umax.v8i8(<8 x i8> %v0, <8 x i8> %v1) ; CODE-LABEL: umax.v8i8 ; CODE: bb.0 @@ -214,7 +214,7 @@ } ; COST-LABEL: umax.v9i8 -; COST-NEXT: Cost Model: Found an estimated cost of 34 for instruction: %res = call <9 x i8> @llvm.umax.v9i8(<9 x i8> %v0, <9 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <9 x i8> @llvm.umax.v9i8(<9 x i8> %v0, <9 x i8> %v1) ; CODE-LABEL: umax.v9i8 ; CODE: bb.0 @@ -227,9 +227,8 @@ ret <9 x i8> %res } - ; COST-LABEL: umax.v16i8 -; COST-NEXT: Cost Model: Found an estimated cost of 62 for instruction: %res = call <16 x i8> @llvm.umax.v16i8(<16 x i8> %v0, <16 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <16 x i8> @llvm.umax.v16i8(<16 x i8> %v0, <16 x i8> %v1) ; CODE-LABEL: umax.v16i8 ; CODE: bb.0 @@ -243,7 +242,7 @@ } ; COST-LABEL: umax.v8i16 -; COST-NEXT: Cost Model: Found an estimated cost of 30 for instruction: %res = call <8 x i16> @llvm.umax.v8i16(<8 x i16> %v0, <8 x i16> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <8 x i16> @llvm.umax.v8i16(<8 x i16> %v0, <8 x i16> %v1) ; CODE-LABEL: umax.v8i16 ; CODE: bb.0 @@ -257,7 +256,7 @@ } ; COST-LABEL: umax.v4i32 -; COST-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %res = call <4 x i32> @llvm.umax.v4i32(<4 x i32> %v0, <4 x i32> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <4 x i32> @llvm.umax.v4i32(<4 x i32> %v0, <4 x i32> %v1) ; CODE-LABEL: umax.v4i32 ; CODE: bb.0 @@ -271,7 +270,7 @@ } ; COST-LABEL: umax.v8i32 -; COST-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %res = call <8 x i32> @llvm.umax.v8i32(<8 x i32> %v0, <8 x i32> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %res = call <8 x i32> @llvm.umax.v8i32(<8 x i32> %v0, <8 x i32> %v1) ; CODE-LABEL: umax.v8i32 ; CODE: bb.0 @@ -300,7 +299,7 @@ } ; COST-LABEL: smax.v8i8 -; COST-NEXT: Cost Model: Found an estimated cost of 30 for instruction: %res = call <8 x i8> @llvm.smax.v8i8(<8 x i8> %v0, <8 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <8 x i8> @llvm.smax.v8i8(<8 x i8> %v0, <8 x i8> %v1) ; CODE-LABEL: smax.v8i8 ; CODE: bb.0 @@ -314,7 +313,7 @@ } ; COST-LABEL: smax.v9i8 -; COST-NEXT: Cost Model: Found an estimated cost of 34 for instruction: %res = call <9 x i8> @llvm.smax.v9i8(<9 x i8> %v0, <9 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <9 x i8> @llvm.smax.v9i8(<9 x i8> %v0, <9 x i8> %v1) ; CODE-LABEL: smax.v9i8 ; CODE: bb.0 @@ -328,7 +327,7 @@ } ; COST-LABEL: smax.v16i8 -; COST-NEXT: Cost Model: Found an estimated cost of 62 for instruction: %res = call <16 x i8> @llvm.smax.v16i8(<16 x i8> %v0, <16 x i8> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <16 x i8> @llvm.smax.v16i8(<16 x i8> %v0, <16 x i8> %v1) ; CODE-LABEL: smax.v16i8 ; CODE: bb.0 @@ -342,7 +341,7 @@ } ; COST-LABEL: smax.v8i16 -; COST-NEXT: Cost Model: Found an estimated cost of 30 for instruction: %res = call <8 x i16> @llvm.smax.v8i16(<8 x i16> %v0, <8 x i16> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <8 x i16> @llvm.smax.v8i16(<8 x i16> %v0, <8 x i16> %v1) ; CODE-LABEL: smax.v8i16 ; CODE: bb.0 @@ -356,7 +355,7 @@ } ; COST-LABEL: smax.v4i32 -; COST-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %res = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %v0, <4 x i32> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %res = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %v0, <4 x i32> %v1) ; CODE-LABEL: smax.v4i32 ; CODE: bb.0 @@ -370,7 +369,7 @@ } ; COST-LABEL: smax.v8i32 -; COST-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %res = call <8 x i32> @llvm.smax.v8i32(<8 x i32> %v0, <8 x i32> %v1) +; COST-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %res = call <8 x i32> @llvm.smax.v8i32(<8 x i32> %v0, <8 x i32> %v1) ; CODE-LABEL: smax.v8i32 ; CODE: bb.0