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"
20#include <optional>
21
22using namespace llvm;
23
24#define DEBUG_TYPE "ppctti"
25
26//===----------------------------------------------------------------------===//
27//
28// PPC cost model.
29//
30//===----------------------------------------------------------------------===//
31
33PPCTTIImpl::getPopcntSupport(unsigned TyWidth) const {
34 assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
35 if (ST->hasPOPCNTD() != PPCSubtarget::POPCNTD_Unavailable && TyWidth <= 64)
36 return ST->hasPOPCNTD() == PPCSubtarget::POPCNTD_Slow ?
38 return TTI::PSK_Software;
39}
40
41std::optional<Instruction *>
43 Intrinsic::ID IID = II.getIntrinsicID();
44 switch (IID) {
45 default:
46 break;
47 case Intrinsic::ppc_altivec_lvx:
48 case Intrinsic::ppc_altivec_lvxl:
49 // Turn PPC lvx -> load if the pointer is known aligned.
51 II.getArgOperand(0), Align(16), IC.getDataLayout(), &II,
52 &IC.getAssumptionCache(), &IC.getDominatorTree()) >= 16) {
53 Value *Ptr = II.getArgOperand(0);
54 return new LoadInst(II.getType(), Ptr, "", false, Align(16));
55 }
56 break;
57 case Intrinsic::ppc_vsx_lxvw4x:
58 case Intrinsic::ppc_vsx_lxvd2x: {
59 // Turn PPC VSX loads into normal loads.
60 Value *Ptr = II.getArgOperand(0);
61 return new LoadInst(II.getType(), Ptr, Twine(""), false, Align(1));
62 }
63 case Intrinsic::ppc_altivec_stvx:
64 case Intrinsic::ppc_altivec_stvxl:
65 // Turn stvx -> store if the pointer is known aligned.
67 II.getArgOperand(1), Align(16), IC.getDataLayout(), &II,
68 &IC.getAssumptionCache(), &IC.getDominatorTree()) >= 16) {
69 Value *Ptr = II.getArgOperand(1);
70 return new StoreInst(II.getArgOperand(0), Ptr, false, Align(16));
71 }
72 break;
73 case Intrinsic::ppc_vsx_stxvw4x:
74 case Intrinsic::ppc_vsx_stxvd2x: {
75 // Turn PPC VSX stores into normal stores.
76 Value *Ptr = II.getArgOperand(1);
77 return new StoreInst(II.getArgOperand(0), Ptr, false, Align(1));
78 }
79 case Intrinsic::ppc_altivec_vperm:
80 // Turn vperm(V1,V2,mask) -> shuffle(V1,V2,mask) if mask is a constant.
81 // Note that ppc_altivec_vperm has a big-endian bias, so when creating
82 // a vectorshuffle for little endian, we must undo the transformation
83 // performed on vec_perm in altivec.h. That is, we must complement
84 // the permutation mask with respect to 31 and reverse the order of
85 // V1 and V2.
86 if (Constant *Mask = dyn_cast<Constant>(II.getArgOperand(2))) {
87 assert(cast<FixedVectorType>(Mask->getType())->getNumElements() == 16 &&
88 "Bad type for intrinsic!");
89
90 // Check that all of the elements are integer constants or undefs.
91 bool AllEltsOk = true;
92 for (unsigned I = 0; I != 16; ++I) {
93 Constant *Elt = Mask->getAggregateElement(I);
94 if (!Elt || !(isa<ConstantInt>(Elt) || isa<UndefValue>(Elt))) {
95 AllEltsOk = false;
96 break;
97 }
98 }
99
100 if (AllEltsOk) {
101 // Cast the input vectors to byte vectors.
102 Value *Op0 =
103 IC.Builder.CreateBitCast(II.getArgOperand(0), Mask->getType());
104 Value *Op1 =
105 IC.Builder.CreateBitCast(II.getArgOperand(1), Mask->getType());
106 Value *Result = PoisonValue::get(Op0->getType());
107
108 // Only extract each element once.
109 Value *ExtractedElts[32];
110 memset(ExtractedElts, 0, sizeof(ExtractedElts));
111
112 for (unsigned I = 0; I != 16; ++I) {
113 if (isa<UndefValue>(Mask->getAggregateElement(I)))
114 continue;
115 unsigned Idx =
116 cast<ConstantInt>(Mask->getAggregateElement(I))->getZExtValue();
117 Idx &= 31; // Match the hardware behavior.
118 if (DL.isLittleEndian())
119 Idx = 31 - Idx;
120
121 if (!ExtractedElts[Idx]) {
122 Value *Op0ToUse = (DL.isLittleEndian()) ? Op1 : Op0;
123 Value *Op1ToUse = (DL.isLittleEndian()) ? Op0 : Op1;
124 ExtractedElts[Idx] = IC.Builder.CreateExtractElement(
125 Idx < 16 ? Op0ToUse : Op1ToUse, Idx & 15);
126 }
127
128 // Insert this value into the result vector.
129 Result =
130 IC.Builder.CreateInsertElement(Result, ExtractedElts[Idx], I);
131 }
132 return CastInst::Create(Instruction::BitCast, Result, II.getType());
133 }
134 }
135 break;
136 }
137 return std::nullopt;
138}
139
141 TTI::TargetCostKind CostKind) const {
142 if (!ST->getCLOpts().constant_hoisting)
143 return BaseT::getIntImmCost(Imm, Ty, CostKind);
144
145 assert(Ty->isIntegerTy());
146
147 unsigned BitSize = Ty->getPrimitiveSizeInBits();
148 if (BitSize == 0)
149 return ~0U;
150
151 if (Imm == 0)
152 return TTI::TCC_Free;
153
154 if (Imm.getBitWidth() <= 64) {
155 if (isInt<16>(Imm.getSExtValue()))
156 return TTI::TCC_Basic;
157
158 if (isInt<32>(Imm.getSExtValue())) {
159 // A constant that can be materialized using lis.
160 if ((Imm.getZExtValue() & 0xFFFF) == 0)
161 return TTI::TCC_Basic;
162
163 return 2 * TTI::TCC_Basic;
164 }
165 }
166
167 return 4 * TTI::TCC_Basic;
168}
169
172 const APInt &Imm, Type *Ty,
173 TTI::TargetCostKind CostKind) const {
174 if (!ST->getCLOpts().constant_hoisting)
175 return BaseT::getIntImmCostIntrin(IID, Idx, Imm, Ty, CostKind);
176
177 assert(Ty->isIntegerTy());
178
179 unsigned BitSize = Ty->getPrimitiveSizeInBits();
180 if (BitSize == 0)
181 return ~0U;
182
183 switch (IID) {
184 default:
185 return TTI::TCC_Free;
186 case Intrinsic::sadd_with_overflow:
187 case Intrinsic::uadd_with_overflow:
188 case Intrinsic::ssub_with_overflow:
189 case Intrinsic::usub_with_overflow:
190 if ((Idx == 1) && Imm.getBitWidth() <= 64 && isInt<16>(Imm.getSExtValue()))
191 return TTI::TCC_Free;
192 break;
193 case Intrinsic::experimental_stackmap:
194 if ((Idx < 2) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue())))
195 return TTI::TCC_Free;
196 break;
197 case Intrinsic::experimental_patchpoint_void:
198 case Intrinsic::experimental_patchpoint:
199 if ((Idx < 4) || (Imm.getBitWidth() <= 64 && isInt<64>(Imm.getSExtValue())))
200 return TTI::TCC_Free;
201 break;
202 }
203 return PPCTTIImpl::getIntImmCost(Imm, Ty, CostKind);
204}
205
206InstructionCost PPCTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
207 const APInt &Imm, Type *Ty,
208 TTI::TargetCostKind CostKind,
209 Instruction *Inst) const {
210 if (!ST->getCLOpts().constant_hoisting)
211 return BaseT::getIntImmCostInst(Opcode, Idx, Imm, Ty, CostKind, Inst);
212
213 assert(Ty->isIntegerTy());
214
215 unsigned BitSize = Ty->getPrimitiveSizeInBits();
216 if (BitSize == 0)
217 return ~0U;
218
219 unsigned ImmIdx = ~0U;
220 bool ShiftedFree = false, RunFree = false, UnsignedFree = false,
221 ZeroFree = false;
222 switch (Opcode) {
223 default:
224 return TTI::TCC_Free;
225 case Instruction::GetElementPtr:
226 // Always hoist the base address of a GetElementPtr. This prevents the
227 // creation of new constants for every base constant that gets constant
228 // folded with the offset.
229 if (Idx == 0)
230 return 2 * TTI::TCC_Basic;
231 return TTI::TCC_Free;
232 case Instruction::And:
233 RunFree = true; // (for the rotate-and-mask instructions)
234 [[fallthrough]];
235 case Instruction::Add:
236 case Instruction::Or:
237 case Instruction::Xor:
238 ShiftedFree = true;
239 [[fallthrough]];
240 case Instruction::Sub:
241 case Instruction::Mul:
242 case Instruction::Shl:
243 case Instruction::LShr:
244 case Instruction::AShr:
245 ImmIdx = 1;
246 break;
247 case Instruction::ICmp:
248 UnsignedFree = true;
249 ImmIdx = 1;
250 // Zero comparisons can use record-form instructions.
251 [[fallthrough]];
252 case Instruction::Select:
253 ZeroFree = true;
254 break;
255 case Instruction::PHI:
256 case Instruction::Call:
257 case Instruction::Ret:
258 case Instruction::Load:
259 case Instruction::Store:
260 break;
261 }
262
263 if (ZeroFree && Imm == 0)
264 return TTI::TCC_Free;
265
266 if (Idx == ImmIdx && Imm.getBitWidth() <= 64) {
267 if (isInt<16>(Imm.getSExtValue()))
268 return TTI::TCC_Free;
269
270 if (RunFree) {
271 if (Imm.getBitWidth() <= 32 &&
272 (isShiftedMask_32(Imm.getZExtValue()) ||
273 isShiftedMask_32(~Imm.getZExtValue())))
274 return TTI::TCC_Free;
275
276 if (ST->isPPC64() &&
277 (isShiftedMask_64(Imm.getZExtValue()) ||
278 isShiftedMask_64(~Imm.getZExtValue())))
279 return TTI::TCC_Free;
280 }
281
282 if (UnsignedFree && isUInt<16>(Imm.getZExtValue()))
283 return TTI::TCC_Free;
284
285 if (ShiftedFree && (Imm.getZExtValue() & 0xFFFF) == 0)
286 return TTI::TCC_Free;
287 }
288
289 return PPCTTIImpl::getIntImmCost(Imm, Ty, CostKind);
290}
291
292// Check if the current Type is an MMA vector type. Valid MMA types are
293// v256i1 and v512i1 respectively.
294static bool isMMAType(Type *Ty) {
295 return Ty->isVectorTy() && (Ty->getScalarSizeInBits() == 1) &&
296 (Ty->getPrimitiveSizeInBits() > 128);
297}
298
301 TTI::TargetCostKind CostKind) const {
302 // We already implement getCastInstrCost and getMemoryOpCost where we perform
303 // the vector adjustment there.
304 if (isa<CastInst>(U) || isa<LoadInst>(U) || isa<StoreInst>(U))
305 return BaseT::getInstructionCost(U, Operands, CostKind);
306
307 if (U->getType()->isVectorTy()) {
308 // Instructions that need to be split should cost more.
309 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(U->getType());
310 return LT.first * BaseT::getInstructionCost(U, Operands, CostKind);
311 }
312
313 return BaseT::getInstructionCost(U, Operands, CostKind);
314}
315
317 AssumptionCache &AC,
318 TargetLibraryInfo *LibInfo,
319 HardwareLoopInfo &HWLoopInfo) const {
320 const PPCTargetMachine &TM = ST->getTargetMachine();
321 TargetSchedModel SchedModel;
322 SchedModel.init(ST);
323
324 // Do not convert small short loops to CTR loop.
325 unsigned ConstTripCount = SE.getSmallConstantTripCount(L);
326 if (ConstTripCount &&
327 ConstTripCount < ST->getCLOpts().min_ctr_loop_threshold) {
329 CodeMetrics::collectEphemeralValues(L, &AC, EphValues);
330 InstructionCost NumInsts;
331 for (BasicBlock *BB : L->blocks()) {
332 for (Instruction &I : *BB) {
333 if (EphValues.count(&I))
334 continue;
335 SmallVector<const Value *, 4> Operands(I.operand_values());
337 }
338 }
339 // 6 is an approximate latency for the mtctr instruction.
340 if (NumInsts <= (6 * SchedModel.getIssueWidth()))
341 return false;
342 }
343
344 // Check that there is no hardware loop related intrinsics in the loop.
345 for (auto *BB : L->getBlocks())
346 for (auto &I : *BB)
347 if (auto *Call = dyn_cast<IntrinsicInst>(&I))
348 if (Call->getIntrinsicID() == Intrinsic::set_loop_iterations ||
349 Call->getIntrinsicID() == Intrinsic::loop_decrement)
350 return false;
351
352 SmallVector<BasicBlock*, 4> ExitingBlocks;
353 L->getExitingBlocks(ExitingBlocks);
354
355 // If there is an exit edge known to be frequently taken,
356 // we should not transform this loop.
357 for (auto &BB : ExitingBlocks) {
358 Instruction *TI = BB->getTerminator();
359 if (CondBrInst *BI = dyn_cast<CondBrInst>(TI)) {
360 uint64_t TrueWeight = 0, FalseWeight = 0;
361 if (!extractBranchWeights(*BI, TrueWeight, FalseWeight))
362 continue;
363
364 // If the exit path is more frequent than the loop path,
365 // we return here without further analysis for this loop.
366 bool TrueIsExit = !L->contains(BI->getSuccessor(0));
367 if (( TrueIsExit && FalseWeight < TrueWeight) ||
368 (!TrueIsExit && FalseWeight > TrueWeight))
369 return false;
370 }
371 }
372
373 LLVMContext &C = L->getHeader()->getContext();
374 HWLoopInfo.CountType = TM.isPPC64() ?
376 HWLoopInfo.LoopDecrement = ConstantInt::get(HWLoopInfo.CountType, 1);
377 return true;
378}
379
382 OptimizationRemarkEmitter *ORE) const {
383 if (ST->getCPUDirective() == PPC::DIR_A2) {
384 // The A2 is in-order with a deep pipeline, and concatenation unrolling
385 // helps expose latency-hiding opportunities to the instruction scheduler.
386 UP.Partial = UP.Runtime = true;
387
388 // We unroll a lot on the A2 (hundreds of instructions), and the benefits
389 // often outweigh the cost of a division to compute the trip count.
390 UP.AllowExpensiveTripCount = true;
391 }
392
393 BaseT::getUnrollingPreferences(L, SE, UP, ORE);
394}
395
400// This function returns true to allow using coldcc calling convention.
401// Returning true results in coldcc being used for functions which are cold at
402// all call sites when the callers of the functions are not calling any other
403// non coldcc functions.
405 return ST->getCLOpts().enable_coldcc;
406}
407
408bool PPCTTIImpl::enableAggressiveInterleaving(bool LoopHasReductions) const {
409 // On the A2, always unroll aggressively.
410 if (ST->getCPUDirective() == PPC::DIR_A2)
411 return true;
412
413 return LoopHasReductions;
414}
415
417PPCTTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
419 if (getST()->hasAltivec())
420 Options.LoadSizes = {16, 8, 4, 2, 1};
421 else
422 Options.LoadSizes = {8, 4, 2, 1};
423
424 Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
425 return Options;
426}
427
429
430unsigned PPCTTIImpl::getNumberOfRegisters(unsigned ClassID) const {
431 assert(ClassID == GPRRC || ClassID == FPRRC ||
432 ClassID == VRRC || ClassID == VSXRC);
433 if (ST->hasVSX()) {
434 assert(ClassID == GPRRC || ClassID == VSXRC || ClassID == VRRC);
435 return ClassID == VSXRC ? 64 : 32;
436 }
437 assert(ClassID == GPRRC || ClassID == FPRRC || ClassID == VRRC);
438 return 32;
439}
440
442 if (Vector)
443 return ST->hasVSX() ? VSXRC : VRRC;
444 if (Ty &&
445 (Ty->getScalarType()->isFloatTy() || Ty->getScalarType()->isDoubleTy()))
446 return ST->hasVSX() ? VSXRC : FPRRC;
447 if (Ty && (Ty->getScalarType()->isFP128Ty() ||
448 Ty->getScalarType()->isPPC_FP128Ty()))
449 return VRRC;
450 if (Ty && Ty->getScalarType()->isHalfTy())
451 return VSXRC;
452 return GPRRC;
453}
454
455const char* PPCTTIImpl::getRegisterClassName(unsigned ClassID) const {
456
457 switch (ClassID) {
458 default:
459 llvm_unreachable("unknown register class");
460 return "PPC::unknown register class";
461 case GPRRC: return "PPC::GPRRC";
462 case FPRRC: return "PPC::FPRRC";
463 case VRRC: return "PPC::VRRC";
464 case VSXRC: return "PPC::VSXRC";
465 }
466}
467
470 switch (K) {
472 return TypeSize::getFixed(ST->isPPC64() ? 64 : 32);
474 return TypeSize::getFixed(ST->hasAltivec() ? 128 : 0);
476 return TypeSize::getScalable(0);
477 }
478
479 llvm_unreachable("Unsupported register kind");
480}
481
483 // Starting with P7 we have a cache line size of 128.
484 unsigned Directive = ST->getCPUDirective();
485 // Assume that Future CPU has the same cache line size as the others.
489 return 128;
490
491 // On other processors return a default of 64 bytes.
492 return 64;
493}
494
496 return 300;
497}
498
500 bool HasUnorderedReductions) const {
501 unsigned Directive = ST->getCPUDirective();
502 // The 440 has no SIMD support, but floating-point instructions
503 // have a 5-cycle latency, so unroll by 5x for latency hiding.
504 if (Directive == PPC::DIR_440)
505 return 5;
506
507 // The A2 has no SIMD support, but floating-point instructions
508 // have a 6-cycle latency, so unroll by 6x for latency hiding.
509 if (Directive == PPC::DIR_A2)
510 return 6;
511
512 // FIXME: For lack of any better information, do no harm...
514 return 1;
515
516 // For P7 and P8, floating-point instructions have a 6-cycle latency and
517 // there are two execution units, so unroll by 12x for latency hiding.
518 // FIXME: the same for P9 as previous gen until POWER9 scheduling is ready
519 // FIXME: the same for P10 as previous gen until POWER10 scheduling is ready
520 // Assume that future is the same as the others.
524 return 12;
525
526 // For most things, modern systems have two execution units (and
527 // out-of-order execution).
528 return 2;
529}
530
531// Returns a cost adjustment factor to adjust the cost of vector instructions
532// on targets which there is overlap between the vector and scalar units,
533// thereby reducing the overall throughput of vector code wrt. scalar code.
534// An invalid instruction cost is returned if the type is an MMA vector type.
536 Type *Ty1,
537 Type *Ty2) const {
538 // If the vector type is of an MMA type (v256i1, v512i1), an invalid
539 // instruction cost is returned. This is to signify to other cost computing
540 // functions to return the maximum instruction cost in order to prevent any
541 // opportunities for the optimizer to produce MMA types within the IR.
542 if (isMMAType(Ty1))
544
545 if (!ST->vectorsUseTwoUnits() || !Ty1->isVectorTy())
546 return InstructionCost(1);
547
548 std::pair<InstructionCost, MVT> LT1 = getTypeLegalizationCost(Ty1);
549 // If type legalization involves splitting the vector, we don't want to
550 // double the cost at every step - only the last step.
551 if (LT1.first != 1 || !LT1.second.isVector())
552 return InstructionCost(1);
553
554 int ISD = TLI->InstructionOpcodeToISD(Opcode);
555 if (TLI->isOperationExpand(ISD, LT1.second))
556 return InstructionCost(1);
557
558 if (Ty2) {
559 std::pair<InstructionCost, MVT> LT2 = getTypeLegalizationCost(Ty2);
560 if (LT2.first != 1 || !LT2.second.isVector())
561 return InstructionCost(1);
562 }
563
564 return InstructionCost(2);
565}
566
568 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
570 ArrayRef<const Value *> Args, const Instruction *CtxI) const {
571 assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode");
572
573 InstructionCost CostFactor = vectorCostAdjustmentFactor(Opcode, Ty, nullptr);
574 if (!CostFactor.isValid())
576
577 // TODO: Handle more cost kinds.
578 if (CostKind != TTI::TCK_RecipThroughput)
579 return BaseT::getArithmeticInstrCost(Opcode, Ty, CostKind, Op1Info,
580 Op2Info, Args, CtxI);
581
582 // Fallback to the default implementation.
584 Opcode, Ty, CostKind, Op1Info, Op2Info);
585 return Cost * CostFactor;
586}
587
589 TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
590 TTI::TargetCostKind CostKind, ArrayRef<int> Mask, int Index,
591 VectorType *SubTp, ArrayRef<const Value *> Args, const Instruction *CtxI,
592 TTI::VectorInstrContext VIC) const {
593
594 InstructionCost CostFactor =
595 vectorCostAdjustmentFactor(Instruction::ShuffleVector, SrcTy, nullptr);
596 if (!CostFactor.isValid())
598
599 // Legalize the type.
600 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(SrcTy);
601
602 // PPC, for both Altivec/VSX, support cheap arbitrary permutations
603 // (at least in the sense that there need only be one non-loop-invariant
604 // instruction). We need one such shuffle instruction for each actual
605 // register (this is not true for arbitrary shuffles, but is true for the
606 // structured types of shuffles covered by TTI::ShuffleKind).
607 return LT.first * CostFactor;
608}
609
611 TTI::TargetCostKind CostKind,
612 const Instruction *I) const {
613 if (CostKind != TTI::TCK_RecipThroughput)
614 return Opcode == Instruction::PHI ? 0 : 1;
615 // Branches are assumed to be predicted.
616 return 0;
617}
618
620 Type *Src,
622 TTI::TargetCostKind CostKind,
623 const Instruction *I) const {
624 assert(TLI->InstructionOpcodeToISD(Opcode) && "Invalid opcode");
625
626 InstructionCost CostFactor = vectorCostAdjustmentFactor(Opcode, Dst, Src);
627 if (!CostFactor.isValid())
629
631 BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
632 Cost *= CostFactor;
633 // TODO: Allow non-throughput costs that aren't binary.
634 if (CostKind != TTI::TCK_RecipThroughput)
635 return Cost == 0 ? 0 : 1;
636 return Cost;
637}
638
640 unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred,
642 TTI::OperandValueInfo Op2Info, const Instruction *I) const {
643 InstructionCost CostFactor =
644 vectorCostAdjustmentFactor(Opcode, ValTy, nullptr);
645 if (!CostFactor.isValid())
647
649 Opcode, ValTy, CondTy, VecPred, CostKind, Op1Info, Op2Info, I);
650 // TODO: Handle other cost kinds.
651 if (CostKind != TTI::TCK_RecipThroughput)
652 return Cost;
653 return Cost * CostFactor;
654}
655
657 unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
658 const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC) const {
659 assert(Val->isVectorTy() && "This must be a vector type");
660
661 int ISD = TLI->InstructionOpcodeToISD(Opcode);
662 assert(ISD && "Invalid opcode");
663
664 InstructionCost CostFactor = vectorCostAdjustmentFactor(Opcode, Val, nullptr);
665 if (!CostFactor.isValid())
667
669 BaseT::getVectorInstrCost(Opcode, Val, CostKind, Index, Op0, Op1, VIC);
670 Cost *= CostFactor;
671
672 if (ST->hasVSX() && Val->getScalarType()->isDoubleTy()) {
673 // Double-precision scalars are already located in index #0 (or #1 if LE).
675 Index == (ST->isLittleEndian() ? 1 : 0))
676 return 0;
677
678 return Cost;
679 }
680 if (Val->getScalarType()->isIntegerTy()) {
681 unsigned EltSize = Val->getScalarSizeInBits();
682 // Computing on 1 bit values requires extra mask or compare operations.
683 unsigned MaskCostForOneBitSize =
684 (ST->getCLOpts().vec_mask_cost && EltSize == 1) ? 1 : 0;
685 // Computing on non const index requires extra mask or compare operations.
686 unsigned MaskCostForIdx = (Index != -1U) ? 0 : 1;
687 if (ST->hasP9Altivec()) {
688 // P10 has vxform insert which can handle non const index. The
689 // MaskCostForIdx is for masking the index.
690 // P9 has insert for const index. A move-to VSR and a permute/insert.
691 // Assume vector operation cost for both (cost will be 2x on P9).
693 if (ST->hasP10Vector())
694 return CostFactor + MaskCostForIdx;
695 if (Index != -1U)
696 return 2 * CostFactor;
697 } else if (ISD == ISD::EXTRACT_VECTOR_ELT) {
698 // It's an extract. Maybe we can do a cheap move-from VSR.
699 unsigned EltSize = Val->getScalarSizeInBits();
700 // P9 has both mfvsrd and mfvsrld for 64 bit integer.
701 if (EltSize == 64 && Index != -1U)
702 return 1;
703 if (EltSize == 32) {
704 unsigned MfvsrwzIndex = ST->isLittleEndian() ? 2 : 1;
705 if (Index == MfvsrwzIndex)
706 return 1;
707
708 // For other indexs like non const, P9 has vxform extract. The
709 // MaskCostForIdx is for masking the index.
710 return CostFactor + MaskCostForIdx;
711 }
712
713 // We need a vector extract (or mfvsrld). Assume vector operation cost.
714 // The cost of the load constant for a vector extract is disregarded
715 // (invariant, easily schedulable).
716 return CostFactor + MaskCostForOneBitSize + MaskCostForIdx;
717 }
718 } else if (ST->hasDirectMove() && Index != -1U) {
719 // Assume permute has standard cost.
720 // Assume move-to/move-from VSR have 2x standard cost.
722 return 3;
723 return 3 + MaskCostForOneBitSize;
724 }
725 }
726
727 // Estimated cost of a load-hit-store delay. This was obtained
728 // experimentally as a minimum needed to prevent unprofitable
729 // vectorization for the paq8p benchmark. It may need to be
730 // raised further if other unprofitable cases remain.
731 unsigned LHSPenalty = 2;
733 LHSPenalty += 7;
734
735 // Vector element insert/extract with Altivec is very expensive,
736 // because they require store and reload with the attendant
737 // processor stall for load-hit-store. Until VSX is available,
738 // these need to be estimated as very costly.
741 return LHSPenalty + Cost;
742
743 return Cost;
744}
745
747 Align Alignment,
748 unsigned AddressSpace,
749 TTI::TargetCostKind CostKind,
751 const Instruction *I) const {
752 InstructionCost CostFactor = vectorCostAdjustmentFactor(Opcode, Src, nullptr);
753 if (!CostFactor.isValid())
755
756 if (TLI->getValueType(DL, Src, true) == MVT::Other)
757 return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
758 CostKind);
759 // Legalize the type.
760 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Src);
761 assert((Opcode == Instruction::Load || Opcode == Instruction::Store) &&
762 "Invalid Opcode");
763
765 BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, CostKind);
766 // TODO: Handle other cost kinds.
767 if (CostKind != TTI::TCK_RecipThroughput)
768 return Cost;
769
770 Cost *= CostFactor;
771
772 bool IsAltivecType = ST->hasAltivec() &&
773 (LT.second == MVT::v16i8 || LT.second == MVT::v8i16 ||
774 LT.second == MVT::v4i32 || LT.second == MVT::v4f32);
775 bool IsVSXType = ST->hasVSX() &&
776 (LT.second == MVT::v2f64 || LT.second == MVT::v2i64);
777
778 // VSX has 32b/64b load instructions. Legalization can handle loading of
779 // 32b/64b to VSR correctly and cheaply. But BaseT::getMemoryOpCost and
780 // PPCTargetLowering can't compute the cost appropriately. So here we
781 // explicitly check this case. There are also corresponding store
782 // instructions.
783 unsigned MemBits = Src->getPrimitiveSizeInBits();
784 unsigned SrcBytes = LT.second.getStoreSize();
785 if (ST->hasVSX() && IsAltivecType) {
786 if (MemBits == 64 || (ST->hasP8Vector() && MemBits == 32))
787 return 1;
788
789 // Use lfiwax/xxspltw
790 if (Opcode == Instruction::Load && MemBits == 32 && Alignment < SrcBytes)
791 return 2;
792 }
793
794 // Aligned loads and stores are easy.
795 if (!SrcBytes || Alignment >= SrcBytes)
796 return Cost;
797
798 // If we can use the permutation-based load sequence, then this is also
799 // relatively cheap (not counting loop-invariant instructions): one load plus
800 // one permute (the last load in a series has extra cost, but we're
801 // neglecting that here). Note that on the P7, we could do unaligned loads
802 // for Altivec types using the VSX instructions, but that's more expensive
803 // than using the permutation-based load sequence. On the P8, that's no
804 // longer true.
805 if (Opcode == Instruction::Load && (!ST->hasP8Vector() && IsAltivecType) &&
806 Alignment >= LT.second.getScalarType().getStoreSize())
807 return Cost + LT.first; // Add the cost of the permutations.
808
809 // For VSX, we can do unaligned loads and stores on Altivec/VSX types. On the
810 // P7, unaligned vector loads are more expensive than the permutation-based
811 // load sequence, so that might be used instead, but regardless, the net cost
812 // is about the same (not counting loop-invariant instructions).
813 if (IsVSXType || (ST->hasVSX() && IsAltivecType))
814 return Cost;
815
816 // Newer PPC supports unaligned memory access.
817 if (TLI->allowsMisalignedMemoryAccesses(LT.second, 0))
818 return Cost;
819
820 // PPC in general does not support unaligned loads and stores. They'll need
821 // to be decomposed based on the alignment factor.
822
823 // Add the cost of each scalar load or store.
824 Cost += LT.first * ((SrcBytes / Alignment.value()) - 1);
825
826 // For a vector type, there is also scalarization overhead (only for
827 // stores, loads are expanded using the vector-load + permutation sequence,
828 // which is much less expensive).
829 if (Src->isVectorTy() && Opcode == Instruction::Store)
830 for (int I = 0, E = cast<FixedVectorType>(Src)->getNumElements(); I < E;
831 ++I)
832 Cost +=
833 getVectorInstrCost(Instruction::ExtractElement, Src, CostKind, I,
834 nullptr, nullptr, TTI::VectorInstrContext::None);
835
836 return Cost;
837}
838
840 unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
841 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
842 bool UseMaskForCond, bool UseMaskForGaps) const {
843 InstructionCost CostFactor =
844 vectorCostAdjustmentFactor(Opcode, VecTy, nullptr);
845 if (!CostFactor.isValid())
847
848 if (UseMaskForCond || UseMaskForGaps)
849 return BaseT::getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
850 Alignment, AddressSpace, CostKind,
851 UseMaskForCond, UseMaskForGaps);
852
853 assert(isa<VectorType>(VecTy) &&
854 "Expect a vector type for interleaved memory op");
855
856 // Legalize the type.
857 std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(VecTy);
858
859 // Firstly, the cost of load/store operation.
861 getMemoryOpCost(Opcode, VecTy, Alignment, AddressSpace, CostKind);
862
863 // PPC, for both Altivec/VSX, support cheap arbitrary permutations
864 // (at least in the sense that there need only be one non-loop-invariant
865 // instruction). For each result vector, we need one shuffle per incoming
866 // vector (except that the first shuffle can take two incoming vectors
867 // because it does not need to take itself).
868 Cost += Factor*(LT.first-1);
869
870 return Cost;
871}
872
875 TTI::TargetCostKind CostKind) const {
876
878 return BaseT::getIntrinsicInstrCost(ICA, CostKind);
879
880 if (ICA.getID() == Intrinsic::vp_load) {
881 MemIntrinsicCostAttributes MICA(Intrinsic::masked_load, ICA.getReturnType(),
882 Align(1), 0);
883 return getMemIntrinsicInstrCost(MICA, CostKind);
884 }
885
886 if (ICA.getID() == Intrinsic::vp_store) {
887 MemIntrinsicCostAttributes MICA(Intrinsic::masked_store,
888 ICA.getArgTypes()[0], Align(1), 0);
889 return getMemIntrinsicInstrCost(MICA, CostKind);
890 }
891
893}
894
896 const Function *Callee,
897 ArrayRef<Type *> Types) const {
898
899 // We need to ensure that argument promotion does not
900 // attempt to promote pointers to MMA types (__vector_pair
901 // and __vector_quad) since these types explicitly cannot be
902 // passed as arguments. Both of these types are larger than
903 // the 128-bit Altivec vectors and have a scalar size of 1 bit.
904 if (!BaseT::areTypesABICompatible(Caller, Callee, Types))
905 return false;
906
907 return llvm::none_of(Types, [](Type *Ty) {
908 if (Ty->isSized())
909 return Ty->isIntOrIntVectorTy(1) && Ty->getPrimitiveSizeInBits() > 128;
910 return false;
911 });
912}
913
915 LoopInfo *LI, DominatorTree *DT,
916 AssumptionCache *AC,
917 TargetLibraryInfo *LibInfo) const {
918 // Process nested loops first.
919 for (Loop *I : *L)
920 if (canSaveCmp(I, BI, SE, LI, DT, AC, LibInfo))
921 return false; // Stop search.
922
923 HardwareLoopInfo HWLoopInfo(L);
924
925 if (!HWLoopInfo.canAnalyze(*LI))
926 return false;
927
928 if (!isHardwareLoopProfitable(L, *SE, *AC, LibInfo, HWLoopInfo))
929 return false;
930
931 if (!HWLoopInfo.isHardwareLoopCandidate(*SE, *LI, *DT))
932 return false;
933
934 *BI = HWLoopInfo.ExitBranch;
935 return true;
936}
937
939 const TargetTransformInfo::LSRCost &C2) const {
940 // PowerPC default behaviour here is "instruction number 1st priority".
941 // If -ppc-lsr-no-insns-cost is set, call default implementation.
942 if (!ST->getCLOpts().lsr_no_insns_cost)
943 return std::tie(C1.Insns, C1.NumRegs, C1.AddRecCost, C1.NumIVMuls,
944 C1.NumBaseAdds, C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
945 std::tie(C2.Insns, C2.NumRegs, C2.AddRecCost, C2.NumIVMuls,
946 C2.NumBaseAdds, C2.ScaleCost, C2.ImmCost, C2.SetupCost);
948}
949
950bool PPCTTIImpl::isNumRegsMajorCostOfLSR() const { return false; }
951
953 // XCOFF hasn't implemented lowerRelativeReference, disable non-ELF for now.
954 if (!ST->isELFv2ABI())
955 return false;
957}
958
960 MemIntrinsicInfo &Info) const {
961 switch (Inst->getIntrinsicID()) {
962 case Intrinsic::ppc_altivec_lvx:
963 case Intrinsic::ppc_altivec_lvxl:
964 case Intrinsic::ppc_altivec_lvebx:
965 case Intrinsic::ppc_altivec_lvehx:
966 case Intrinsic::ppc_altivec_lvewx:
967 case Intrinsic::ppc_vsx_lxvd2x:
968 case Intrinsic::ppc_vsx_lxvw4x:
969 case Intrinsic::ppc_vsx_lxvd2x_be:
970 case Intrinsic::ppc_vsx_lxvw4x_be:
971 case Intrinsic::ppc_vsx_lxvl:
972 case Intrinsic::ppc_vsx_lxvll:
973 case Intrinsic::ppc_vsx_lxvp: {
974 Info.PtrVal = Inst->getArgOperand(0);
975 Info.ReadMem = true;
976 Info.WriteMem = false;
977 return true;
978 }
979 case Intrinsic::ppc_altivec_stvx:
980 case Intrinsic::ppc_altivec_stvxl:
981 case Intrinsic::ppc_altivec_stvebx:
982 case Intrinsic::ppc_altivec_stvehx:
983 case Intrinsic::ppc_altivec_stvewx:
984 case Intrinsic::ppc_vsx_stxvd2x:
985 case Intrinsic::ppc_vsx_stxvw4x:
986 case Intrinsic::ppc_vsx_stxvd2x_be:
987 case Intrinsic::ppc_vsx_stxvw4x_be:
988 case Intrinsic::ppc_vsx_stxvl:
989 case Intrinsic::ppc_vsx_stxvll:
990 case Intrinsic::ppc_vsx_stxvp: {
991 Info.PtrVal = Inst->getArgOperand(1);
992 Info.ReadMem = false;
993 Info.WriteMem = true;
994 return true;
995 }
996 case Intrinsic::ppc_stbcx:
997 case Intrinsic::ppc_sthcx:
998 case Intrinsic::ppc_stdcx:
999 case Intrinsic::ppc_stwcx: {
1000 Info.PtrVal = Inst->getArgOperand(0);
1001 Info.ReadMem = false;
1002 Info.WriteMem = true;
1003 return true;
1004 }
1005 default:
1006 break;
1007 }
1008
1009 return false;
1010}
1011
1013 return TLI->supportsTailCallFor(CB);
1014}
1015
1016// Target hook used by CodeGen to decide whether to expand vector predication
1017// intrinsics into scalar operations or to use special ISD nodes to represent
1018// them. The Target will not see the intrinsics.
1022 unsigned Directive = ST->getCPUDirective();
1023 VPLegalization DefaultLegalization = BaseT::getVPLegalizationStrategy(PI);
1025 (!ST->getCLOpts().pwr9_evl || Directive != PPC::DIR_PWR9))
1026 return DefaultLegalization;
1027
1028 if (!ST->isPPC64())
1029 return DefaultLegalization;
1030
1031 unsigned IID = PI.getIntrinsicID();
1032 if (IID != Intrinsic::vp_load && IID != Intrinsic::vp_store)
1033 return DefaultLegalization;
1034
1035 bool IsLoad = IID == Intrinsic::vp_load;
1036 Type *VecTy = IsLoad ? PI.getType() : PI.getOperand(0)->getType();
1037 EVT VT = TLI->getValueType(DL, VecTy, true);
1038 if (VT != MVT::v2i64 && VT != MVT::v4i32 && VT != MVT::v8i16 &&
1039 VT != MVT::v16i8)
1040 return DefaultLegalization;
1041
1042 auto IsAllTrueMask = [](Value *MaskVal) {
1043 if (Value *SplattedVal = getSplatValue(MaskVal))
1044 if (auto *ConstValue = dyn_cast<Constant>(SplattedVal))
1045 return ConstValue->isAllOnesValue();
1046 return false;
1047 };
1048 unsigned MaskIx = IsLoad ? 1 : 2;
1049 if (!IsAllTrueMask(PI.getOperand(MaskIx)))
1050 return DefaultLegalization;
1051
1053}
1054
1056 if (!ST->getCLOpts().evl || !ST->isPPC64())
1057 return false;
1058 unsigned CPU = ST->getCPUDirective();
1059 return CPU == PPC::DIR_PWR10 || CPU == PPC::DIR_PWR_FUTURE ||
1060 (ST->getCLOpts().pwr9_evl && CPU == PPC::DIR_PWR9);
1061}
1062
1063bool PPCTTIImpl::isLegalMaskedLoad(Type *DataType, Align Alignment,
1064 unsigned AddressSpace,
1065 TTI::MaskKind MaskKind) const {
1066 if (!hasActiveVectorLength())
1067 return false;
1068
1069 auto IsLegalLoadWithLengthType = [](EVT VT) {
1070 if (VT != MVT::i64 && VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8)
1071 return false;
1072 return true;
1073 };
1074
1075 return IsLegalLoadWithLengthType(TLI->getValueType(DL, DataType, true));
1076}
1077
1079 unsigned AddressSpace,
1080 TTI::MaskKind MaskKind) const {
1081 return isLegalMaskedLoad(DataType, Alignment, AddressSpace);
1082}
1083
1086 TTI::TargetCostKind CostKind) const {
1087
1088 InstructionCost BaseCost = BaseT::getMemIntrinsicInstrCost(MICA, CostKind);
1089
1090 unsigned Opcode;
1091 switch (MICA.getID()) {
1092 case Intrinsic::masked_load:
1093 Opcode = Instruction::Load;
1094 break;
1095 case Intrinsic::masked_store:
1096 Opcode = Instruction::Store;
1097 break;
1098 default:
1099 return BaseCost;
1100 }
1101
1102 Type *DataTy = MICA.getDataType();
1103 Align Alignment = MICA.getAlignment();
1104 unsigned AddressSpace = MICA.getAddressSpace();
1105
1106 auto VecTy = dyn_cast<FixedVectorType>(DataTy);
1107 if (!VecTy)
1108 return BaseCost;
1109 if (Opcode == Instruction::Load) {
1110 if (!isLegalMaskedLoad(VecTy->getScalarType(), Alignment, AddressSpace))
1111 return BaseCost;
1112 } else {
1113 if (!isLegalMaskedStore(VecTy->getScalarType(), Alignment, AddressSpace))
1114 return BaseCost;
1115 }
1116 if (VecTy->getPrimitiveSizeInBits() > 128)
1117 return BaseCost;
1118
1119 // Cost is 1 (scalar compare) + 1 (scalar select) +
1120 // 1 * vectorCostAdjustmentFactor (vector load with length)
1121 // Maybe + 1 (scalar shift)
1123 1 + 1 + vectorCostAdjustmentFactor(Opcode, DataTy, nullptr);
1124 if (ST->getCPUDirective() != PPC::DIR_PWR_FUTURE ||
1125 VecTy->getScalarSizeInBits() != 8)
1126 Cost += 1; // need shift for length
1127 return Cost;
1128}
1129
1131 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
1133 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
1134 TTI::TargetCostKind CostKind, std::optional<FastMathFlags> FMF) const {
1136
1137 if (!getST()->hasAltivec())
1138 return Invalid;
1139 if (Opcode != Instruction::Add)
1140 return Invalid;
1141
1142 EVT AccVT = TLI->getValueType(DL, AccumType, true);
1143 if (AccVT != MVT::i32)
1144 return Invalid;
1145
1146 Type *ATy = VectorType::get(InputTypeA, VF);
1147 EVT AVT = TLI->getValueType(DL, ATy, true);
1148
1149 if (OpAExtend != TTI::PR_SignExtend && OpAExtend != TTI::PR_ZeroExtend)
1150 return Invalid;
1151
1152 if (!BinOp) {
1153 // It's just an add, so only the LHS type matters. RHS is just 1s.
1154 if (AVT != MVT::v16i8 && AVT != MVT::v8i16)
1155 return Invalid;
1156 // We can do either (sext/-) or (zext/-) for v16i8 and v8i16
1157 return vectorCostAdjustmentFactor(Instruction::Add, ATy, nullptr);
1158 }
1159
1160 if (BinOp.value() != Instruction::Mul)
1161 return Invalid;
1162 if (InputTypeA != InputTypeB)
1163 return Invalid;
1164 if (OpBExtend != TTI::PR_SignExtend && OpBExtend != TTI::PR_ZeroExtend)
1165 return Invalid;
1166
1167 if (AVT == MVT::v16i8) {
1168 // For v16i8 PPC supports vmsumubm (zext/zext), vmsummbm (sext/zext), and
1169 // (sext/sext) by multi-instruction expansion.
1170 if (OpAExtend == TTI::PR_ZeroExtend && OpBExtend != TTI::PR_ZeroExtend)
1171 return Invalid;
1172 // The (sext/sext) case will be custom lowered using multiply even/odd and
1173 // v8i16 reductions.
1174 if (OpBExtend == TTI::PR_SignExtend)
1175 return 4 * vectorCostAdjustmentFactor(Instruction::Add, ATy, nullptr);
1176 } else if (AVT == MVT::v8i16) {
1177 // For v8i16 PPC supports vmsumuhm (zext/zext) and vmsumshm (sext/sext)
1178 if (OpAExtend != OpBExtend)
1179 return Invalid;
1180 } else {
1181 return Invalid;
1182 }
1183
1184 return vectorCostAdjustmentFactor(Instruction::Add, ATy, nullptr);
1185}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t 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")
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 bool isMMAType(Type *Ty)
This file a TargetTransformInfoImplBase conforming object specific to the PPC target machine.
This file contains the declarations for profiling metadata utility functions.
int64_t C1
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:44
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:2748
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2736
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition IRBuilder.h:2319
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:76
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:352
static constexpr TypeSize getScalable(ScalarTy MinimumSize)
Definition TypeSize.h:355
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:295
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:294
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.h:354
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:370
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
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:1607
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...