[llvm] r270537 - [CostModel][X86][XOP] Added XOP costmodel for BITREVERSE

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue May 24 01:18:04 PDT 2016


Author: rksimon
Date: Tue May 24 03:17:50 2016
New Revision: 270537

URL: http://llvm.org/viewvc/llvm-project?rev=270537&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetTransformInfo.h
    llvm/trunk/test/Analysis/CostModel/X86/bitreverse.ll

Modified: llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp?rev=270537&r1=270536&r2=270537&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp Tue May 24 03:17:50 2016
@@ -917,6 +917,49 @@ int X86TTIImpl::getCmpSelInstrCost(unsig
   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
     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))

Modified: llvm/trunk/lib/Target/X86/X86TargetTransformInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetTransformInfo.h?rev=270537&r1=270536&r2=270537&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetTransformInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86TargetTransformInfo.h Tue May 24 03:17:50 2016
@@ -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);

Modified: llvm/trunk/test/Analysis/CostModel/X86/bitreverse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/X86/bitreverse.ll?rev=270537&r1=270536&r2=270537&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/CostModel/X86/bitreverse.ll (original)
+++ llvm/trunk/test/Analysis/CostModel/X86/bitreverse.ll Tue May 24 03:17:50 2016
@@ -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(<
 ; 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(<
 ; 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(<
 ; 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(<
 ; 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(<
 ; 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
 ; 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(<
 ; 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(<
 ; 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
 }




More information about the llvm-commits mailing list