From 1bd3d00e7e5a299cefb2cd4759de30aafd7d1c7c Mon Sep 17 00:00:00 2001 From: Sam Parker Date: Mon, 17 Jun 2019 13:39:28 +0000 Subject: [CodeGen] Check for HardwareLoop Latch ExitBlock The HardwareLoops pass finds exit blocks with a scevable exit count. If the target specifies to update the loop counter in a register, through a phi, we need to ensure that the exit block is a latch so that we can insert the phi with the correct value for the incoming edge. Differential Revision: https://reviews.llvm.org/D63336 llvm-svn: 363556 --- llvm/lib/CodeGen/HardwareLoops.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen/HardwareLoops.cpp') diff --git a/llvm/lib/CodeGen/HardwareLoops.cpp b/llvm/lib/CodeGen/HardwareLoops.cpp index df063545f28..99191090220 100644 --- a/llvm/lib/CodeGen/HardwareLoops.cpp +++ b/llvm/lib/CodeGen/HardwareLoops.cpp @@ -235,7 +235,17 @@ bool HardwareLoops::TryConvertLoop(TTI::HardwareLoopInfo &HWLoopInfo) { for (SmallVectorImpl::iterator I = ExitingBlocks.begin(), IE = ExitingBlocks.end(); I != IE; ++I) { - const SCEV *EC = SE->getExitCount(L, *I); + BasicBlock *BB = *I; + + // If we pass the updated counter back through a phi, we need to know + // which latch the updated value will be coming from. + if (!L->isLoopLatch(BB)) { + if ((ForceHardwareLoopPHI.getNumOccurrences() && ForceHardwareLoopPHI) || + HWLoopInfo.CounterInReg) + continue; + } + + const SCEV *EC = SE->getExitCount(L, BB); if (isa(EC)) continue; if (const SCEVConstant *ConstEC = dyn_cast(EC)) { @@ -251,7 +261,7 @@ bool HardwareLoops::TryConvertLoop(TTI::HardwareLoopInfo &HWLoopInfo) { // If this exiting block is contained in a nested loop, it is not eligible // for insertion of the branch-and-decrement since the inner loop would // end up messing up the value in the CTR. - if (!HWLoopInfo.IsNestingLegal && LI->getLoopFor(*I) != L && + if (!HWLoopInfo.IsNestingLegal && LI->getLoopFor(BB) != L && !ForceNestedLoop) continue; @@ -278,7 +288,7 @@ bool HardwareLoops::TryConvertLoop(TTI::HardwareLoopInfo &HWLoopInfo) { continue; // Make sure this blocks ends with a conditional branch. - Instruction *TI = (*I)->getTerminator(); + Instruction *TI = BB->getTerminator(); if (!TI) continue; -- cgit v1.2.3