summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/HardwareLoops.cpp
diff options
context:
space:
mode:
authorSam Parker <sam.parker@arm.com>2019-06-17 13:39:28 +0000
committerSam Parker <sam.parker@arm.com>2019-06-17 13:39:28 +0000
commit1bd3d00e7e5a299cefb2cd4759de30aafd7d1c7c (patch)
tree8de221318778a2af7195c530785f5ada8b6f38bc /llvm/lib/CodeGen/HardwareLoops.cpp
parent7dc917603be45fa3f5e81b25e860514ab479a531 (diff)
downloadbcm5719-llvm-1bd3d00e7e5a299cefb2cd4759de30aafd7d1c7c.tar.gz
bcm5719-llvm-1bd3d00e7e5a299cefb2cd4759de30aafd7d1c7c.zip
[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
Diffstat (limited to 'llvm/lib/CodeGen/HardwareLoops.cpp')
-rw-r--r--llvm/lib/CodeGen/HardwareLoops.cpp16
1 files changed, 13 insertions, 3 deletions
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<BasicBlock *>::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<SCEVCouldNotCompute>(EC))
continue;
if (const SCEVConstant *ConstEC = dyn_cast<SCEVConstant>(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;
OpenPOWER on IntegriCloud