summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/HardwareLoops.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-07-29 20:15:26 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-07-29 20:15:26 +0000
commit344a3780b2e33f6ca763666c380202b18aab72a3 (patch)
treef0b203ee6eb71d7fdd792373e3c81eb18d6934dd /llvm/lib/CodeGen/HardwareLoops.cpp
parentb60736ec1405bb0a8dd40989f67ef4c93da068ab (diff)
Diffstat (limited to 'llvm/lib/CodeGen/HardwareLoops.cpp')
-rw-r--r--llvm/lib/CodeGen/HardwareLoops.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/HardwareLoops.cpp b/llvm/lib/CodeGen/HardwareLoops.cpp
index 810b10c9c82a..4316034371a5 100644
--- a/llvm/lib/CodeGen/HardwareLoops.cpp
+++ b/llvm/lib/CodeGen/HardwareLoops.cpp
@@ -232,11 +232,9 @@ bool HardwareLoops::runOnFunction(Function &F) {
AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
M = F.getParent();
- for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) {
- Loop *L = *I;
+ for (Loop *L : *LI)
if (L->isOutermost())
TryConvertLoop(L);
- }
return MadeChange;
}
@@ -408,8 +406,8 @@ Value *HardwareLoop::InitLoopCount() {
}
if (!isSafeToExpandAt(TripCount, BB->getTerminator(), SE)) {
- LLVM_DEBUG(dbgs() << "- Bailing, unsafe to expand TripCount "
- << *TripCount << "\n");
+ LLVM_DEBUG(dbgs() << "- Bailing, unsafe to expand TripCount " << *TripCount
+ << "\n");
return nullptr;
}
@@ -426,9 +424,9 @@ Value *HardwareLoop::InitLoopCount() {
UseLoopGuard = UseLoopGuard && CanGenerateTest(L, Count);
BeginBB = UseLoopGuard ? BB : L->getLoopPreheader();
LLVM_DEBUG(dbgs() << " - Loop Count: " << *Count << "\n"
- << " - Expanded Count in " << BB->getName() << "\n"
- << " - Will insert set counter intrinsic into: "
- << BeginBB->getName() << "\n");
+ << " - Expanded Count in " << BB->getName() << "\n"
+ << " - Will insert set counter intrinsic into: "
+ << BeginBB->getName() << "\n");
return Count;
}
@@ -436,25 +434,32 @@ Value* HardwareLoop::InsertIterationSetup(Value *LoopCountInit) {
IRBuilder<> Builder(BeginBB->getTerminator());
Type *Ty = LoopCountInit->getType();
bool UsePhi = UsePHICounter || ForceHardwareLoopPHI;
- Intrinsic::ID ID = UseLoopGuard ? Intrinsic::test_set_loop_iterations
- : (UsePhi ? Intrinsic::start_loop_iterations
- : Intrinsic::set_loop_iterations);
+ Intrinsic::ID ID = UseLoopGuard
+ ? (UsePhi ? Intrinsic::test_start_loop_iterations
+ : Intrinsic::test_set_loop_iterations)
+ : (UsePhi ? Intrinsic::start_loop_iterations
+ : Intrinsic::set_loop_iterations);
Function *LoopIter = Intrinsic::getDeclaration(M, ID, Ty);
- Value *SetCount = Builder.CreateCall(LoopIter, LoopCountInit);
+ Value *LoopSetup = Builder.CreateCall(LoopIter, LoopCountInit);
// Use the return value of the intrinsic to control the entry of the loop.
if (UseLoopGuard) {
assert((isa<BranchInst>(BeginBB->getTerminator()) &&
cast<BranchInst>(BeginBB->getTerminator())->isConditional()) &&
"Expected conditional branch");
+
+ Value *SetCount =
+ UsePhi ? Builder.CreateExtractValue(LoopSetup, 1) : LoopSetup;
auto *LoopGuard = cast<BranchInst>(BeginBB->getTerminator());
LoopGuard->setCondition(SetCount);
if (LoopGuard->getSuccessor(0) != L->getLoopPreheader())
LoopGuard->swapSuccessors();
}
- LLVM_DEBUG(dbgs() << "HWLoops: Inserted loop counter: "
- << *SetCount << "\n");
- return UseLoopGuard ? LoopCountInit : SetCount;
+ LLVM_DEBUG(dbgs() << "HWLoops: Inserted loop counter: " << *LoopSetup
+ << "\n");
+ if (UsePhi && UseLoopGuard)
+ LoopSetup = Builder.CreateExtractValue(LoopSetup, 0);
+ return !UsePhi ? LoopCountInit : LoopSetup;
}
void HardwareLoop::InsertLoopDec() {