25 #define DEBUG_TYPE "systemztti" 81 case Instruction::GetElementPtr:
98 case Instruction::ICmp:
109 case Instruction::Sub:
119 case Instruction::Mul:
126 case Instruction::Or:
127 case Instruction::Xor:
137 case Instruction::And:
155 case Instruction::Shl:
156 case Instruction::LShr:
157 case Instruction::AShr:
162 case Instruction::UDiv:
163 case Instruction::SDiv:
164 case Instruction::URem:
165 case Instruction::SRem:
166 case Instruction::Trunc:
167 case Instruction::ZExt:
168 case Instruction::SExt:
169 case Instruction::IntToPtr:
170 case Instruction::PtrToInt:
171 case Instruction::BitCast:
172 case Instruction::PHI:
199 case Intrinsic::sadd_with_overflow:
200 case Intrinsic::uadd_with_overflow:
201 case Intrinsic::ssub_with_overflow:
202 case Intrinsic::usub_with_overflow:
211 case Intrinsic::smul_with_overflow:
212 case Intrinsic::umul_with_overflow:
219 case Intrinsic::experimental_stackmap:
223 case Intrinsic::experimental_patchpoint_void:
224 case Intrinsic::experimental_patchpoint_i64:
244 bool HasCall =
false;
245 unsigned NumStores = 0;
246 for (
auto &BB : L->
blocks())
247 for (
auto &
I : *BB) {
248 if (isa<CallInst>(&
I) || isa<InvokeInst>(&
I)) {
253 if (
F->getIntrinsicID() == Intrinsic::memcpy ||
254 F->getIntrinsicID() == Intrinsic::memset)
260 if (isa<StoreInst>(&
I)) {
261 Type *MemAccessTy =
I.getOperand(0)->getType();
269 unsigned const Max = (NumStores ? (12 / NumStores) : UINT_MAX);
308 bool Vector = (ClassID == 1);
336 assert(Size > 0 &&
"Element must have non-zero size.");
346 assert(WideBits > 0 &&
"Could not compute size of vector");
347 return ((WideBits % 128U) ? ((WideBits / 128U) + 1) : (WideBits / 128U));
368 const unsigned DivInstrCost = 20;
369 const unsigned DivMulSeqCost = 10;
370 const unsigned SDivPow2Cost = 4;
373 Opcode == Instruction::SDiv || Opcode == Instruction::SRem;
374 bool UnsignedDivRem =
375 Opcode == Instruction::UDiv || Opcode == Instruction::URem;
378 bool DivRemConst =
false;
379 bool DivRemConstPow2 =
false;
380 if ((SignedDivRem || UnsignedDivRem) && Args.
size() == 2) {
381 if (
const Constant *
C = dyn_cast<Constant>(Args[1])) {
384 ? dyn_cast_or_null<const ConstantInt>(
C->getSplatValue())
385 : dyn_cast<const ConstantInt>(
C));
386 if (CVal !=
nullptr &&
388 DivRemConstPow2 =
true;
396 "getArithmeticInstrCost() called with vector type.");
402 if (Opcode == Instruction::Shl || Opcode == Instruction::LShr ||
403 Opcode == Instruction::AShr) {
408 return (NumVectors * (SignedDivRem ? SDivPow2Cost : 1));
411 if ((SignedDivRem || UnsignedDivRem) && VF > 4)
422 if (Opcode == Instruction::FAdd || Opcode == Instruction::FSub ||
423 Opcode == Instruction::FMul || Opcode == Instruction::FDiv) {
424 switch (ScalarBits) {
431 unsigned ScalarCost =
449 if (Opcode == Instruction::FRem) {
452 if (VF == 2 && ScalarBits == 32)
461 if (Opcode == Instruction::FAdd || Opcode == Instruction::FSub ||
462 Opcode == Instruction::FMul || Opcode == Instruction::FDiv)
466 if (Opcode == Instruction::FRem)
471 if (Opcode == Instruction::Xor) {
472 for (
const Value *A : Args) {
474 if (
I->hasOneUse() &&
475 (
I->getOpcode() == Instruction::And ||
476 I->getOpcode() == Instruction::Or ||
477 I->getOpcode() == Instruction::Xor))
481 else if (Opcode == Instruction::Or || Opcode == Instruction::And) {
482 for (
const Value *A : Args) {
484 if (
I->hasOneUse() &&
I->getOpcode() == Instruction::Xor)
491 if (Opcode == Instruction::Or)
494 if (Opcode == Instruction::Xor && ScalarBits == 1) {
501 return (SignedDivRem ? SDivPow2Cost : 1);
503 return DivMulSeqCost;
504 if (SignedDivRem || UnsignedDivRem)
510 Opd1PropInfo, Opd2PropInfo, Args, CxtI);
532 return (Index == 0 ? 0 : NumVectors);
539 return NumVectors - 1;
566 "Packing must reduce size of vector type.");
568 "Packing should not change number of elements.");
584 for (
unsigned P = 0;
P < Log2Diff; ++
P) {
605 "Should only be called with vector types.");
607 unsigned PackCost = 0;
611 if (SrcScalarBits > DstScalarBits)
614 else if (SrcScalarBits < DstScalarBits) {
617 PackCost = Log2Diff * DstNumParts;
619 PackCost += DstNumParts - 1;
628 Type *OpTy =
nullptr;
630 OpTy = CI->getOperand(0)->getType();
632 if (LogicI->getNumOperands() == 2)
633 if (
CmpInst *CI0 = dyn_cast<CmpInst>(LogicI->getOperand(0)))
634 if (isa<CmpInst>(LogicI->getOperand(1)))
635 OpTy = CI0->getOperand(0)->getType();
637 if (OpTy !=
nullptr) {
662 if (CmpOpTy !=
nullptr)
664 if (Opcode == Instruction::ZExt || Opcode == Instruction::UIToFP)
676 assert (ST->
hasVector() &&
"getCastInstrCost() called with vector type.");
682 if (Opcode == Instruction::Trunc) {
688 if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt) {
689 if (SrcScalarBits >= 8) {
695 unsigned NumSrcVectorOps =
696 (NumUnpacks > 1 ? (NumDstVectors - NumSrcVectors)
697 : (NumDstVectors / 2));
699 return (NumUnpacks * NumDstVectors) + NumSrcVectorOps;
701 else if (SrcScalarBits == 1)
705 if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP ||
706 Opcode == Instruction::FPToSI || Opcode == Instruction::FPToUI) {
712 if (SrcScalarBits == DstScalarBits)
713 return NumDstVectors;
715 if (SrcScalarBits == 1)
724 unsigned TotCost = VF * ScalarCost;
725 bool NeedsInserts =
true, NeedsExtracts =
true;
727 if (DstScalarBits == 128 &&
728 (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP))
729 NeedsInserts =
false;
730 if (SrcScalarBits == 128 &&
731 (Opcode == Instruction::FPToSI || Opcode == Instruction::FPToUI))
732 NeedsExtracts =
false;
738 if (VF == 2 && SrcScalarBits == 32 && DstScalarBits == 32)
744 if (Opcode == Instruction::FPTrunc) {
745 if (SrcScalarBits == 128)
748 return VF / 2 +
std::max(1U, VF / 4 );
751 if (Opcode == Instruction::FPExt) {
752 if (SrcScalarBits == 32 && DstScalarBits == 64) {
765 if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP) {
766 if (SrcScalarBits >= 32 ||
767 (I !=
nullptr && isa<LoadInst>(I->
getOperand(0))))
769 return SrcScalarBits > 1 ? 2 : 5 ;
772 if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
780 if (Opcode == Instruction::SExt)
781 Cost = (DstScalarBits < 64 ? 3 : 4);
782 if (Opcode == Instruction::ZExt)
798 unsigned ExtCost = 0;
801 if (!isa<LoadInst>(
Op) && !isa<ConstantInt>(
Op))
810 assert (ST->
hasVector() &&
"getCmpSelInstrCost() called with vector type.");
814 if (Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) {
815 unsigned PredicateExtraCost = 0;
819 case CmpInst::Predicate::ICMP_NE:
820 case CmpInst::Predicate::ICMP_UGE:
821 case CmpInst::Predicate::ICMP_ULE:
822 case CmpInst::Predicate::ICMP_SGE:
823 case CmpInst::Predicate::ICMP_SLE:
824 PredicateExtraCost = 1;
826 case CmpInst::Predicate::FCMP_ONE:
827 case CmpInst::Predicate::FCMP_ORD:
828 case CmpInst::Predicate::FCMP_UEQ:
829 case CmpInst::Predicate::FCMP_UNO:
830 PredicateExtraCost = 2;
842 unsigned Cost = (NumVecs_cmp * (CmpCostPerVector + PredicateExtraCost));
850 unsigned PackCost = 0;
852 if (CmpOpTy !=
nullptr)
861 case Instruction::ICmp: {
865 if (I !=
nullptr && ScalarBits >= 32)
868 if (!Ld->hasOneUse() && Ld->getParent() == I->
getParent() &&
869 C->getZExtValue() == 0)
892 return ((Index % 2 == 0) ? 1 : 0);
894 if (Opcode == Instruction::ExtractElement) {
915 unsigned TruncBits = 0;
916 unsigned SExtBits = 0;
917 unsigned ZExtBits = 0;
920 if (isa<TruncInst>(UserI))
921 TruncBits = UserBits;
922 else if (isa<SExtInst>(UserI))
924 else if (isa<ZExtInst>(UserI))
927 if (TruncBits || SExtBits || ZExtBits) {
929 UserI = cast<Instruction>(*UserI->
user_begin());
932 if ((UserI->
getOpcode() == Instruction::Sub ||
933 UserI->
getOpcode() == Instruction::SDiv ||
934 UserI->
getOpcode() == Instruction::UDiv) &&
939 unsigned LoadOrTruncBits =
940 ((SExtBits || ZExtBits) ? 0 : (TruncBits ? TruncBits : LoadedBits));
943 case Instruction::Sub:
944 case Instruction::ICmp:
945 if (LoadedBits == 32 && ZExtBits == 64)
948 case Instruction::Mul:
949 if (UserI->
getOpcode() != Instruction::ICmp) {
950 if (LoadedBits == 16 &&
954 if (LoadOrTruncBits == 16)
958 case Instruction::SDiv:
959 if (LoadedBits == 32 && SExtBits == 64)
962 case Instruction::UDiv:
963 case Instruction::And:
964 case Instruction::Or:
965 case Instruction::Xor:
977 if (UserI->
getOpcode() == Instruction::ICmp)
981 return (LoadOrTruncBits == 32 || LoadOrTruncBits == 64);
989 if (
auto *CI = dyn_cast<CallInst>(
I))
990 if (
auto *
F = CI->getCalledFunction())
991 if (
F->getIntrinsicID() == Intrinsic::bswap)
1010 for (
unsigned i = 0; i < 2; ++i) {
1017 (isa<TruncInst>(OtherOp) || isa<SExtInst>(OtherOp) ||
1018 isa<ZExtInst>(OtherOp)))
1042 else if (
const StoreInst *
SI = dyn_cast<StoreInst>(I)) {
1043 const Value *StoredVal =
SI->getValueOperand();
1066 bool UseMaskForCond,
1067 bool UseMaskForGaps) {
1068 if (UseMaskForCond || UseMaskForGaps)
1070 Alignment, AddressSpace,
1071 UseMaskForCond, UseMaskForGaps);
1072 assert(isa<VectorType>(VecTy) &&
1073 "Expect a vector type for interleaved memory op");
1076 auto ceil = [](
unsigned A,
unsigned B) {
return (A +
B - 1) /
B; };
1079 assert(Factor > 1 && NumElts % Factor == 0 &&
"Invalid interleave factor");
1080 unsigned VF = NumElts / Factor;
1083 unsigned NumPermutes = 0;
1089 BitVector UsedInsts(NumVectorMemOps,
false);
1090 std::vector<BitVector> ValueVecs(Factor,
BitVector(NumVectorMemOps,
false));
1091 for (
unsigned Index : Indices)
1092 for (
unsigned Elt = 0; Elt < VF; ++Elt) {
1093 unsigned Vec = (
Index + Elt * Factor) / NumEltsPerVecReg;
1097 NumVectorMemOps = UsedInsts.
count();
1099 for (
unsigned Index : Indices) {
1103 unsigned NumSrcVecs = ValueVecs[
Index].count();
1105 assert (NumSrcVecs >= NumDstVecs &&
"Expected at least as many sources");
1106 NumPermutes +=
std::max(1U, NumSrcVecs - NumDstVecs);
1112 unsigned NumSrcVecs = std::min(NumEltsPerVecReg, Factor);
1113 unsigned NumDstVecs = NumVectorMemOps;
1114 assert (NumSrcVecs > 1 &&
"Expected at least two source vectors.");
1115 NumPermutes += (NumDstVecs * NumSrcVecs) - NumDstVecs;
1119 return NumVectorMemOps + NumPermutes;
1123 if (RetTy->
isVectorTy() && ID == Intrinsic::bswap)
1140 unsigned ScalarizationCostPassed) {
1145 FMF, ScalarizationCostPassed);
constexpr bool isUInt< 32 >(uint64_t x)
This class is the base class for the comparison instructions.
uint64_t getZExtValue() const
Get zero extended value.
int getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr)
This class represents lattice values for constants.
Cost tables and simple lookup functions.
unsigned getVectorTruncCost(Type *SrcTy, Type *DstTy)
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract)
Estimate the overhead of scalarizing an instruction.
bool isLSRCostLess(TargetTransformInfo::LSRCost &C1, TargetTransformInfo::LSRCost &C2)
The main scalar evolution driver.
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
constexpr bool isInt< 16 >(int64_t x)
An instruction for reading from memory.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
bool isVectorTy() const
True if this is an instance of VectorType.
int getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty)
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Value * > Args, FastMathFlags FMF, unsigned VF=1)
Get intrinsic cost based on arguments.
const HexagonInstrInfo * TII
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
bool hasMiscellaneousExtensions2() const
int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I)
int64_t getSExtValue() const
Get sign extended value.
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
Type * getType() const
All values are typed, get the type of this value.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const APInt & getValue() const
Return the constant as an APInt value reference.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
An instruction for storing to memory.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
bool hasMiscellaneousExtensions3() const
Value * getOperand(unsigned i) const
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isVoidTy() const
Return true if this is 'void'.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
The instances of the Type class are immutable: once they are created, they are never changed...
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
size_t size() const
size - Get the array size.
This is an important base class in LLVM.
bool hasDivRemOp(Type *DataType, bool IsSigned)
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I=nullptr)
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
unsigned getNumberOfParts(Type *Tp)
bool hasVectorEnhancements2() const
bool hasVectorEnhancements1() const
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
unsigned getBoolVecToIntConversionCost(unsigned Opcode, Type *Dst, const Instruction *I)
const SystemZInstrInfo * getInstrInfo() const override
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
unsigned getNumOperands() const
This is the shared class of boolean and integer constants.
constexpr bool isInt< 32 >(int64_t x)
size_type count() const
count - Returns the number of bits which are set.
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
unsigned getRegisterBitWidth(bool Vector) const
int getIntImmCost(const APInt &Imm, Type *Ty)
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
unsigned getVectorNumElements() const
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
Class for arbitrary precision integers.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
unsigned getNumberOfRegisters(unsigned ClassID) const
int getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty)
Represents a single loop in the control flow graph.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Establish a view to a call site for examination.
int getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
constexpr bool isUInt< 16 >(uint64_t x)
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
int getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, ArrayRef< Value *> Args, FastMathFlags FMF, unsigned VF=1)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
LLVM Value Representation.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
bool isRxSBGMask(uint64_t Mask, unsigned BitSize, unsigned &Start, unsigned &End) const
bool hasOneUse() const
Return true if there is exactly one user of this value.
Convenience struct for specifying and reasoning about fast-math flags.
bool isFoldableLoad(const LoadInst *Ld, const Instruction *&FoldedValue)
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
bool hasLoadStoreOnCond2() const
iterator_range< block_iterator > blocks() const
bool hasPopulationCount() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This file describes how to lower LLVM code to machine code.
const BasicBlock * getParent() const
unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy)