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