26 #define DEBUG_TYPE "systemztti"
82 case Instruction::GetElementPtr:
99 case Instruction::ICmp:
110 case Instruction::Sub:
120 case Instruction::Mul:
127 case Instruction::Or:
128 case Instruction::Xor:
138 case Instruction::And:
156 case Instruction::Shl:
157 case Instruction::LShr:
158 case Instruction::AShr:
163 case Instruction::UDiv:
164 case Instruction::SDiv:
165 case Instruction::URem:
166 case Instruction::SRem:
167 case Instruction::Trunc:
168 case Instruction::ZExt:
169 case Instruction::SExt:
170 case Instruction::IntToPtr:
171 case Instruction::PtrToInt:
172 case Instruction::BitCast:
173 case Instruction::PHI:
200 case Intrinsic::sadd_with_overflow:
201 case Intrinsic::uadd_with_overflow:
202 case Intrinsic::ssub_with_overflow:
203 case Intrinsic::usub_with_overflow:
212 case Intrinsic::smul_with_overflow:
213 case Intrinsic::umul_with_overflow:
220 case Intrinsic::experimental_stackmap:
224 case Intrinsic::experimental_patchpoint_void:
225 case Intrinsic::experimental_patchpoint_i64:
245 bool HasCall =
false;
246 unsigned NumStores = 0;
247 for (
auto &BB : L->
blocks())
248 for (
auto &
I : *BB) {
249 if (isa<CallInst>(&
I) || isa<InvokeInst>(&
I)) {
254 if (
F->getIntrinsicID() == Intrinsic::memcpy ||
255 F->getIntrinsicID() == Intrinsic::memset)
261 if (isa<StoreInst>(&
I)) {
262 Type *MemAccessTy =
I.getOperand(0)->getType();
270 unsigned const Max = (NumStores ? (12 / NumStores) : UINT_MAX);
314 unsigned Opcode,
Type *Ty,
331 const unsigned SDivCostEstimate = 4;
332 bool SDivPow2 =
false;
333 bool UDivPow2 =
false;
334 if ((Opcode == Instruction::SDiv || Opcode == Instruction::UDiv) &&
337 if (
const Constant *
C = dyn_cast<Constant>(Args[1])) {
338 if (
C->getType()->isVectorTy())
339 CI = dyn_cast_or_null<const ConstantInt>(
C->getSplatValue());
345 if (Opcode == Instruction::SDiv)
353 assert (ST->
hasVector() &&
"getArithmeticInstrCost() called with vector type.");
359 if (Opcode == Instruction::Shl || Opcode == Instruction::LShr ||
360 Opcode == Instruction::AShr || UDivPow2) {
365 return (NumVectors * SDivCostEstimate);
371 if (Opcode == Instruction::FAdd || Opcode == Instruction::FSub ||
372 Opcode == Instruction::FMul || Opcode == Instruction::FDiv) {
373 switch (ScalarBits) {
397 if (Opcode == Instruction::FRem) {
400 if (VF == 2 && ScalarBits == 32)
409 if (Opcode == Instruction::FAdd || Opcode == Instruction::FSub ||
410 Opcode == Instruction::FMul || Opcode == Instruction::FDiv)
414 if (Opcode == Instruction::FRem)
417 if (Opcode == Instruction::LShr || Opcode == Instruction::AShr)
418 return (ScalarBits >= 32 ? 1 : 2 );
421 if (Opcode == Instruction::Or)
424 if (Opcode == Instruction::Xor && ScalarBits == 1)
431 return SDivCostEstimate;
434 if ((Opcode == Instruction::SDiv || Opcode == Instruction::SRem))
436 return (ScalarBits < 32 ? 4 : (ScalarBits == 32 ? 2 : 1));
438 if (Opcode == Instruction::UDiv || Opcode == Instruction::URem)
440 return (ScalarBits < 32 ? 4 : 2);
445 Opd1PropInfo, Opd2PropInfo, Args);
468 return (Index == 0 ? 0 : NumVectors);
475 return NumVectors - 1;
502 "Packing must reduce size of vector type.");
504 "Packing should not change number of elements.");
520 for (
unsigned P = 0;
P < Log2Diff; ++
P) {
541 "Should only be called with vector types.");
543 unsigned PackCost = 0;
547 if (SrcScalarBits > DstScalarBits)
550 else if (SrcScalarBits < DstScalarBits) {
553 PackCost = Log2Diff * DstNumParts;
555 PackCost += DstNumParts - 1;
564 Type *OpTy =
nullptr;
566 OpTy = CI->getOperand(0)->getType();
568 if (LogicI->getNumOperands() == 2)
569 if (
CmpInst *CI0 = dyn_cast<CmpInst>(LogicI->getOperand(0)))
570 if (isa<CmpInst>(LogicI->getOperand(1)))
571 OpTy = CI0->getOperand(0)->getType();
573 if (OpTy !=
nullptr) {
593 assert (ST->
hasVector() &&
"getCastInstrCost() called with vector type.");
599 if (Opcode == Instruction::Trunc) {
605 if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt) {
606 if (SrcScalarBits >= 8) {
612 unsigned NumSrcVectorOps =
613 (NumUnpacks > 1 ? (NumDstVectors - NumSrcVectors)
614 : (NumDstVectors / 2));
616 return (NumUnpacks * NumDstVectors) + NumSrcVectorOps;
618 else if (SrcScalarBits == 1) {
624 if (CmpOpTy !=
nullptr)
626 if (Opcode == Instruction::ZExt)
628 Cost += NumDstVectors;
633 if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP ||
634 Opcode == Instruction::FPToSI || Opcode == Instruction::FPToUI) {
639 if (SrcScalarBits == 64 && DstScalarBits == 64)
640 return NumDstVectors;
647 unsigned TotCost = VF * ScalarCost;
648 bool NeedsInserts =
true, NeedsExtracts =
true;
650 if (DstScalarBits == 128 &&
651 (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP))
652 NeedsInserts =
false;
653 if (SrcScalarBits == 128 &&
654 (Opcode == Instruction::FPToSI || Opcode == Instruction::FPToUI))
655 NeedsExtracts =
false;
660 if (VF == 2 && SrcScalarBits == 32 && DstScalarBits == 32)
666 if (Opcode == Instruction::FPTrunc) {
667 if (SrcScalarBits == 128)
670 return VF / 2 +
std::max(1U, VF / 4 );
673 if (Opcode == Instruction::FPExt) {
674 if (SrcScalarBits == 32 && DstScalarBits == 64) {
687 if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP)
688 return (SrcScalarBits >= 32 ? 1 : 2 );
690 if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
695 if (Opcode == Instruction::SExt)
696 Cost = (DstScalarBits < 64 ? 3 : 4);
697 if (Opcode == Instruction::ZExt)
714 assert (ST->
hasVector() &&
"getCmpSelInstrCost() called with vector type.");
718 if (Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) {
719 unsigned PredicateExtraCost = 0;
722 switch (dyn_cast<CmpInst>(I)->getPredicate()) {
723 case CmpInst::Predicate::ICMP_NE:
724 case CmpInst::Predicate::ICMP_UGE:
725 case CmpInst::Predicate::ICMP_ULE:
726 case CmpInst::Predicate::ICMP_SGE:
727 case CmpInst::Predicate::ICMP_SLE:
728 PredicateExtraCost = 1;
730 case CmpInst::Predicate::FCMP_ONE:
731 case CmpInst::Predicate::FCMP_ORD:
732 case CmpInst::Predicate::FCMP_UEQ:
733 case CmpInst::Predicate::FCMP_UNO:
734 PredicateExtraCost = 2;
746 unsigned Cost = (NumVecs_cmp * (CmpCostPerVector + PredicateExtraCost));
754 unsigned PackCost = 0;
756 if (CmpOpTy !=
nullptr)
765 case Instruction::ICmp: {
786 return ((Index % 2 == 0) ? 1 : 0);
788 if (Opcode == Instruction::ExtractElement) {
810 bool FoldsLoad =
false;
812 case Instruction::ICmp:
814 case Instruction::Sub:
815 case Instruction::Mul:
816 case Instruction::SDiv:
817 case Instruction::UDiv:
818 case Instruction::And:
819 case Instruction::Or:
820 case Instruction::Xor:
828 FoldsLoad = (Bits == 32 || Bits == 64);
834 "Expected to only handle binops.");
838 for (
unsigned i = 0; i < 2; ++i) {
865 assert(isa<VectorType>(VecTy) &&
866 "Expect a vector type for interleaved memory op");
870 assert (WideBits > 0 &&
"Could not compute size of vector");
872 ((WideBits % 128U) ? ((WideBits / 128U) + 1) : (WideBits / 128U));
877 ((NumWideParts > NumElsPerVector) ? NumElsPerVector : NumWideParts);
880 unsigned NumOperands =
886 int NumPermutes = NumSrcParts * NumOperands;
889 return NumWideParts + NumPermutes;
constexpr bool isUInt< 32 >(uint64_t x)
This class is the base class for the comparison instructions.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
uint64_t getZExtValue() const
Get zero extended value.
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace)
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.
unsigned getNumOperands() const
The main scalar evolution driver.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
constexpr bool isInt< 16 >(int64_t x)
An instruction for reading from memory.
bool hasVectorEnhancements1() const
const HexagonInstrInfo * TII
const APInt & getValue() const
Return the constant as an APInt value reference.
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I)
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
unsigned getNumberOfRegisters(bool Vector)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
size_t size() const
size - Get the array size.
iterator_range< block_iterator > blocks() const
int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
The instances of the Type class are immutable: once they are created, they are never changed...
bool isVectorTy() const
True if this is an instance of VectorType.
This is an important base class in LLVM.
int64_t getSExtValue() const
Get sign extended value.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static const unsigned End
Value * getOperand(unsigned i) const
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 isRxSBGMask(uint64_t Mask, unsigned BitSize, unsigned &Start, unsigned &End) const
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
const SystemZInstrInfo * getInstrInfo() const override
bool hasPopulationCount() const
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
This is the shared class of boolean and integer constants.
constexpr bool isInt< 32 >(int64_t x)
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 * >())
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
int getIntImmCost(const APInt &Imm, Type *Ty)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
unsigned getVectorNumElements() const
Represents a single loop in the control flow graph.
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Establish a view to a call site for examination.
bool hasOneUse() const
Return true if there is exactly one user of this value.
unsigned getRegisterBitWidth(bool Vector) const
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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
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 * >())
This file describes how to lower LLVM code to machine code.
bool isVoidTy() const
Return true if this is 'void'.
unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy)