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);
332 unsigned Opcode,
Type *Ty,
349 const unsigned SDivCostEstimate = 4;
350 bool SDivPow2 =
false;
351 bool UDivPow2 =
false;
352 if ((Opcode == Instruction::SDiv || Opcode == Instruction::UDiv) &&
355 if (
const Constant *
C = dyn_cast<Constant>(Args[1])) {
357 CI = dyn_cast_or_null<const ConstantInt>(
C->getSplatValue());
363 if (Opcode == Instruction::SDiv)
371 assert (ST->
hasVector() &&
"getArithmeticInstrCost() called with vector type.");
377 if (Opcode == Instruction::Shl || Opcode == Instruction::LShr ||
378 Opcode == Instruction::AShr || UDivPow2) {
383 return (NumVectors * SDivCostEstimate);
389 if (Opcode == Instruction::FAdd || Opcode == Instruction::FSub ||
390 Opcode == Instruction::FMul || Opcode == Instruction::FDiv) {
391 switch (ScalarBits) {
415 if (Opcode == Instruction::FRem) {
418 if (VF == 2 && ScalarBits == 32)
427 if (Opcode == Instruction::FAdd || Opcode == Instruction::FSub ||
428 Opcode == Instruction::FMul || Opcode == Instruction::FDiv)
432 if (Opcode == Instruction::FRem)
435 if (Opcode == Instruction::LShr || Opcode == Instruction::AShr)
436 return (ScalarBits >= 32 ? 1 : 2 );
439 if (Opcode == Instruction::Or)
442 if (Opcode == Instruction::Xor && ScalarBits == 1)
449 return SDivCostEstimate;
452 if ((Opcode == Instruction::SDiv || Opcode == Instruction::SRem))
454 return (ScalarBits < 32 ? 4 : (ScalarBits == 32 ? 2 : 1));
456 if (Opcode == Instruction::UDiv || Opcode == Instruction::URem)
458 return (ScalarBits < 32 ? 4 : 2);
463 Opd1PropInfo, Opd2PropInfo, Args);
486 return (Index == 0 ? 0 : NumVectors);
493 return NumVectors - 1;
520 "Packing must reduce size of vector type.");
522 "Packing should not change number of elements.");
538 for (
unsigned P = 0;
P < Log2Diff; ++
P) {
559 "Should only be called with vector types.");
561 unsigned PackCost = 0;
565 if (SrcScalarBits > DstScalarBits)
568 else if (SrcScalarBits < DstScalarBits) {
571 PackCost = Log2Diff * DstNumParts;
573 PackCost += DstNumParts - 1;
582 Type *OpTy =
nullptr;
584 OpTy = CI->getOperand(0)->getType();
586 if (LogicI->getNumOperands() == 2)
587 if (
CmpInst *CI0 = dyn_cast<CmpInst>(LogicI->getOperand(0)))
588 if (isa<CmpInst>(LogicI->getOperand(1)))
589 OpTy = CI0->getOperand(0)->getType();
591 if (OpTy !=
nullptr) {
611 assert (ST->
hasVector() &&
"getCastInstrCost() called with vector type.");
617 if (Opcode == Instruction::Trunc) {
623 if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt) {
624 if (SrcScalarBits >= 8) {
630 unsigned NumSrcVectorOps =
631 (NumUnpacks > 1 ? (NumDstVectors - NumSrcVectors)
632 : (NumDstVectors / 2));
634 return (NumUnpacks * NumDstVectors) + NumSrcVectorOps;
636 else if (SrcScalarBits == 1) {
642 if (CmpOpTy !=
nullptr)
644 if (Opcode == Instruction::ZExt)
646 Cost += NumDstVectors;
651 if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP ||
652 Opcode == Instruction::FPToSI || Opcode == Instruction::FPToUI) {
657 if (SrcScalarBits == 64 && DstScalarBits == 64)
658 return NumDstVectors;
665 unsigned TotCost = VF * ScalarCost;
666 bool NeedsInserts =
true, NeedsExtracts =
true;
668 if (DstScalarBits == 128 &&
669 (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP))
670 NeedsInserts =
false;
671 if (SrcScalarBits == 128 &&
672 (Opcode == Instruction::FPToSI || Opcode == Instruction::FPToUI))
673 NeedsExtracts =
false;
678 if (VF == 2 && SrcScalarBits == 32 && DstScalarBits == 32)
684 if (Opcode == Instruction::FPTrunc) {
685 if (SrcScalarBits == 128)
688 return VF / 2 +
std::max(1U, VF / 4 );
691 if (Opcode == Instruction::FPExt) {
692 if (SrcScalarBits == 32 && DstScalarBits == 64) {
705 if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP)
706 return (SrcScalarBits >= 32 ? 1 : 2 );
708 if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
713 if (Opcode == Instruction::SExt)
714 Cost = (DstScalarBits < 64 ? 3 : 4);
715 if (Opcode == Instruction::ZExt)
732 assert (ST->
hasVector() &&
"getCmpSelInstrCost() called with vector type.");
736 if (Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) {
737 unsigned PredicateExtraCost = 0;
741 case CmpInst::Predicate::ICMP_NE:
742 case CmpInst::Predicate::ICMP_UGE:
743 case CmpInst::Predicate::ICMP_ULE:
744 case CmpInst::Predicate::ICMP_SGE:
745 case CmpInst::Predicate::ICMP_SLE:
746 PredicateExtraCost = 1;
748 case CmpInst::Predicate::FCMP_ONE:
749 case CmpInst::Predicate::FCMP_ORD:
750 case CmpInst::Predicate::FCMP_UEQ:
751 case CmpInst::Predicate::FCMP_UNO:
752 PredicateExtraCost = 2;
764 unsigned Cost = (NumVecs_cmp * (CmpCostPerVector + PredicateExtraCost));
772 unsigned PackCost = 0;
774 if (CmpOpTy !=
nullptr)
783 case Instruction::ICmp: {
804 return ((Index % 2 == 0) ? 1 : 0);
806 if (Opcode == Instruction::ExtractElement) {
828 bool FoldsLoad =
false;
830 case Instruction::ICmp:
832 case Instruction::Sub:
833 case Instruction::Mul:
834 case Instruction::SDiv:
835 case Instruction::UDiv:
836 case Instruction::And:
837 case Instruction::Or:
838 case Instruction::Xor:
846 FoldsLoad = (Bits == 32 || Bits == 64);
852 "Expected to only handle binops.");
856 for (
unsigned i = 0; i < 2; ++i) {
883 assert(isa<VectorType>(VecTy) &&
884 "Expect a vector type for interleaved memory op");
888 assert (WideBits > 0 &&
"Could not compute size of vector");
890 ((WideBits % 128U) ? ((WideBits / 128U) + 1) : (WideBits / 128U));
895 ((NumWideParts > NumElsPerVector) ? NumElsPerVector : NumWideParts);
898 unsigned NumOperands =
904 int NumPermutes = NumSrcParts * NumOperands;
907 return NumWideParts + NumPermutes;
constexpr bool isUInt< 32 >(uint64_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 * >())
This class is the base class for the comparison instructions.
uint64_t getZExtValue() const
Get zero extended value.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
Compute iterated dominance frontiers using a linear time algorithm.
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.
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.
bool isVectorTy() const
True if this is an instance of VectorType.
unsigned getBitWidth() const
Return the number of bits in the APInt.
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)
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.
unsigned getNumberOfRegisters(bool Vector)
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.
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)
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'.
int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
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...
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 hasVectorEnhancements1() const
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
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)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
unsigned getRegisterBitWidth(bool Vector) const
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.
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.
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.
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)
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
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.
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 *>())
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.
unsigned getVectorBitmaskConversionCost(Type *SrcTy, Type *DstTy)