diff options
| author | Krzysztof Parzyszek <kparzysz@codeaurora.org> | 2018-03-23 18:00:18 +0000 |
|---|---|---|
| committer | Krzysztof Parzyszek <kparzysz@codeaurora.org> | 2018-03-23 18:00:18 +0000 |
| commit | 80f10e4fe5987cda01724ba9663b6d96754e3169 (patch) | |
| tree | 9e9d6e7854314e7b949ca748b1899ed6be00159e /llvm/lib/Target | |
| parent | 6c63e6c2225cdd6a2ded8440431af6b0c56a4c0b (diff) | |
| download | bcm5719-llvm-80f10e4fe5987cda01724ba9663b6d96754e3169.tar.gz bcm5719-llvm-80f10e4fe5987cda01724ba9663b6d96754e3169.zip | |
[Hexagon] Avoid early if-conversion for one sided branches
Patch by Anand Kodnani.
llvm-svn: 328344
Diffstat (limited to 'llvm/lib/Target')
| -rw-r--r-- | llvm/lib/Target/Hexagon/HexagonEarlyIfConv.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/llvm/lib/Target/Hexagon/HexagonEarlyIfConv.cpp b/llvm/lib/Target/Hexagon/HexagonEarlyIfConv.cpp index 8410dc4a5f7..f2ca118cd47 100644 --- a/llvm/lib/Target/Hexagon/HexagonEarlyIfConv.cpp +++ b/llvm/lib/Target/Hexagon/HexagonEarlyIfConv.cpp @@ -100,7 +100,7 @@ namespace llvm { } // end namespace llvm static cl::opt<bool> EnableHexagonBP("enable-hexagon-br-prob", cl::Hidden, - cl::init(false), cl::desc("Enable branch probability info")); + cl::init(true), cl::desc("Enable branch probability info")); static cl::opt<unsigned> SizeLimit("eif-limit", cl::init(6), cl::Hidden, cl::desc("Size limit in Hexagon early if-conversion")); static cl::opt<bool> SkipExitBranches("eif-no-loop-exit", cl::init(false), @@ -243,7 +243,7 @@ bool HexagonEarlyIfConversion::matchFlowPattern(MachineBasicBlock *B, // Interested only in conditional branches, no .new, no new-value, etc. // Check the terminators directly, it's easier than handling all responses - // from AnalyzeBranch. + // from analyzeBranch. MachineBasicBlock *TB = nullptr, *FB = nullptr; MachineBasicBlock::const_iterator T1I = B->getFirstTerminator(); if (T1I == B->end()) @@ -336,7 +336,7 @@ bool HexagonEarlyIfConversion::matchFlowPattern(MachineBasicBlock *B, return true; } -// KLUDGE: HexagonInstrInfo::AnalyzeBranch won't work on a block that +// KLUDGE: HexagonInstrInfo::analyzeBranch won't work on a block that // contains EH_LABEL. bool HexagonEarlyIfConversion::hasEHLabel(const MachineBasicBlock *B) const { for (auto &I : *B) @@ -345,7 +345,7 @@ bool HexagonEarlyIfConversion::hasEHLabel(const MachineBasicBlock *B) const { return false; } -// KLUDGE: HexagonInstrInfo::AnalyzeBranch may be unable to recognize +// KLUDGE: HexagonInstrInfo::analyzeBranch may be unable to recognize // that a block can never fall-through. bool HexagonEarlyIfConversion::hasUncondBranch(const MachineBasicBlock *B) const { @@ -495,7 +495,7 @@ unsigned HexagonEarlyIfConversion::countPredicateDefs( unsigned R = MO.getReg(); if (!TargetRegisterInfo::isVirtualRegister(R)) continue; - if (MRI->getRegClass(R) == &Hexagon::PredRegsRegClass) + if (isPredicate(R)) PredDefs++; } } @@ -503,10 +503,21 @@ unsigned HexagonEarlyIfConversion::countPredicateDefs( } bool HexagonEarlyIfConversion::isProfitable(const FlowPattern &FP) const { + BranchProbability JumpProb(1, 10); + BranchProbability Prob(9, 10); + if (MBPI && FP.TrueB && !FP.FalseB && + (MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) < JumpProb || + MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) > Prob)) + return false; + + if (MBPI && !FP.TrueB && FP.FalseB && + (MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) < JumpProb || + MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) > Prob)) + return false; + if (FP.TrueB && FP.FalseB) { // Do not IfCovert if the branch is one sided. if (MBPI) { - BranchProbability Prob(9, 10); if (MBPI->getEdgeProbability(FP.SplitB, FP.TrueB) > Prob) return false; if (MBPI->getEdgeProbability(FP.SplitB, FP.FalseB) > Prob) @@ -1018,11 +1029,7 @@ void HexagonEarlyIfConversion::mergeBlocks(MachineBasicBlock *PredB, HII->removeBranch(*PredB); PredB->removeSuccessor(SuccB); PredB->splice(PredB->end(), SuccB, SuccB->begin(), SuccB->end()); - MachineBasicBlock::succ_iterator I, E = SuccB->succ_end(); - for (I = SuccB->succ_begin(); I != E; ++I) - PredB->addSuccessor(*I); - PredB->normalizeSuccProbs(); - replacePhiEdges(SuccB, PredB); + PredB->transferSuccessorsAndUpdatePHIs(SuccB); removeBlock(SuccB); if (!TermOk) PredB->updateTerminator(); @@ -1044,7 +1051,7 @@ void HexagonEarlyIfConversion::simplifyFlowGraph(const FlowPattern &FP) { // By now, the split block has only one successor (SB), and SB has only // one predecessor. We can try to merge them. We will need to update ter- - // minators in FP.Split+SB, and that requires working AnalyzeBranch, which + // minators in FP.Split+SB, and that requires working analyzeBranch, which // fails on Hexagon for blocks that have EH_LABELs. However, if SB ends // with an unconditional branch, we won't need to touch the terminators. if (!hasEHLabel(SB) || hasUncondBranch(SB)) |

