LLVM 24.0.0git
PPCTargetTransformInfo.cpp
Go to the documentation of this file.
1//===-- PPCTargetTransformInfo.cpp - PPC specific TTI ---------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
16#include "llvm/IR/IntrinsicsPowerPC.h"
21#include <optional>
22
23using namespace llvm;
24
25#define DEBUG_TYPE "ppctti"
26
27static cl::opt<bool> PPCEVL("ppc-evl",
28 cl::desc("Allow EVL type vp.load/vp.store"),
29 cl::init(false), cl::Hidden);
30
31static cl::opt<bool> Pwr9EVL("ppc-pwr9-evl",
32 cl::desc("Allow vp.load and vp.store for pwr9"),
33 cl::init(false), cl::Hidden);
34
35static cl::opt<bool> VecMaskCost("ppc-vec-mask-cost",
36cl::desc("add masking cost for i1 vectors"), cl::init(true), cl::Hidden);
37
38static cl::opt<bool>
39 EnablePPCConstHoist("ppc-constant-hoisting",
40 cl::desc("enable constant hoisting on PPC"),
41 cl::init(true), cl::Hidden);
42
43static cl::opt<bool>
44EnablePPCColdCC("ppc-enable-coldcc", cl::Hidden, cl::init(false),
45 cl::desc("Enable using coldcc calling conv for cold "
46 "internal functions"));
47
48static cl::opt<bool>
49LsrNoInsnsCost("ppc-lsr-no-insns-cost", cl::Hidden, cl::init(false),
50 cl::desc("Do not add instruction count to lsr cost model"));
51
52// The latency of mtctr is only justified if there are more than 4
53// comparisons that will be removed as a result.
55 "ppc-min-ctr-loop-threshold", cl::init(4), cl::Hidden,
56 cl::desc("Loops with a constant trip count smaller than "
57 "this value will not use the count register."));
58
59//===----------------------------------------------------------------------===//
60//
61// PPC cost model.
62//
63//===----------------------------------------------------------------------===//
64
66PPCTTIImpl::getPopcntSupport(unsigned TyWidth) const {
67 assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
68 if (ST->hasPOPCNTD() != PPCSubtarget::POPCNTD_Unavailable && TyWidth <= 64)
69 return ST->hasPOPCNTD() == PPCSubtarget::POPCNTD_Slow ?
71 return TTI::PSK_Software;
72}
73
74std::optional<Instruction *>
76 Intrinsic::ID IID = II.getIntrinsicID();
77 switch (IID) {
78 default:
79 break;
80 case Intrinsic::ppc_altivec_lvx:
81 case Intrinsic::ppc_altivec_lvxl:
82 // Turn PPC lvx -> load if the pointer is known aligned.
84 II.getArgOperand(0), Align(16), IC.getDataLayout(), &II,
85 &IC.getAssumptionCache(), &IC.getDominatorTree()) >= 16) {
86 Value *Ptr = II.getArgOperand(0);
87 return new LoadInst(II.getType(), Ptr, "", false, Align(16));
88 }
89 break;
90 case Intrinsic::ppc_vsx_lxvw4x:
91 case Intrinsic::ppc_vsx_lxvd2x: {
92 // Turn PPC VSX loads into normal loads.
93 Value *Ptr = II.getArgOperand(0);
94 return new LoadInst(II.getType(), Ptr, Twine(""), false, Align(1));
95 }
96 case Intrinsic::ppc_altivec_stvx:
97 case Intrinsic::ppc_altivec_stvxl:
98 // Turn stvx -> store if the pointer is known aligned.
100 II.getArgOperand(1), Align(16), IC.getDataLayout(), &II,
101 &IC.getAssumptionCache(), &IC.getDominatorTree()) >= 16) {
102 Value *Ptr = II.getArgOperand(1);
103 return new StoreInst(II.getArgOperand(0), Ptr, false, Align(16));
104 }
105 break;
106 case Intrinsic::ppc_vsx_stxvw4x:
107 case Intrinsic::ppc_vsx_stxvd2x: {
108 // Turn PPC VSX stores into normal stores.
109 Value *Ptr = II.getArgOperand(1);
110 return new StoreInst(II.getArgOperand(0), Ptr, false, Align(1));
111 }
112 case Intrinsic::ppc_altivec_vperm:
113 // Turn vperm(V1,V2,mask) -> shuffle(V1,V2,mask) if mask is a constant.
114 // Note that ppc_altivec_vperm has a big-endian bias, so when creating
115 // a vectorshuffle for little endian, we must undo the transformation
116 // performed on vec_perm in altivec.h. That is, we must complement
117 // the permutation mask with respect to 31 and reverse the order of
118 // V1 and V2.
119 if (Constant *Mask = dyn_cast<Constant>(II.getArgOperand(2))) {
120 assert(cast<FixedVectorType>(Mask->getType())->getNumElements() == 16 &&
121 "Bad type for intrinsic!");
122
123 // Check that all of the elements are integer constants or undefs.
124 bool AllEltsOk = true;
125 for (unsigned I = 0; I != 16; ++I) {
126 Constant *Elt = Mask->getAggregateElement(I);
127 if (!Elt || !(isa<ConstantInt>(Elt) || isa<UndefValue>(Elt))) {
128 AllEltsOk = false;
129 break;
130 }
131 }
132
133 if (AllEltsOk) {
134 // Cast the input vectors to byte vectors.
135 Value *Op0 =
136 IC.Builder.CreateBitCast(II.getArgOperand(0), Mask->getType());
137 Value *Op1 =
138 IC.Builder.CreateBitCast(II.getArgOperand(1), Mask->getType());
139 Value *Result = PoisonValue::get(Op0->getType());
140
141 // Only extract each element once.
142 Value *ExtractedElts[32];
143 memset(ExtractedElts, 0, sizeof(ExtractedElts));
144
145 for (unsigned I = 0; I != 16; ++I) {
146 if (isa<UndefValue>(Mask->getAggregateElement(I)))
147 continue;
148 unsigned Idx =
149 cast<ConstantInt>(Mask->getAggregateElement(I))->getZExtValue();
150 Idx &= 31; // Match the hardware behavior.
151 if (DL.isLittleEndian())
152 Idx = 31 - Idx;
153
154 if (!ExtractedElts[Idx]) {
155 Value *Op0ToUse = (DL.isLittleEndian()) ? Op1 : Op0;
156 Value *Op1ToUse = (DL.isLittleEndian()) ? Op0 : Op1;
157 ExtractedElts[Idx] = IC.Builder.CreateExtractElement(
158 Idx < 16 ? Op0ToUse : Op1ToUse, Idx & 15);
159 }
160
161 // Insert this value into the result vector.
162 Result =
163 IC.Builder.CreateInsertElement(Result, ExtractedElts[Idx], I);
164 }
165 return CastInst::Create(Instruction::BitCast, Result, II.getType());
166 }
167 }
168 break;
169 }
170 return std::nullopt;
171}
172
176 return BaseT::getIntImmCost(Imm, Ty, CostKind);
177
178 assert(Ty->isIntegerTy());
179
180 unsigned BitSize = Ty->getPrimitiveSizeInBits();
181 if (BitSize == 0)
182 return ~0U;
183
184 if (Imm == 0)
185 return TTI::TCC_Free;
186
187 if (Imm.getBitWidth() <= 64) {
188 if (isInt<16>(Imm.getSExtValue()))
189 return TTI::TCC_Basic;
190
191 if (isInt<32>(Imm.getSExtValue())) {
192 // A constant that can be materialized using lis.
193 if ((Imm.getZExtValue() & 0xFFFF) == 0)
194 return TTI::TCC_Basic;
195
196 return 2 * TTI::TCC_Basic;
197 }
198 }
199
200 return 4 * TTI::TCC_Basic;
201}
202
205 const APInt &Imm, Type *Ty,
208 return BaseT::getIntImmCostIntrin(IID, Idx, Imm, Ty, CostKind);
209
210 assert(Ty->isIntegerTy());
211
212 unsigned BitSize = Ty->getPrimitiveSizeInBits();
213 if (BitSize == 0)
214 return ~0U;
215
216 switch (IID) {
217 default:
218 return TTI::TCC_Free;
219 case Intrinsic::sadd_with_overflow:
220 case Intrinsic::uadd_with_overflow:
221 case Intrinsic::ssub_with_overflow:
222 case Intrinsic::usub_with_overflow:
223 if ((Idx == 1) && Imm.getBitWidth() <= 64 && isInt<16>(Imm.getSExtValue()))
224 return TTI::TCC_Free;
225 break;
226 case Intrinsic::experimental_stackmap:
227 if ((Idx < 2) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue())))
228 return TTI::TCC_Free;
229 break;
230 case Intrinsic::experimental_patchpoint_void:
231 case Intrinsic::experimental_patchpoint:
232 if ((Idx < 4) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue())))
233 return TTI::TCC_Free;
234 break;
235 }
237}
238
239InstructionCost PPCTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
240 const APInt &Imm, Type *Ty,
242 Instruction *Inst) const {
244 return BaseT::getIntImmCostInst(Opcode, Idx, Imm, Ty, CostKind, Inst);
245
246 assert(Ty->isIntegerTy());
247
248 unsigned BitSize = Ty->getPrimitiveSizeInBits();
249 if (BitSize == 0)
250 return ~0U;
251
252 unsigned ImmIdx = ~0U;
253 bool ShiftedFree = false, RunFree = false, UnsignedFree = false,
254 ZeroFree = false;
255 switch (Opcode) {
256 default:
257 return TTI::TCC_Free;
258 case Instruction::GetElementPtr:
259 // Always hoist the base address of a GetElementPtr. This prevents the
260 // creation of new constants for every base constant that gets constant
261 // folded with the offset.
262 if (Idx == 0)
263 return 2 * TTI::TCC_Basic;
264 return TTI::TCC_Free;
265 case Instruction::And:
266 RunFree = true; // (for the rotate-and-mask instructions)
267 [[fallthrough]];
268 case Instruction::Add:
269 case Instruction::Or:
270 case Instruction::Xor:
271 ShiftedFree = true;
272 [[fallthrough]];
273 case Instruction::Sub:
274 case Instruction::Mul:
275 case Instruction::Shl:
276 case Instruction::LShr:
277 case Instruction::AShr:
278 ImmIdx = 1;
279 break;
280 case Instruction::ICmp:
281 UnsignedFree = true;
282 ImmIdx = 1;
283 // Zero comparisons can use record-form instructions.
284 [[fallthrough]];
285 case Instruction::Select:
286 ZeroFree = true;
287 break;
288 case Instruction::PHI:
289 case Instruction::Call:
290 case Instruction::Ret:
291 case Instruction::Load:
292 case Instruction::Store:
293 break;
294 }
295
296 if (ZeroFree && Imm == 0)
297 return TTI::TCC_Free;
298
299 if (Idx == ImmIdx && Imm.getBitWidth() <= 64) {
300 if (isInt<16>(Imm.getSExtValue()))
301 return TTI::TCC_Free;
302
303 if (RunFree) {
304 if (Imm.getBitWidth() <= 32 &&
305 (isShiftedMask_32(Imm.getZExtValue()) ||
306 isShiftedMask_32(~Imm.getZExtValue())))
307 return TTI::TCC_Free;
308
309 if (ST->isPPC64() &&
310 (isShiftedMask_64(Imm.getZExtValue()) ||
311 isShiftedMask_64(~Imm.getZExtValue())))
312 return TTI::TCC_Free;
313 }
314
315 if (UnsignedFree && isUInt<16>(Imm.getZExtValue()))
316 return TTI::TCC_Free;
317
318 if (ShiftedFree && (Imm.getZExtValue() & 0xFFFF) == 0)
319 return TTI::TCC_Free;
320 }
321
323}
324
325// Check if the current Type is an MMA vector type. Valid MMA types are
326// v256i1 and v512i1 respectively.
327static bool isMMAType(Type *Ty) {
328 return Ty->isVectorTy() && (Ty->getScalarSizeInBits() == 1) &&
329 (Ty->getPrimitiveSizeInBits() > 128);
330}
331
335 // We already implement getCastInstrCost and getMemoryOpCost where we perform
336 // the vector adjustment there.
337 if (isa<CastInst>(U) || isa<LoadInst>(U) || isa<StoreInst>(U))
339
340 if (U->getType()->isVectorTy()) {
341 // Instructions that need to be split should cost more.
342 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(U->getType());
343 return LT.first * BaseT::getInstructionCost(U, Operands, CostKind);
344 }
345
347}
348
350 AssumptionCache &AC,
351 TargetLibraryInfo *LibInfo,
352 HardwareLoopInfo &HWLoopInfo) const {
353 const PPCTargetMachine &TM = ST->getTargetMachine();
354 TargetSchedModel SchedModel;
355 SchedModel.init(ST);
356
357 // Do not convert small short loops to CTR loop.
358 unsigned ConstTripCount = SE.getSmallConstantTripCount(L);
359 if (ConstTripCount && ConstTripCount < SmallCTRLoopThreshold) {
361 CodeMetrics::collectEphemeralValues(L, &AC, EphValues);
362 InstructionCost NumInsts;
363 for (BasicBlock *BB : L->blocks()) {
364 for (Instruction &I : *BB) {
365 if (EphValues.count(&I))
366 continue;
367 SmallVector<const Value *, 4> Operands(I.operand_values());
369 }
370 }
371 // 6 is an approximate latency for the mtctr instruction.
372 if (NumInsts <= (6 * SchedModel.getIssueWidth()))
373 return false;
374 }
375
376 // Check that there is no hardware loop related intrinsics in the loop.
377 for (auto *BB : L->getBlocks())
378 for (auto &I : *BB)
379 if (auto *Call = dyn_cast<IntrinsicInst>(&I))
380 if (Call->getIntrinsicID() == Intrinsic::set_loop_iterations ||
381 Call->getIntrinsicID() == Intrinsic::loop_decrement)
382 return false;
383
384 SmallVector<BasicBlock*, 4> ExitingBlocks;
385 L->getExitingBlocks(ExitingBlocks);
386
387 // If there is an exit edge known to be frequently taken,
388 // we should not transform this loop.
389 for (auto &BB : ExitingBlocks) {
390 Instruction *TI = BB->getTerminator();
391 if (!TI) continue;
392
393 if (CondBrInst *BI = dyn_cast<CondBrInst>(TI)) {
394 uint64_t TrueWeight = 0, FalseWeight = 0;
395 if (!extractBranchWeights(*BI, TrueWeight, FalseWeight))
396 continue;
397
398 // If the exit path is more frequent than the loop path,
399 // we return here without further analysis for this loop.
400 bool TrueIsExit = !L->contains(BI->getSuccessor(0));
401 if (( TrueIsExit && FalseWeight < TrueWeight) ||
402 (!TrueIsExit && FalseWeight > TrueWeight))
403 return false;
404 }
405 }
406
407 LLVMContext &C = L->getHeader()->getContext();
408 HWLoopInfo.CountType = TM.isPPC64() ?
410 HWLoopInfo.LoopDecrement = ConstantInt::get(HWLoopInfo.CountType, 1);
411 return true;
412}
413
416 OptimizationRemarkEmitter *ORE) const {
417 if (ST->getCPUDirective() == PPC::DIR_A2) {
418 // The A2 is in-order with a deep pipeline, and concatenation unrolling
419 // helps expose latency-hiding opportunities to the instruction scheduler.
420 UP.Partial = UP.Runtime = true;
421
422 // We unroll a lot on the A2 (hundreds of instructions), and the benefits
423 // often outweigh the cost of a division to compute the trip count.
424 UP.AllowExpensiveTripCount = true;
425 }
426
427 BaseT::getUnrollingPreferences(L, SE, UP, ORE);
428}
429
434// This function returns true to allow using coldcc calling convention.
435// Returning true results in coldcc being used for functions which are cold at
436// all call sites when the callers of the functions are not calling any other
437// non coldcc functions.
441
442bool PPCTTIImpl::enableAggressiveInterleaving(bool LoopHasReductions) const {
443 // On the A2, always unroll aggressively.
444 if (ST->getCPUDirective() == PPC::DIR_A2)
445 return true;
446
447 return LoopHasReductions;
448}
449
451PPCTTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
453 if (getST()->hasAltivec())
454 Options.LoadSizes = {16, 8, 4, 2, 1};
455 else
456 Options.LoadSizes = {8, 4, 2, 1};
457
458 Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
459 return Options;
460}
461
463
464unsigned PPCTTIImpl::getNumberOfRegisters(unsigned ClassID) const {
465 assert(ClassID == GPRRC || ClassID == FPRRC ||
466 ClassID == VRRC || ClassID == VSXRC);
467 if (ST->hasVSX()) {
468 assert(ClassID == GPRRC || ClassID == VSXRC || ClassID == VRRC);
469 return ClassID == VSXRC ? 64 : 32;
470 }
471 assert(ClassID == GPRRC || ClassID == FPRRC || ClassID == VRRC);
472 return 32;
473}
474
476 if (Vector)
477 return ST->hasVSX() ? VSXRC : VRRC;
478 if (Ty &&
479 (Ty->getScalarType()->isFloatTy() || Ty->getScalarType()->isDoubleTy()))
480 return ST->hasVSX() ? VSXRC : FPRRC;
481 if (Ty && (Ty->getScalarType()->isFP128Ty() ||
482 Ty->getScalarType()->isPPC_FP128Ty()))
483 return VRRC;
484 if (Ty && Ty->getScalarType()->isHalfTy())
485 return VSXRC;
486 return GPRRC;
487}
488
489const char* PPCTTIImpl::getRegisterClassName(unsigned ClassID) const {
490
491 switch (ClassID) {
492 default:
493 llvm_unreachable("unknown register class");
494 return "PPC::unknown register class";
495 case GPRRC: return "PPC::GPRRC";
496 case FPRRC: return "PPC::FPRRC";
497 case VRRC: return "PPC::VRRC";
498 case VSXRC: return "PPC::VSXRC";
499 }
500}
501
504 switch (K) {
506 return TypeSize::getFixed(ST->isPPC64() ? 64 : 32);
508 return TypeSize::getFixed(ST->hasAltivec() ? 128 : 0);
510 return TypeSize::getScalable(0);
511 }
512
513 llvm_unreachable("Unsupported register kind");
514}
515
517 // Starting with P7 we have a cache line size of 128.
518 unsigned Directive = ST->getCPUDirective();
519 // Assume that Future CPU has the same cache line size as the others.
523 return 128;
524
525 // On other processors return a default of 64 bytes.
526 return 64;
527}
528
530 return 300;
531}
532
534 bool HasUnorderedReductions) const {
535 unsigned Directive = ST->getCPUDirective();
536 // The 440 has no SIMD support, but floating-point instructions
537 // have a 5-cycle latency, so unroll by 5x for latency hiding.
538 if (Directive == PPC::DIR_440)
539 return 5;
540
541 // The A2 has no SIMD support, but floating-point instructions
542 // have a 6-cycle latency, so unroll by 6x for latency hiding.
543 if (Directive == PPC::DIR_A2)
544 return 6;
545
546 // FIXME: For lack of any better information, do no harm...
548 return 1;
549
550 // For P7 and P8, floating-point instructions have a 6-cycle latency and
551 // there are two execution units, so unroll by 12x for latency hiding.
552 // FIXME: the same for P9 as previous gen until POWER9 scheduling is ready
553 // FIXME: the same for P10 as previous gen until POWER10 scheduling is ready
554 // Assume that future is the same as the others.
558 return 12;
559
560 // For most things, modern systems have two execution units (and
561 // out-of-order execution).
562 return 2;
563}
564
565// Returns a cost adjustment factor to adjust the cost of vector instructions
566// on targets which there is overlap between the vector and scalar units,
567// thereby reducing the overall throughput of vector code wrt. scalar code.
568// An invalid instruction cost is returned if the type is an MMA vector type.
570 Type *Ty1,
571 Type *Ty2) const {
572 // If the vector type is of an MMA type (v256i1, v512i1), an invalid
573 // instruction cost is returned. This is to signify to other cost computing
574 // functions to return the maximum instruction cost in order to prevent any
575 // opportunities for the optimizer to produce MMA types within the IR.
576 if (isMMAType(Ty1))
578
579 if (!ST->vectorsUseTwoUnits() || !Ty1->isVectorTy())
580 return InstructionCost(1);
581
582 std::pair<InstructionCost, MVT> LT1 = getTypeLegalizationCost(Ty1);
583 // If type legalization involves splitting the vector, we don't want to
584 // double the cost at every step - only the last step.
585 if (LT1.first != 1 || !LT1.second.isVector())
586 return InstructionCost(1);
587
588 int ISD = TLI->InstructionOpcodeToISD(Opcode);
589 if (TLI->isOperationExpand(ISD, LT1.second))
590 return InstructionCost(1);
591
592 if (Ty2) {
593 std::pair<InstructionCost, MVT> LT2 = getTypeLegalizationCost(Ty2);
594 if (LT2.first != 1 || !LT2.second.isVector())
595 return InstructionCost(1);
596 }
597
598 return InstructionCost(2);
599}
600
602 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
604 ArrayRef<const Value *> Args, const Instruction *CtxI) const {
605 assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode");
606
607 InstructionCost CostFactor = vectorCostAdjustmentFactor(Opcode, Ty, nullptr);
608 if (!CostFactor.isValid())
610
611 // TODO: Handle more cost kinds.
613 return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
614 Op2Info, Args, CtxI);
615
616 // Fallback to the default implementation.
618 Opcode, Ty, CostKind, Op1Info, Op2Info);
619 return Cost * CostFactor;
620}
621
623 TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
625 VectorType *SubTp, ArrayRef<const Value *> Args, const Instruction *CtxI,
626 TTI::VectorInstrContext VIC) const {
627
628 InstructionCost CostFactor =
629 vectorCostAdjustmentFactor(Instruction::ShuffleVector, SrcTy, nullptr);
630 if (!CostFactor.isValid())
632
633 // Legalize the type.
634 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(SrcTy);
635
636 // PPC, for both Altivec/VSX, support cheap arbitrary permutations
637 // (at least in the sense that there need only be one non-loop-invariant
638 // instruction). We need one such shuffle instruction for each actual
639 // register (this is not true for arbitrary shuffles, but is true for the
640 // structured types of shuffles covered by TTI::ShuffleKind).
641 return LT.first * CostFactor;
642}
643
646 const Instruction *I) const {
648 return Opcode == Instruction::PHI ? 0 : 1;
649 // Branches are assumed to be predicted.
650 return 0;
651}
652
654 Type *Src,
657 const Instruction *I) const {
658 assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode");
659
660 InstructionCost CostFactor = vectorCostAdjustmentFactor(Opcode, Dst, Src);
661 if (!CostFactor.isValid())
663
665 BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
666 Cost *= CostFactor;
667 // TODO: Allow non-throughput costs that aren't binary.
669 return Cost == 0 ? 0 : 1;
670 return Cost;
671}
672
674 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
676 TTI::OperandValueInfo Op2Info, const Instruction *I) const {
677 InstructionCost CostFactor =
678 vectorCostAdjustmentFactor(Opcode, ValTy, nullptr);
679 if (!CostFactor.isValid())
681
683 Opcode, ValTy, CondTy, VecPred, CostKind, Op1Info, Op2Info, I);
684 // TODO: Handle other cost kinds.
686 return Cost;
687 return Cost * CostFactor;
688}
689
691 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
692 const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC) const {
693 assert(Val->isVectorTy() && "This must be a vector type");
694
695 int ISD = TLI->InstructionOpcodeToISD(Opcode);
696 assert(ISD && "Invalid opcode");
697
698 InstructionCost CostFactor = vectorCostAdjustmentFactor(Opcode, Val, nullptr);
699 if (!CostFactor.isValid())
701
703 BaseT::getVectorInstrCost(Opcode, Val, CostKind, Index, Op0, Op1, VIC);
704 Cost *= CostFactor;
705
706 if (ST->hasVSX() && Val->getScalarType()->isDoubleTy()) {
707 // Double-precision scalars are already located in index #0 (or #1 if LE).
709 Index == (ST->isLittleEndian() ? 1 : 0))
710 return 0;
711
712 return Cost;
713 }
714 if (Val->getScalarType()->isIntegerTy()) {
715 unsigned EltSize = Val->getScalarSizeInBits();
716 // Computing on 1 bit values requires extra mask or compare operations.
717 unsigned MaskCostForOneBitSize = (VecMaskCost && EltSize == 1) ? 1 : 0;
718 // Computing on non const index requires extra mask or compare operations.
719 unsigned MaskCostForIdx = (Index != -1U) ? 0 : 1;
720 if (ST->hasP9Altivec()) {
721 // P10 has vxform insert which can handle non const index. The
722 // MaskCostForIdx is for masking the index.
723 // P9 has insert for const index. A move-to VSR and a permute/insert.
724 // Assume vector operation cost for both (cost will be 2x on P9).
726 if (ST->hasP10Vector())
727 return CostFactor + MaskCostForIdx;
728 if (Index != -1U)
729 return 2 * CostFactor;
730 } else if (ISD == ISD::EXTRACT_VECTOR_ELT) {
731 // It's an extract. Maybe we can do a cheap move-from VSR.
732 unsigned EltSize = Val->getScalarSizeInBits();
733 // P9 has both mfvsrd and mfvsrld for 64 bit integer.
734 if (EltSize == 64 && Index != -1U)
735 return 1;
736 if (EltSize == 32) {
737 unsigned MfvsrwzIndex = ST->isLittleEndian() ? 2 : 1;
738 if (Index == MfvsrwzIndex)
739 return 1;
740
741 // For other indexs like non const, P9 has vxform extract. The
742 // MaskCostForIdx is for masking the index.
743 return CostFactor + MaskCostForIdx;
744 }
745
746 // We need a vector extract (or mfvsrld). Assume vector operation cost.
747 // The cost of the load constant for a vector extract is disregarded
748 // (invariant, easily schedulable).
749 return CostFactor + MaskCostForOneBitSize + MaskCostForIdx;
750 }
751 } else if (ST->hasDirectMove() && Index != -1U) {
752 // Assume permute has standard cost.
753 // Assume move-to/move-from VSR have 2x standard cost.
755 return 3;
756 return 3 + MaskCostForOneBitSize;
757 }
758 }
759
760 // Estimated cost of a load-hit-store delay. This was obtained
761 // experimentally as a minimum needed to prevent unprofitable
762 // vectorization for the paq8p benchmark. It may need to be
763 // raised further if other unprofitable cases remain.
764 unsigned LHSPenalty = 2;
766 LHSPenalty += 7;
767
768 // Vector element insert/extract with Altivec is very expensive,
769 // because they require store and reload with the attendant
770 // processor stall for load-hit-store. Until VSX is available,
771 // these need to be estimated as very costly.
774 return LHSPenalty + Cost;
775
776 return Cost;
777}
778
780 Align Alignment,
781 unsigned AddressSpace,
784 const Instruction *I) const {
785 InstructionCost CostFactor = vectorCostAdjustmentFactor(Opcode, Src, nullptr);
786 if (!CostFactor.isValid())
788
789 if (TLI->getValueType(DL, Src, true) == MVT::Other)
790 return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
791 CostKind);
792 // Legalize the type.
793 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Src);
794 assert((Opcode == Instruction::Load || Opcode == Instruction::Store) &&
795 "Invalid Opcode");
796
798 BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, CostKind);
799 // TODO: Handle other cost kinds.
801 return Cost;
802
803 Cost *= CostFactor;
804
805 bool IsAltivecType = ST->hasAltivec() &&
806 (LT.second == MVT::v16i8 || LT.second == MVT::v8i16 ||
807 LT.second == MVT::v4i32 || LT.second == MVT::v4f32);
808 bool IsVSXType = ST->hasVSX() &&
809 (LT.second == MVT::v2f64 || LT.second == MVT::v2i64);
810
811 // VSX has 32b/64b load instructions. Legalization can handle loading of
812 // 32b/64b to VSR correctly and cheaply. But BaseT::getMemoryOpCost and
813 // PPCTargetLowering can't compute the cost appropriately. So here we
814 // explicitly check this case. There are also corresponding store
815 // instructions.
816 unsigned MemBits = Src->getPrimitiveSizeInBits();
817 unsigned SrcBytes = LT.second.getStoreSize();
818 if (ST->hasVSX() && IsAltivecType) {
819 if (MemBits == 64 || (ST->hasP8Vector() && MemBits == 32))
820 return 1;
821
822 // Use lfiwax/xxspltw
823 if (Opcode == Instruction::Load && MemBits == 32 && Alignment < SrcBytes)
824 return 2;
825 }
826
827 // Aligned loads and stores are easy.
828 if (!SrcBytes || Alignment >= SrcBytes)
829 return Cost;
830
831 // If we can use the permutation-based load sequence, then this is also
832 // relatively cheap (not counting loop-invariant instructions): one load plus
833 // one permute (the last load in a series has extra cost, but we're
834 // neglecting that here). Note that on the P7, we could do unaligned loads
835 // for Altivec types using the VSX instructions, but that's more expensive
836 // than using the permutation-based load sequence. On the P8, that's no
837 // longer true.
838 if (Opcode == Instruction::Load && (!ST->hasP8Vector() && IsAltivecType) &&
839 Alignment >= LT.second.getScalarType().getStoreSize())
840 return Cost + LT.first; // Add the cost of the permutations.
841
842 // For VSX, we can do unaligned loads and stores on Altivec/VSX types. On the
843 // P7, unaligned vector loads are more expensive than the permutation-based
844 // load sequence, so that might be used instead, but regardless, the net cost
845 // is about the same (not counting loop-invariant instructions).
846 if (IsVSXType || (ST->hasVSX() && IsAltivecType))
847 return Cost;
848
849 // Newer PPC supports unaligned memory access.
850 if (TLI->allowsMisalignedMemoryAccesses(LT.second, 0))
851 return Cost;
852
853 // PPC in general does not support unaligned loads and stores. They'll need
854 // to be decomposed based on the alignment factor.
855
856 // Add the cost of each scalar load or store.
857 Cost += LT.first * ((SrcBytes / Alignment.value()) - 1);
858
859 // For a vector type, there is also scalarization overhead (only for
860 // stores, loads are expanded using the vector-load + permutation sequence,
861 // which is much less expensive).
862 if (Src->isVectorTy() && Opcode == Instruction::Store)
863 for (int I = 0, E = cast<FixedVectorType>(Src)->getNumElements(); I < E;
864 ++I)
865 Cost +=
866 getVectorInstrCost(Instruction::ExtractElement, Src, CostKind, I,
867 nullptr, nullptr, TTI::VectorInstrContext::None);
868
869 return Cost;
870}
871
873 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
874 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
875 bool UseMaskForCond, bool UseMaskForGaps) const {
876 InstructionCost CostFactor =
877 vectorCostAdjustmentFactor(Opcode, VecTy, nullptr);
878 if (!CostFactor.isValid())
880
881 if (UseMaskForCond || UseMaskForGaps)
882 return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
883 Alignment, AddressSpace, CostKind,
884 UseMaskForCond, UseMaskForGaps);
885
886 assert(isa<VectorType>(VecTy) &&
887 "Expect a vector type for interleaved memory op");
888
889 // Legalize the type.
890 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(VecTy);
891
892 // Firstly, the cost of load/store operation.
894 getMemoryOpCost(Opcode, VecTy, Alignment, AddressSpace, CostKind);
895
896 // PPC, for both Altivec/VSX, support cheap arbitrary permutations
897 // (at least in the sense that there need only be one non-loop-invariant
898 // instruction). For each result vector, we need one shuffle per incoming
899 // vector (except that the first shuffle can take two incoming vectors
900 // because it does not need to take itself).
901 Cost += Factor*(LT.first-1);
902
903 return Cost;
904}
905
909
912
913 if (ICA.getID() == Intrinsic::vp_load) {
914 MemIntrinsicCostAttributes MICA(Intrinsic::masked_load, ICA.getReturnType(),
915 Align(1), 0);
917 }
918
919 if (ICA.getID() == Intrinsic::vp_store) {
920 MemIntrinsicCostAttributes MICA(Intrinsic::masked_store,
921 ICA.getArgTypes()[0], Align(1), 0);
923 }
924
926}
927
929 const Function *Callee,
930 ArrayRef<Type *> Types) const {
931
932 // We need to ensure that argument promotion does not
933 // attempt to promote pointers to MMA types (__vector_pair
934 // and __vector_quad) since these types explicitly cannot be
935 // passed as arguments. Both of these types are larger than
936 // the 128-bit Altivec vectors and have a scalar size of 1 bit.
937 if (!BaseT::areTypesABICompatible(Caller, Callee, Types))
938 return false;
939
940 return llvm::none_of(Types, [](Type *Ty) {
941 if (Ty->isSized())
942 return Ty->isIntOrIntVectorTy(1) && Ty->getPrimitiveSizeInBits() > 128;
943 return false;
944 });
945}
946
948 LoopInfo *LI, DominatorTree *DT,
949 AssumptionCache *AC,
950 TargetLibraryInfo *LibInfo) const {
951 // Process nested loops first.
952 for (Loop *I : *L)
953 if (canSaveCmp(I, BI, SE, LI, DT, AC, LibInfo))
954 return false; // Stop search.
955
956 HardwareLoopInfo HWLoopInfo(L);
957
958 if (!HWLoopInfo.canAnalyze(*LI))
959 return false;
960
961 if (!isHardwareLoopProfitable(L, *SE, *AC, LibInfo, HWLoopInfo))
962 return false;
963
964 if (!HWLoopInfo.isHardwareLoopCandidate(*SE, *LI, *DT))
965 return false;
966
967 *BI = HWLoopInfo.ExitBranch;
968 return true;
969}
970
972 const TargetTransformInfo::LSRCost &C2) const {
973 // PowerPC default behaviour here is "instruction number 1st priority".
974 // If LsrNoInsnsCost is set, call default implementation.
975 if (!LsrNoInsnsCost)
976 return std::tie(C1.Insns, C1.NumRegs, C1.AddRecCost, C1.NumIVMuls,
977 C1.NumBaseAdds, C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
978 std::tie(C2.Insns, C2.NumRegs, C2.AddRecCost, C2.NumIVMuls,
979 C2.NumBaseAdds, C2.ScaleCost, C2.ImmCost, C2.SetupCost);
981}
982
983bool PPCTTIImpl::isNumRegsMajorCostOfLSR() const { return false; }
984
986 // XCOFF hasn't implemented lowerRelativeReference, disable non-ELF for now.
987 if (!ST->isELFv2ABI())
988 return false;
990}
991
993 MemIntrinsicInfo &Info) const {
994 switch (Inst->getIntrinsicID()) {
995 case Intrinsic::ppc_altivec_lvx:
996 case Intrinsic::ppc_altivec_lvxl:
997 case Intrinsic::ppc_altivec_lvebx:
998 case Intrinsic::ppc_altivec_lvehx:
999 case Intrinsic::ppc_altivec_lvewx:
1000 case Intrinsic::ppc_vsx_lxvd2x:
1001 case Intrinsic::ppc_vsx_lxvw4x:
1002 case Intrinsic::ppc_vsx_lxvd2x_be:
1003 case Intrinsic::ppc_vsx_lxvw4x_be:
1004 case Intrinsic::ppc_vsx_lxvl:
1005 case Intrinsic::ppc_vsx_lxvll:
1006 case Intrinsic::ppc_vsx_lxvp: {
1007 Info.PtrVal = Inst->getArgOperand(0);
1008 Info.ReadMem = true;
1009 Info.WriteMem = false;
1010 return true;
1011 }
1012 case Intrinsic::ppc_altivec_stvx:
1013 case Intrinsic::ppc_altivec_stvxl:
1014 case Intrinsic::ppc_altivec_stvebx:
1015 case Intrinsic::ppc_altivec_stvehx:
1016 case Intrinsic::ppc_altivec_stvewx:
1017 case Intrinsic::ppc_vsx_stxvd2x:
1018 case Intrinsic::ppc_vsx_stxvw4x:
1019 case Intrinsic::ppc_vsx_stxvd2x_be:
1020 case Intrinsic::ppc_vsx_stxvw4x_be:
1021 case Intrinsic::ppc_vsx_stxvl:
1022 case Intrinsic::ppc_vsx_stxvll:
1023 case Intrinsic::ppc_vsx_stxvp: {
1024 Info.PtrVal = Inst->getArgOperand(1);
1025 Info.ReadMem = false;
1026 Info.WriteMem = true;
1027 return true;
1028 }
1029 case Intrinsic::ppc_stbcx:
1030 case Intrinsic::ppc_sthcx:
1031 case Intrinsic::ppc_stdcx:
1032 case Intrinsic::ppc_stwcx: {
1033 Info.PtrVal = Inst->getArgOperand(0);
1034 Info.ReadMem = false;
1035 Info.WriteMem = true;
1036 return true;
1037 }
1038 default:
1039 break;
1040 }
1041
1042 return false;
1043}
1044
1046 return TLI->supportsTailCallFor(CB);
1047}
1048
1049// Target hook used by CodeGen to decide whether to expand vector predication
1050// intrinsics into scalar operations or to use special ISD nodes to represent
1051// them. The Target will not see the intrinsics.
1055 unsigned Directive = ST->getCPUDirective();
1056 VPLegalization DefaultLegalization = BaseT::getVPLegalizationStrategy(PI);
1059 return DefaultLegalization;
1060
1061 if (!ST->isPPC64())
1062 return DefaultLegalization;
1063
1064 unsigned IID = PI.getIntrinsicID();
1065 if (IID != Intrinsic::vp_load && IID != Intrinsic::vp_store)
1066 return DefaultLegalization;
1067
1068 bool IsLoad = IID == Intrinsic::vp_load;
1069 Type *VecTy = IsLoad ? PI.getType() : PI.getOperand(0)->getType();
1070 EVT VT = TLI->getValueType(DL, VecTy, true);
1071 if (VT != MVT::v2i64 && VT != MVT::v4i32 && VT != MVT::v8i16 &&
1072 VT != MVT::v16i8)
1073 return DefaultLegalization;
1074
1075 auto IsAllTrueMask = [](Value *MaskVal) {
1076 if (Value *SplattedVal = getSplatValue(MaskVal))
1077 if (auto *ConstValue = dyn_cast<Constant>(SplattedVal))
1078 return ConstValue->isAllOnesValue();
1079 return false;
1080 };
1081 unsigned MaskIx = IsLoad ? 1 : 2;
1082 if (!IsAllTrueMask(PI.getOperand(MaskIx)))
1083 return DefaultLegalization;
1084
1086}
1087
1089 if (!PPCEVL || !ST->isPPC64())
1090 return false;
1091 unsigned CPU = ST->getCPUDirective();
1092 return CPU == PPC::DIR_PWR10 || CPU == PPC::DIR_PWR_FUTURE ||
1093 (Pwr9EVL && CPU == PPC::DIR_PWR9);
1094}
1095
1096bool PPCTTIImpl::isLegalMaskedLoad(Type *DataType, Align Alignment,
1097 unsigned AddressSpace,
1098 TTI::MaskKind MaskKind) const {
1099 if (!hasActiveVectorLength())
1100 return false;
1101
1102 auto IsLegalLoadWithLengthType = [](EVT VT) {
1103 if (VT != MVT::i64 && VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8)
1104 return false;
1105 return true;
1106 };
1107
1108 return IsLegalLoadWithLengthType(TLI->getValueType(DL, DataType, true));
1109}
1110
1112 unsigned AddressSpace,
1113 TTI::MaskKind MaskKind) const {
1114 return isLegalMaskedLoad(DataType, Alignment, AddressSpace);
1115}
1116
1120
1122
1123 unsigned Opcode;
1124 switch (MICA.getID()) {
1125 case Intrinsic::masked_load:
1126 Opcode = Instruction::Load;
1127 break;
1128 case Intrinsic::masked_store:
1129 Opcode = Instruction::Store;
1130 break;
1131 default:
1132 return BaseCost;
1133 }
1134
1135 Type *DataTy = MICA.getDataType();
1136 Align Alignment = MICA.getAlignment();
1137 unsigned AddressSpace = MICA.getAddressSpace();
1138
1139 auto VecTy = dyn_cast<FixedVectorType>(DataTy);
1140 if (!VecTy)
1141 return BaseCost;
1142 if (Opcode == Instruction::Load) {
1143 if (!isLegalMaskedLoad(VecTy->getScalarType(), Alignment, AddressSpace))
1144 return BaseCost;
1145 } else {
1146 if (!isLegalMaskedStore(VecTy->getScalarType(), Alignment, AddressSpace))
1147 return BaseCost;
1148 }
1149 if (VecTy->getPrimitiveSizeInBits() > 128)
1150 return BaseCost;
1151
1152 // Cost is 1 (scalar compare) + 1 (scalar select) +
1153 // 1 * vectorCostAdjustmentFactor (vector load with length)
1154 // Maybe + 1 (scalar shift)
1156 1 + 1 + vectorCostAdjustmentFactor(Opcode, DataTy, nullptr);
1157 if (ST->getCPUDirective() != PPC::DIR_PWR_FUTURE ||
1158 VecTy->getScalarSizeInBits() != 8)
1159 Cost += 1; // need shift for length
1160 return Cost;
1161}
1162
1164 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
1166 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
1167 TTI::TargetCostKind CostKind, std::optional<FastMathFlags> FMF) const {
1169
1170 if (!getST()->hasAltivec())
1171 return Invalid;
1172 if (Opcode != Instruction::Add)
1173 return Invalid;
1174
1175 EVT AccVT = TLI->getValueType(DL, AccumType, true);
1176 if (AccVT != MVT::i32)
1177 return Invalid;
1178
1179 Type *ATy = VectorType::get(InputTypeA, VF);
1180 EVT AVT = TLI->getValueType(DL, ATy, true);
1181
1182 if (OpAExtend != TTI::PR_SignExtend && OpAExtend != TTI::PR_ZeroExtend)
1183 return Invalid;
1184
1185 if (!BinOp) {
1186 // It's just an add, so only the LHS type matters. RHS is just 1s.
1187 if (AVT != MVT::v16i8 && AVT != MVT::v8i16)
1188 return Invalid;
1189 // We can do either (sext/-) or (zext/-) for v16i8 and v8i16
1190 return vectorCostAdjustmentFactor(Instruction::Add, ATy, nullptr);
1191 }
1192
1193 if (BinOp.value() != Instruction::Mul)
1194 return Invalid;
1195 if (InputTypeA != InputTypeB)
1196 return Invalid;
1197 if (OpBExtend != TTI::PR_SignExtend && OpBExtend != TTI::PR_ZeroExtend)
1198 return Invalid;
1199
1200 if (AVT == MVT::v16i8) {
1201 // For v16i8 PPC supports vmsumubm (zext/zext) and vmsummbm (sext/zext)
1202 if (OpBExtend != TTI::PR_ZeroExtend)
1203 return Invalid;
1204 } else if (AVT == MVT::v8i16) {
1205 // For v8i16 PPC supports vmsumuhm (zext/zext) and vmsumshm (sext/sext)
1206 if (OpAExtend != OpBExtend)
1207 return Invalid;
1208 } else {
1209 return Invalid;
1210 }
1211
1212 return vectorCostAdjustmentFactor(Instruction::Add, ATy, nullptr);
1213}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned Imm
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
TargetTransformInfo::VPLegalization VPLegalization
This file provides the interface for the instcombine pass implementation.
static LVOptions Options
Definition LVOptions.cpp:25
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
static cl::opt< unsigned > SmallCTRLoopThreshold("ppc-min-ctr-loop-threshold", cl::init(4), cl::Hidden, cl::desc("Loops with a constant trip count smaller than " "this value will not use the count register."))
static cl::opt< bool > PPCEVL("ppc-evl", cl::desc("Allow EVL type vp.load/vp.store"), cl::init(false), cl::Hidden)
static cl::opt< bool > VecMaskCost("ppc-vec-mask-cost", cl::desc("add masking cost for i1 vectors"), cl::init(true), cl::Hidden)
static cl::opt< bool > Pwr9EVL("ppc-pwr9-evl", cl::desc("Allow vp.load and vp.store for pwr9"), cl::init(false), cl::Hidden)
static bool isMMAType(Type *Ty)
static cl::opt< bool > EnablePPCConstHoist("ppc-constant-hoisting", cl::desc("enable constant hoisting on PPC"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnablePPCColdCC("ppc-enable-coldcc", cl::Hidden, cl::init(false), cl::desc("Enable using coldcc calling conv for cold " "internal functions"))
static cl::opt< bool > LsrNoInsnsCost("ppc-lsr-no-insns-cost", cl::Hidden, cl::init(false), cl::desc("Do not add instruction count to lsr cost model"))
This file a TargetTransformInfoImplBase conforming object specific to the PPC target machine.
This file contains the declarations for profiling metadata utility functions.
SI Fold Operands
This file describes how to lower LLVM code to machine code.
This pass exposes codegen information to IR-level passes.
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
bool shouldBuildRelLookupTables() const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Opd2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr) const override
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const override
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
std::pair< InstructionCost, MVT > getTypeLegalizationCost(Type *Ty) const
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const override
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Value * getArgOperand(unsigned i) const
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
Conditional Branch instruction.
This is an important base class in LLVM.
Definition Constant.h:43
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2678
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2666
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2252
The core instruction combiner logic.
const DataLayout & getDataLayout() const
DominatorTree & getDominatorTree() const
AssumptionCache & getAssumptionCache() const
static InstructionCost getInvalid(CostType Val=0)
static InstructionCost getMax()
const SmallVectorImpl< Type * > & getArgTypes() const
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:71
An instruction for reading from memory.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Information for memory intrinsic cost model.
The optimization diagnostic interface.
bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1, const TargetTransformInfo::LSRCost &C2) const override
InstructionCost vectorCostAdjustmentFactor(unsigned Opcode, Type *Ty1, Type *Ty2) const
unsigned getMaxInterleaveFactor(ElementCount VF, bool HasUnorderedReductions) const override
InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, TTI::PartialReductionExtendKind OpAExtend, TTI::PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp, TTI::TargetCostKind CostKind, std::optional< FastMathFlags > FMF) const override
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
bool isLegalMaskedLoad(Type *DataType, Align Alignment, unsigned AddressSpace, TTI::MaskKind MaskKind=TTI::MaskKind::VariableOrConstantMask) const override
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
bool enableInterleavedAccessVectorization() const override
unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const override
TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override
unsigned getCacheLineSize() const override
bool hasActiveVectorLength() const override
InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const override
Get memory intrinsic cost based on arguments.
bool useColdCCForColdCall(Function &F) const override
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr) const override
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const override
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const override
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override
bool isLegalMaskedStore(Type *DataType, Align Alignment, unsigned AddressSpace, TTI::MaskKind MaskKind=TTI::MaskKind::VariableOrConstantMask) const override
bool isNumRegsMajorCostOfLSR() const override
unsigned getPrefetchDistance() const override
TargetTransformInfo::VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const override
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
unsigned getNumberOfRegisters(unsigned ClassID) const override
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo) const override
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr) const override
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, TTI::TargetCostKind CostKind, ArrayRef< int > Mask, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
Get intrinsic cost based on arguments.
const char * getRegisterClassName(unsigned ClassID) const override
InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind) const override
bool shouldBuildRelLookupTables() const override
bool supportsTailCallFor(const CallBase *CB) const override
bool canSaveCmp(Loop *L, CondBrInst **BI, ScalarEvolution *SE, LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC, TargetLibraryInfo *LibInfo) const override
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
bool areTypesABICompatible(const Function *Caller, const Function *Callee, ArrayRef< Type * > Types) const override
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
bool enableAggressiveInterleaving(bool LoopHasReductions) const override
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
std::optional< Instruction * > instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const override
Common code between 32-bit and 64-bit PowerPC targets.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
The main scalar evolution driver.
LLVM_ABI unsigned getSmallConstantTripCount(const Loop *L)
Returns the exact trip count of the loop if we can compute it, and the result is a small constant.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
Provide an instruction scheduling machine model to CodeGen passes.
unsigned getIssueWidth() const
Maximum number of micro-ops that may be scheduled per cycle.
LLVM_ABI void init(const TargetSubtargetInfo *TSInfo, bool EnableSModel=true, bool EnableSItins=true)
Initialize the machine model for instruction scheduling.
virtual TargetTransformInfo::VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const
virtual InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const
virtual InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr) const
virtual InstructionCost getInstructionCost(const User *U, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind) const
virtual bool isLSRCostLess(const TTI::LSRCost &C1, const TTI::LSRCost &C2) const
virtual InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const
virtual bool areTypesABICompatible(const Function *Caller, const Function *Callee, ArrayRef< Type * > Types) const
MaskKind
Some targets only support masked load/store with a constant mask.
TargetCostKind
The kind of cost model.
@ TCK_RecipThroughput
Reciprocal throughput.
@ TCK_CodeSize
Instruction code size.
PopcntSupportKind
Flags indicating the kind of support for population count.
llvm::VectorInstrContext VectorInstrContext
@ TCC_Free
Expected to fold away in lowering.
@ TCC_Basic
The cost of a typical 'add' instruction.
ShuffleKind
The various kinds of shuffle patterns for vector queries.
CastContextHint
Represents a hint about the context in which a cast is used.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:339
static constexpr TypeSize getScalable(ScalarTy MinimumSize)
Definition TypeSize.h:342
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:300
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:283
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:363
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.cpp:222
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition Type.h:158
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
Value * getOperand(unsigned i) const
Definition User.h:207
This is the common base class for vector predication intrinsics.
static LLVM_ABI bool isVPIntrinsic(Intrinsic::ID)
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
Base class of all SIMD vector types.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ISD namespace - This namespace contains an enum which represents all of the SelectionDAG node types a...
Definition ISDOpcodes.h:26
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition ISDOpcodes.h:581
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition ISDOpcodes.h:570
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
InstructionCost Cost
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
LLVM_ABI Align getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
Definition Local.cpp:1556
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
constexpr bool isShiftedMask_32(uint32_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (32 bit ver...
Definition MathExtras.h:268
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
Definition MathExtras.h:274
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:280
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1769
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static LLVM_ABI void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value * > &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop).
Extended Value Type.
Definition ValueTypes.h:35
Attributes of a target dependent hardware loop.
LLVM_ABI bool canAnalyze(LoopInfo &LI)
LLVM_ABI bool isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, bool ForceNestedLoop=false, bool ForceHardwareLoopPHI=false)
Information about a load/store intrinsic defined by the target.
unsigned Insns
TODO: Some of these could be merged.
Returns options for expansion of memcmp. IsZeroCmp is.
Parameters that control the generic loop unrolling transformation.
bool Runtime
Allow runtime unrolling (unrolling of loops to expand the size of the loop body even when the number ...
bool Partial
Allow partial unrolling (unrolling of loops to expand the size of the loop body, not only to eliminat...
bool AllowExpensiveTripCount
Allow emitting expensive instructions (such as divisions) when computing the trip count of a loop for...