summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2016-05-24 08:17:50 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2016-05-24 08:17:50 +0000
commit611c8e7533032ff54ed0e743e16c0f4df0959367 (patch)
tree478f1588ecbd828813f8c71c0ef38fb90c0b3cda
parentad25a60d24d6b99996c0f085fdb7af8def5e992d (diff)
[CostModel][X86][XOP] Added XOP costmodel for BITREVERSE
Now that we have a nice fast VPPERM solution. Added framework for future intrinsic costs as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270537 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/X86/X86TargetTransformInfo.cpp45
-rw-r--r--lib/Target/X86/X86TargetTransformInfo.h5
-rw-r--r--test/Analysis/CostModel/X86/bitreverse.ll24
3 files changed, 61 insertions, 13 deletions
diff --git a/lib/Target/X86/X86TargetTransformInfo.cpp b/lib/Target/X86/X86TargetTransformInfo.cpp
index 28ae96d4108..508fbe03aeb 100644
--- a/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -917,6 +917,49 @@ int X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy) {
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy);
}
+int X86TTIImpl::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
+ ArrayRef<Type *> Tys, FastMathFlags FMF) {
+ static const CostTblEntry XOPCostTbl[] = {
+ { ISD::BITREVERSE, MVT::v4i64, 4 },
+ { ISD::BITREVERSE, MVT::v8i32, 4 },
+ { ISD::BITREVERSE, MVT::v16i16, 4 },
+ { ISD::BITREVERSE, MVT::v32i8, 4 },
+ { ISD::BITREVERSE, MVT::v2i64, 1 },
+ { ISD::BITREVERSE, MVT::v4i32, 1 },
+ { ISD::BITREVERSE, MVT::v8i16, 1 },
+ { ISD::BITREVERSE, MVT::v16i8, 1 },
+ { ISD::BITREVERSE, MVT::i64, 3 },
+ { ISD::BITREVERSE, MVT::i32, 3 },
+ { ISD::BITREVERSE, MVT::i16, 3 },
+ { ISD::BITREVERSE, MVT::i8, 3 }
+ };
+
+ unsigned ISD = ISD::DELETED_NODE;
+ switch (IID) {
+ default:
+ break;
+ case Intrinsic::bitreverse:
+ ISD = ISD::BITREVERSE;
+ break;
+ }
+
+ // Legalize the type.
+ std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, RetTy);
+ MVT MTy = LT.second;
+
+ // Attempt to lookup cost.
+ if (ST->hasXOP())
+ if (const auto *Entry = CostTableLookup(XOPCostTbl, ISD, MTy))
+ return LT.first * Entry->Cost;
+
+ return BaseT::getIntrinsicInstrCost(IID, RetTy, Tys, FMF);
+}
+
+int X86TTIImpl::getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
+ ArrayRef<Value *> Args, FastMathFlags FMF) {
+ return BaseT::getIntrinsicInstrCost(IID, RetTy, Args, FMF);
+}
+
int X86TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) {
assert(Val->isVectorTy() && "This must be a vector type");
@@ -1320,7 +1363,7 @@ int X86TTIImpl::getGSVectorCost(unsigned Opcode, Type *SrcVTy, Value *Ptr,
GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr);
if (IndexSize < 64 || !GEP)
return IndexSize;
-
+
unsigned NumOfVarIndices = 0;
Value *Ptrs = GEP->getPointerOperand();
if (Ptrs->getType()->isVectorTy() && !getSplatValue(Ptrs))
diff --git a/lib/Target/X86/X86TargetTransformInfo.h b/lib/Target/X86/X86TargetTransformInfo.h
index adb745e912d..ab8046bb9fd 100644
--- a/lib/Target/X86/X86TargetTransformInfo.h
+++ b/lib/Target/X86/X86TargetTransformInfo.h
@@ -80,6 +80,11 @@ public:
bool VariableMask, unsigned Alignment);
int getAddressComputationCost(Type *PtrTy, bool IsComplex);
+ int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
+ ArrayRef<Type *> Tys, FastMathFlags FMF);
+ int getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy,
+ ArrayRef<Value *> Args, FastMathFlags FMF);
+
int getReductionCost(unsigned Opcode, Type *Ty, bool IsPairwiseForm);
int getIntImmCost(int64_t);
diff --git a/test/Analysis/CostModel/X86/bitreverse.ll b/test/Analysis/CostModel/X86/bitreverse.ll
index 9eb0ef2b4b5..4f04f3b0dd9 100644
--- a/test/Analysis/CostModel/X86/bitreverse.ll
+++ b/test/Analysis/CostModel/X86/bitreverse.ll
@@ -18,7 +18,7 @@ define i64 @var_bitreverse_i64(i64 %a) {
; SSE42: Found an estimated cost of 1 for instruction: %bitreverse
; AVX: Found an estimated cost of 1 for instruction: %bitreverse
; AVX2: Found an estimated cost of 1 for instruction: %bitreverse
-; XOP: Found an estimated cost of 1 for instruction: %bitreverse
+; XOP: Found an estimated cost of 3 for instruction: %bitreverse
%bitreverse = call i64 @llvm.bitreverse.i64(i64 %a)
ret i64 %bitreverse
}
@@ -29,7 +29,7 @@ define i32 @var_bitreverse_i32(i32 %a) {
; SSE42: Found an estimated cost of 1 for instruction: %bitreverse
; AVX: Found an estimated cost of 1 for instruction: %bitreverse
; AVX2: Found an estimated cost of 1 for instruction: %bitreverse
-; XOP: Found an estimated cost of 1 for instruction: %bitreverse
+; XOP: Found an estimated cost of 3 for instruction: %bitreverse
%bitreverse = call i32 @llvm.bitreverse.i32(i32 %a)
ret i32 %bitreverse
}
@@ -40,7 +40,7 @@ define i16 @var_bitreverse_i16(i16 %a) {
; SSE42: Found an estimated cost of 1 for instruction: %bitreverse
; AVX: Found an estimated cost of 1 for instruction: %bitreverse
; AVX2: Found an estimated cost of 1 for instruction: %bitreverse
-; XOP: Found an estimated cost of 1 for instruction: %bitreverse
+; XOP: Found an estimated cost of 3 for instruction: %bitreverse
%bitreverse = call i16 @llvm.bitreverse.i16(i16 %a)
ret i16 %bitreverse
}
@@ -51,7 +51,7 @@ define i8 @var_bitreverse_i8(i8 %a) {
; SSE42: Found an estimated cost of 1 for instruction: %bitreverse
; AVX: Found an estimated cost of 1 for instruction: %bitreverse
; AVX2: Found an estimated cost of 1 for instruction: %bitreverse
-; XOP: Found an estimated cost of 1 for instruction: %bitreverse
+; XOP: Found an estimated cost of 3 for instruction: %bitreverse
%bitreverse = call i8 @llvm.bitreverse.i8(i8 %a)
ret i8 %bitreverse
}
@@ -74,7 +74,7 @@ define <2 x i64> @var_bitreverse_v2i64(<2 x i64> %a) {
; SSE42: Found an estimated cost of 6 for instruction: %bitreverse
; AVX: Found an estimated cost of 6 for instruction: %bitreverse
; AVX2: Found an estimated cost of 6 for instruction: %bitreverse
-; XOP: Found an estimated cost of 6 for instruction: %bitreverse
+; XOP: Found an estimated cost of 1 for instruction: %bitreverse
%bitreverse = call <2 x i64> @llvm.bitreverse.v2i64(<2 x i64> %a)
ret <2 x i64> %bitreverse
}
@@ -85,7 +85,7 @@ define <4 x i64> @var_bitreverse_v4i64(<4 x i64> %a) {
; SSE42: Found an estimated cost of 12 for instruction: %bitreverse
; AVX: Found an estimated cost of 12 for instruction: %bitreverse
; AVX2: Found an estimated cost of 12 for instruction: %bitreverse
-; XOP: Found an estimated cost of 12 for instruction: %bitreverse
+; XOP: Found an estimated cost of 4 for instruction: %bitreverse
%bitreverse = call <4 x i64> @llvm.bitreverse.v4i64(<4 x i64> %a)
ret <4 x i64> %bitreverse
}
@@ -96,7 +96,7 @@ define <4 x i32> @var_bitreverse_v4i32(<4 x i32> %a) {
; SSE42: Found an estimated cost of 12 for instruction: %bitreverse
; AVX: Found an estimated cost of 12 for instruction: %bitreverse
; AVX2: Found an estimated cost of 12 for instruction: %bitreverse
-; XOP: Found an estimated cost of 12 for instruction: %bitreverse
+; XOP: Found an estimated cost of 1 for instruction: %bitreverse
%bitreverse = call <4 x i32> @llvm.bitreverse.v4i32(<4 x i32> %a)
ret <4 x i32> %bitreverse
}
@@ -107,7 +107,7 @@ define <8 x i32> @var_bitreverse_v8i32(<8 x i32> %a) {
; SSE42: Found an estimated cost of 24 for instruction: %bitreverse
; AVX: Found an estimated cost of 24 for instruction: %bitreverse
; AVX2: Found an estimated cost of 24 for instruction: %bitreverse
-; XOP: Found an estimated cost of 24 for instruction: %bitreverse
+; XOP: Found an estimated cost of 4 for instruction: %bitreverse
%bitreverse = call <8 x i32> @llvm.bitreverse.v8i32(<8 x i32> %a)
ret <8 x i32> %bitreverse
}
@@ -118,7 +118,7 @@ define <8 x i16> @var_bitreverse_v8i16(<8 x i16> %a) {
; SSE42: Found an estimated cost of 24 for instruction: %bitreverse
; AVX: Found an estimated cost of 24 for instruction: %bitreverse
; AVX2: Found an estimated cost of 24 for instruction: %bitreverse
-; XOP: Found an estimated cost of 24 for instruction: %bitreverse
+; XOP: Found an estimated cost of 1 for instruction: %bitreverse
%bitreverse = call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> %a)
ret <8 x i16> %bitreverse
}
@@ -129,7 +129,7 @@ define <16 x i16> @var_bitreverse_v16i16(<16 x i16> %a) {
; SSE42: Found an estimated cost of 48 for instruction: %bitreverse
; AVX: Found an estimated cost of 48 for instruction: %bitreverse
; AVX2: Found an estimated cost of 48 for instruction: %bitreverse
-; XOP: Found an estimated cost of 48 for instruction: %bitreverse
+; XOP: Found an estimated cost of 4 for instruction: %bitreverse
%bitreverse = call <16 x i16> @llvm.bitreverse.v16i16(<16 x i16> %a)
ret <16 x i16> %bitreverse
}
@@ -140,7 +140,7 @@ define <16 x i8> @var_bitreverse_v16i8(<16 x i8> %a) {
; SSE42: Found an estimated cost of 48 for instruction: %bitreverse
; AVX: Found an estimated cost of 48 for instruction: %bitreverse
; AVX2: Found an estimated cost of 48 for instruction: %bitreverse
-; XOP: Found an estimated cost of 48 for instruction: %bitreverse
+; XOP: Found an estimated cost of 1 for instruction: %bitreverse
%bitreverse = call <16 x i8> @llvm.bitreverse.v16i8(<16 x i8> %a)
ret <16 x i8> %bitreverse
}
@@ -151,7 +151,7 @@ define <32 x i8> @var_bitreverse_v32i8(<32 x i8> %a) {
; SSE42: Found an estimated cost of 96 for instruction: %bitreverse
; AVX: Found an estimated cost of 96 for instruction: %bitreverse
; AVX2: Found an estimated cost of 96 for instruction: %bitreverse
-; XOP: Found an estimated cost of 96 for instruction: %bitreverse
+; XOP: Found an estimated cost of 4 for instruction: %bitreverse
%bitreverse = call <32 x i8> @llvm.bitreverse.v32i8(<32 x i8> %a)
ret <32 x i8> %bitreverse
}