Skip to content

Commit 85edf1f

Browse files
author
Chen Zheng
committed
[PowerPC] remove the ctr clobbers check related to TLS access
Dynamic tls access model will be lowered to MI which clobbers CTR in the loop in ISEL(ADDItlsgdLADDR) and post-isel CTR loop pass will revert the loop to a normal compare + branch form. So no need to add this clobber check in hardware loop insertion pass now. Reviewed By: nemanjai Differential revision: https://reviews.llvm.org/D140367
1 parent 8fd279f commit 85edf1f

File tree

2 files changed

+10
-52
lines changed

2 files changed

+10
-52
lines changed

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -339,29 +339,6 @@ InstructionCost PPCTTIImpl::getInstructionCost(const User *U,
339339
return BaseT::getInstructionCost(U, Operands, CostKind);
340340
}
341341

342-
// Determining the address of a TLS variable results in a function call in
343-
// certain TLS models.
344-
static bool memAddrUsesCTR(const Value *MemAddr, const PPCTargetMachine &TM,
345-
SmallPtrSetImpl<const Value *> &Visited) {
346-
// No need to traverse again if we already checked this operand.
347-
if (!Visited.insert(MemAddr).second)
348-
return false;
349-
const auto *GV = dyn_cast<GlobalValue>(MemAddr);
350-
if (!GV) {
351-
// Recurse to check for constants that refer to TLS global variables.
352-
if (const auto *CV = dyn_cast<Constant>(MemAddr))
353-
for (const auto &CO : CV->operands())
354-
if (memAddrUsesCTR(CO, TM, Visited))
355-
return true;
356-
return false;
357-
}
358-
359-
if (!GV->isThreadLocal())
360-
return false;
361-
TLSModel::Model Model = TM.getTLSModel(GV);
362-
return Model == TLSModel::GeneralDynamic || Model == TLSModel::LocalDynamic;
363-
}
364-
365342
bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
366343
AssumptionCache &AC,
367344
TargetLibraryInfo *LibInfo,
@@ -415,25 +392,6 @@ bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
415392
}
416393
}
417394

418-
// If an exit block has a PHI that accesses a TLS variable as one of the
419-
// incoming values from the loop, we cannot produce a CTR loop because the
420-
// address for that value will be computed in the loop.
421-
SmallVector<BasicBlock *, 4> ExitBlocks;
422-
L->getExitBlocks(ExitBlocks);
423-
SmallPtrSet<const Value *, 4> Visited;
424-
for (auto &BB : ExitBlocks) {
425-
for (auto &PHI : BB->phis()) {
426-
for (int Idx = 0, EndIdx = PHI.getNumIncomingValues(); Idx < EndIdx;
427-
Idx++) {
428-
const BasicBlock *IncomingBB = PHI.getIncomingBlock(Idx);
429-
const Value *IncomingValue = PHI.getIncomingValue(Idx);
430-
if (L->contains(IncomingBB) &&
431-
memAddrUsesCTR(IncomingValue, TM, Visited))
432-
return false;
433-
}
434-
}
435-
}
436-
437395
LLVMContext &C = L->getHeader()->getContext();
438396
HWLoopInfo.CountType = TM.isPPC64() ?
439397
Type::getInt64Ty(C) : Type::getInt32Ty(C);

llvm/test/CodeGen/PowerPC/pr48527.ll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ define void @_ZNK1q1rEv() local_unnamed_addr #0 align 2 {
1616
; CHECK-LABEL: _ZNK1q1rEv:
1717
; CHECK: # %bb.0: # %entry
1818
; CHECK-NEXT: mflr 0
19-
; CHECK-NEXT: std 28, -32(1) # 8-byte Folded Spill
2019
; CHECK-NEXT: std 29, -24(1) # 8-byte Folded Spill
2120
; CHECK-NEXT: std 30, -16(1) # 8-byte Folded Spill
2221
; CHECK-NEXT: stdu 1, -64(1)
2322
; CHECK-NEXT: std 0, 80(1)
24-
; CHECK-NEXT: li 29, 0
25-
; CHECK-NEXT: lwz 30, 0(3)
26-
; CHECK-NEXT: addis 3, 2, .LC0@toc@ha
27-
; CHECK-NEXT: ld 28, .LC0@toc@l(3)
23+
; CHECK-NEXT: addis 4, 2, .LC0@toc@ha
24+
; CHECK-NEXT: lwz 3, 0(3)
25+
; CHECK-NEXT: ld 29, .LC0@toc@l(4)
26+
; CHECK-NEXT: addi 3, 3, -1
27+
; CHECK-NEXT: clrldi 3, 3, 32
28+
; CHECK-NEXT: addi 30, 3, 1
2829
; CHECK-NEXT: addis 3, 2, aj@got@tlsgd@ha
2930
; CHECK-NEXT: addi 3, 3, aj@got@tlsgd@l
3031
; CHECK-NEXT: bl __tls_get_addr(aj@tlsgd)
@@ -33,14 +34,14 @@ define void @_ZNK1q1rEv() local_unnamed_addr #0 align 2 {
3334
; CHECK-NEXT: .p2align 5
3435
; CHECK-NEXT: .LBB0_1: # %monotonic.i
3536
; CHECK-NEXT: #
36-
; CHECK-NEXT: lwz 5, 0(28)
37+
; CHECK-NEXT: lwz 5, 0(29)
3738
; CHECK-NEXT: andi. 5, 5, 255
3839
; CHECK-NEXT: bne 0, .LBB0_4
3940
; CHECK-NEXT: # %bb.2: # %for.cond.i
4041
; CHECK-NEXT: #
41-
; CHECK-NEXT: addi 29, 29, 1
42-
; CHECK-NEXT: cmplw 29, 30
43-
; CHECK-NEXT: bne 0, .LBB0_1
42+
; CHECK-NEXT: addi 30, 30, -1
43+
; CHECK-NEXT: cmpldi 30, 0
44+
; CHECK-NEXT: bc 12, 1, .LBB0_1
4445
; CHECK-NEXT: # %bb.3:
4546
; CHECK-NEXT: mr 4, 3
4647
; CHECK-NEXT: .LBB0_4: # %if.end
@@ -50,7 +51,6 @@ define void @_ZNK1q1rEv() local_unnamed_addr #0 align 2 {
5051
; CHECK-NEXT: ld 0, 16(1)
5152
; CHECK-NEXT: ld 30, -16(1) # 8-byte Folded Reload
5253
; CHECK-NEXT: ld 29, -24(1) # 8-byte Folded Reload
53-
; CHECK-NEXT: ld 28, -32(1) # 8-byte Folded Reload
5454
; CHECK-NEXT: mtlr 0
5555
; CHECK-NEXT: blr
5656
entry:

0 commit comments

Comments
 (0)