Merge commit 4f568fbd2 from llvm git (by Nemanja Ivanovic):
[PowerPC] Do not emit HW loop when TLS var accessed in PHI of loop exit If any PHI nodes in loop exit blocks have incoming values from the loop that are accesses of TLS variables with local dynamic or general dynamic TLS model, the address will be computed inside the loop. Since this includes a call to __tls_get_addr, this will in turn cause the CTR loops verifier to complain. Disable CTR loops in such cases. Fixes: https://bugs.llvm.org/show_bug.cgi?id=48527 This should fix building ceph 12.2.12 on powerpc64, powerpc, powerpcspe and powerpc64le. Requested by: pkubaj MFC after: 3 days
This commit is contained in:
parent
8b4c3a03f9
commit
543478be75
@ -226,6 +226,29 @@ PPCTTIImpl::getUserCost(const User *U, ArrayRef<const Value *> Operands,
|
||||
return BaseT::getUserCost(U, Operands, CostKind);
|
||||
}
|
||||
|
||||
// Determining the address of a TLS variable results in a function call in
|
||||
// certain TLS models.
|
||||
static bool memAddrUsesCTR(const Value *MemAddr, const PPCTargetMachine &TM,
|
||||
SmallPtrSetImpl<const Value *> &Visited) {
|
||||
// No need to traverse again if we already checked this operand.
|
||||
if (!Visited.insert(MemAddr).second)
|
||||
return false;
|
||||
const auto *GV = dyn_cast<GlobalValue>(MemAddr);
|
||||
if (!GV) {
|
||||
// Recurse to check for constants that refer to TLS global variables.
|
||||
if (const auto *CV = dyn_cast<Constant>(MemAddr))
|
||||
for (const auto &CO : CV->operands())
|
||||
if (memAddrUsesCTR(CO, TM, Visited))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GV->isThreadLocal())
|
||||
return false;
|
||||
TLSModel::Model Model = TM.getTLSModel(GV);
|
||||
return Model == TLSModel::GeneralDynamic || Model == TLSModel::LocalDynamic;
|
||||
}
|
||||
|
||||
bool PPCTTIImpl::mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo,
|
||||
SmallPtrSetImpl<const Value *> &Visited) {
|
||||
const PPCTargetMachine &TM = ST->getTargetMachine();
|
||||
@ -244,31 +267,6 @@ bool PPCTTIImpl::mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo,
|
||||
return false;
|
||||
};
|
||||
|
||||
// Determining the address of a TLS variable results in a function call in
|
||||
// certain TLS models.
|
||||
std::function<bool(const Value *)> memAddrUsesCTR =
|
||||
[&memAddrUsesCTR, &TM, &Visited](const Value *MemAddr) -> bool {
|
||||
// No need to traverse again if we already checked this operand.
|
||||
if (!Visited.insert(MemAddr).second)
|
||||
return false;
|
||||
const auto *GV = dyn_cast<GlobalValue>(MemAddr);
|
||||
if (!GV) {
|
||||
// Recurse to check for constants that refer to TLS global variables.
|
||||
if (const auto *CV = dyn_cast<Constant>(MemAddr))
|
||||
for (const auto &CO : CV->operands())
|
||||
if (memAddrUsesCTR(CO))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GV->isThreadLocal())
|
||||
return false;
|
||||
TLSModel::Model Model = TM.getTLSModel(GV);
|
||||
return Model == TLSModel::GeneralDynamic ||
|
||||
Model == TLSModel::LocalDynamic;
|
||||
};
|
||||
|
||||
auto isLargeIntegerTy = [](bool Is32Bit, Type *Ty) {
|
||||
if (IntegerType *ITy = dyn_cast<IntegerType>(Ty))
|
||||
return ITy->getBitWidth() > (Is32Bit ? 32U : 64U);
|
||||
@ -486,7 +484,7 @@ bool PPCTTIImpl::mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo,
|
||||
}
|
||||
|
||||
for (Value *Operand : J->operands())
|
||||
if (memAddrUsesCTR(Operand))
|
||||
if (memAddrUsesCTR(Operand, TM, Visited))
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -546,6 +544,24 @@ bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
|
||||
}
|
||||
}
|
||||
|
||||
// If an exit block has a PHI that accesses a TLS variable as one of the
|
||||
// incoming values from the loop, we cannot produce a CTR loop because the
|
||||
// address for that value will be computed in the loop.
|
||||
SmallVector<BasicBlock *, 4> ExitBlocks;
|
||||
L->getExitBlocks(ExitBlocks);
|
||||
for (auto &BB : ExitBlocks) {
|
||||
for (auto &PHI : BB->phis()) {
|
||||
for (int Idx = 0, EndIdx = PHI.getNumIncomingValues(); Idx < EndIdx;
|
||||
Idx++) {
|
||||
const BasicBlock *IncomingBB = PHI.getIncomingBlock(Idx);
|
||||
const Value *IncomingValue = PHI.getIncomingValue(Idx);
|
||||
if (L->contains(IncomingBB) &&
|
||||
memAddrUsesCTR(IncomingValue, TM, Visited))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LLVMContext &C = L->getHeader()->getContext();
|
||||
HWLoopInfo.CountType = TM.isPPC64() ?
|
||||
Type::getInt64Ty(C) : Type::getInt32Ty(C);
|
||||
|
Loading…
Reference in New Issue
Block a user