Deleted Added
full compact
PPCTargetTransformInfo.cpp (360784) PPCTargetTransformInfo.cpp (368974)
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

--- 199 unchanged lines hidden (view full) ---

208 // Instructions that need to be split should cost more.
209 std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, U->getType());
210 return LT.first * BaseT::getUserCost(U, Operands);
211 }
212
213 return BaseT::getUserCost(U, Operands);
214}
215
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

--- 199 unchanged lines hidden (view full) ---

208 // Instructions that need to be split should cost more.
209 std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, U->getType());
210 return LT.first * BaseT::getUserCost(U, Operands);
211 }
212
213 return BaseT::getUserCost(U, Operands);
214}
215
216bool PPCTTIImpl::mightUseCTR(BasicBlock *BB,
217 TargetLibraryInfo *LibInfo) {
216// Determining the address of a TLS variable results in a function call in
217// certain TLS models.
218static bool memAddrUsesCTR(const Value *MemAddr, const PPCTargetMachine &TM,
219 SmallPtrSetImpl<const Value *> &Visited) {
220 // No need to traverse again if we already checked this operand.
221 if (!Visited.insert(MemAddr).second)
222 return false;
223 const auto *GV = dyn_cast<GlobalValue>(MemAddr);
224 if (!GV) {
225 // Recurse to check for constants that refer to TLS global variables.
226 if (const auto *CV = dyn_cast<Constant>(MemAddr))
227 for (const auto &CO : CV->operands())
228 if (memAddrUsesCTR(CO, TM, Visited))
229 return true;
230 return false;
231 }
232
233 if (!GV->isThreadLocal())
234 return false;
235 TLSModel::Model Model = TM.getTLSModel(GV);
236 return Model == TLSModel::GeneralDynamic || Model == TLSModel::LocalDynamic;
237}
238
239bool PPCTTIImpl::mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo,
240 SmallPtrSetImpl<const Value *> &Visited) {
218 const PPCTargetMachine &TM = ST->getTargetMachine();
219
220 // Loop through the inline asm constraints and look for something that
221 // clobbers ctr.
222 auto asmClobbersCTR = [](InlineAsm *IA) {
223 InlineAsm::ConstraintInfoVector CIV = IA->ParseConstraints();
224 for (unsigned i = 0, ie = CIV.size(); i < ie; ++i) {
225 InlineAsm::ConstraintInfo &C = CIV[i];
226 if (C.Type != InlineAsm::isInput)
227 for (unsigned j = 0, je = C.Codes.size(); j < je; ++j)
228 if (StringRef(C.Codes[j]).equals_lower("{ctr}"))
229 return true;
230 }
231 return false;
232 };
233
241 const PPCTargetMachine &TM = ST->getTargetMachine();
242
243 // Loop through the inline asm constraints and look for something that
244 // clobbers ctr.
245 auto asmClobbersCTR = [](InlineAsm *IA) {
246 InlineAsm::ConstraintInfoVector CIV = IA->ParseConstraints();
247 for (unsigned i = 0, ie = CIV.size(); i < ie; ++i) {
248 InlineAsm::ConstraintInfo &C = CIV[i];
249 if (C.Type != InlineAsm::isInput)
250 for (unsigned j = 0, je = C.Codes.size(); j < je; ++j)
251 if (StringRef(C.Codes[j]).equals_lower("{ctr}"))
252 return true;
253 }
254 return false;
255 };
256
234 // Determining the address of a TLS variable results in a function call in
235 // certain TLS models.
236 std::function<bool(const Value*)> memAddrUsesCTR =
237 [&memAddrUsesCTR, &TM](const Value *MemAddr) -> bool {
238 const auto *GV = dyn_cast<GlobalValue>(MemAddr);
239 if (!GV) {
240 // Recurse to check for constants that refer to TLS global variables.
241 if (const auto *CV = dyn_cast<Constant>(MemAddr))
242 for (const auto &CO : CV->operands())
243 if (memAddrUsesCTR(CO))
244 return true;
245
246 return false;
247 }
248
249 if (!GV->isThreadLocal())
250 return false;
251 TLSModel::Model Model = TM.getTLSModel(GV);
252 return Model == TLSModel::GeneralDynamic ||
253 Model == TLSModel::LocalDynamic;
254 };
255
256 auto isLargeIntegerTy = [](bool Is32Bit, Type *Ty) {
257 if (IntegerType *ITy = dyn_cast<IntegerType>(Ty))
258 return ITy->getBitWidth() > (Is32Bit ? 32U : 64U);
259
260 return false;
261 };
262
263 for (BasicBlock::iterator J = BB->begin(), JE = BB->end();

--- 199 unchanged lines hidden (view full) ---

463 case Instruction::UIToFP:
464 case Instruction::SIToFP:
465 case Instruction::FCmp:
466 return true;
467 }
468 }
469
470 for (Value *Operand : J->operands())
257 auto isLargeIntegerTy = [](bool Is32Bit, Type *Ty) {
258 if (IntegerType *ITy = dyn_cast<IntegerType>(Ty))
259 return ITy->getBitWidth() > (Is32Bit ? 32U : 64U);
260
261 return false;
262 };
263
264 for (BasicBlock::iterator J = BB->begin(), JE = BB->end();

--- 199 unchanged lines hidden (view full) ---

464 case Instruction::UIToFP:
465 case Instruction::SIToFP:
466 case Instruction::FCmp:
467 return true;
468 }
469 }
470
471 for (Value *Operand : J->operands())
471 if (memAddrUsesCTR(Operand))
472 if (memAddrUsesCTR(Operand, TM, Visited))
472 return true;
473 }
474
475 return false;
476}
477
478bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
479 AssumptionCache &AC,

--- 13 unchanged lines hidden (view full) ---

493 Metrics.analyzeBasicBlock(BB, *this, EphValues);
494 // 6 is an approximate latency for the mtctr instruction.
495 if (Metrics.NumInsts <= (6 * SchedModel.getIssueWidth()))
496 return false;
497 }
498
499 // We don't want to spill/restore the counter register, and so we don't
500 // want to use the counter register if the loop contains calls.
473 return true;
474 }
475
476 return false;
477}
478
479bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
480 AssumptionCache &AC,

--- 13 unchanged lines hidden (view full) ---

494 Metrics.analyzeBasicBlock(BB, *this, EphValues);
495 // 6 is an approximate latency for the mtctr instruction.
496 if (Metrics.NumInsts <= (6 * SchedModel.getIssueWidth()))
497 return false;
498 }
499
500 // We don't want to spill/restore the counter register, and so we don't
501 // want to use the counter register if the loop contains calls.
502 SmallPtrSet<const Value *, 4> Visited;
501 for (Loop::block_iterator I = L->block_begin(), IE = L->block_end();
502 I != IE; ++I)
503 for (Loop::block_iterator I = L->block_begin(), IE = L->block_end();
504 I != IE; ++I)
503 if (mightUseCTR(*I, LibInfo))
505 if (mightUseCTR(*I, LibInfo, Visited))
504 return false;
505
506 SmallVector<BasicBlock*, 4> ExitingBlocks;
507 L->getExitingBlocks(ExitingBlocks);
508
509 // If there is an exit edge known to be frequently taken,
510 // we should not transform this loop.
511 for (auto &BB : ExitingBlocks) {

--- 10 unchanged lines hidden (view full) ---

522 // we return here without further analysis for this loop.
523 bool TrueIsExit = !L->contains(BI->getSuccessor(0));
524 if (( TrueIsExit && FalseWeight < TrueWeight) ||
525 (!TrueIsExit && FalseWeight > TrueWeight))
526 return false;
527 }
528 }
529
506 return false;
507
508 SmallVector<BasicBlock*, 4> ExitingBlocks;
509 L->getExitingBlocks(ExitingBlocks);
510
511 // If there is an exit edge known to be frequently taken,
512 // we should not transform this loop.
513 for (auto &BB : ExitingBlocks) {

--- 10 unchanged lines hidden (view full) ---

524 // we return here without further analysis for this loop.
525 bool TrueIsExit = !L->contains(BI->getSuccessor(0));
526 if (( TrueIsExit && FalseWeight < TrueWeight) ||
527 (!TrueIsExit && FalseWeight > TrueWeight))
528 return false;
529 }
530 }
531
532 // If an exit block has a PHI that accesses a TLS variable as one of the
533 // incoming values from the loop, we cannot produce a CTR loop because the
534 // address for that value will be computed in the loop.
535 SmallVector<BasicBlock *, 4> ExitBlocks;
536 L->getExitBlocks(ExitBlocks);
537 for (auto &BB : ExitBlocks) {
538 for (auto &PHI : BB->phis()) {
539 for (int Idx = 0, EndIdx = PHI.getNumIncomingValues(); Idx < EndIdx;
540 Idx++) {
541 const BasicBlock *IncomingBB = PHI.getIncomingBlock(Idx);
542 const Value *IncomingValue = PHI.getIncomingValue(Idx);
543 if (L->contains(IncomingBB) &&
544 memAddrUsesCTR(IncomingValue, TM, Visited))
545 return false;
546 }
547 }
548 }
549
530 LLVMContext &C = L->getHeader()->getContext();
531 HWLoopInfo.CountType = TM.isPPC64() ?
532 Type::getInt64Ty(C) : Type::getInt32Ty(C);
533 HWLoopInfo.LoopDecrement = ConstantInt::get(HWLoopInfo.CountType, 1);
534 return true;
535}
536
537void PPCTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,

--- 432 unchanged lines hidden ---
550 LLVMContext &C = L->getHeader()->getContext();
551 HWLoopInfo.CountType = TM.isPPC64() ?
552 Type::getInt64Ty(C) : Type::getInt32Ty(C);
553 HWLoopInfo.LoopDecrement = ConstantInt::get(HWLoopInfo.CountType, 1);
554 return true;
555}
556
557void PPCTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,

--- 432 unchanged lines hidden ---