summaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorSerguei Katkov <serguei.katkov@azul.com>2019-07-18 07:36:20 +0000
committerSerguei Katkov <serguei.katkov@azul.com>2019-07-18 07:36:20 +0000
commit0ffa833d54707c9d8d83f10ab7019a70c18885ca (patch)
tree3ad07443b68f88eed64b2722bdf494936168ede9 /llvm
parent[RISCV][DebugInfo] Fix dwarf-riscv-relocs.ll test on Windows (diff)
downloadllvm-project-0ffa833d54707c9d8d83f10ab7019a70c18885ca.tar.gz
llvm-project-0ffa833d54707c9d8d83f10ab7019a70c18885ca.tar.bz2
llvm-project-0ffa833d54707c9d8d83f10ab7019a70c18885ca.zip
[LoopInfo] Use early return in branch weight update functions. NFC.
llvm-svn: 366411
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp59
1 files changed, 30 insertions, 29 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp b/llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp
index deb38df4420f..005306cf1898 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp
@@ -382,23 +382,23 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
static void updateBranchWeights(BasicBlock *Header, BranchInst *LatchBR,
unsigned IterNumber, unsigned AvgIters,
uint64_t &PeeledHeaderWeight) {
+ if (!PeeledHeaderWeight)
+ return;
// FIXME: Pick a more realistic distribution.
// Currently the proportion of weight we assign to the fall-through
// side of the branch drops linearly with the iteration number, and we use
// a 0.9 fudge factor to make the drop-off less sharp...
- if (PeeledHeaderWeight) {
- uint64_t FallThruWeight =
- PeeledHeaderWeight * ((float)(AvgIters - IterNumber) / AvgIters * 0.9);
- uint64_t ExitWeight = PeeledHeaderWeight - FallThruWeight;
- PeeledHeaderWeight -= ExitWeight;
-
- unsigned HeaderIdx = (LatchBR->getSuccessor(0) == Header ? 0 : 1);
- MDBuilder MDB(LatchBR->getContext());
- MDNode *WeightNode =
- HeaderIdx ? MDB.createBranchWeights(ExitWeight, FallThruWeight)
- : MDB.createBranchWeights(FallThruWeight, ExitWeight);
- LatchBR->setMetadata(LLVMContext::MD_prof, WeightNode);
- }
+ uint64_t FallThruWeight =
+ PeeledHeaderWeight * ((float)(AvgIters - IterNumber) / AvgIters * 0.9);
+ uint64_t ExitWeight = PeeledHeaderWeight - FallThruWeight;
+ PeeledHeaderWeight -= ExitWeight;
+
+ unsigned HeaderIdx = (LatchBR->getSuccessor(0) == Header ? 0 : 1);
+ MDBuilder MDB(LatchBR->getContext());
+ MDNode *WeightNode =
+ HeaderIdx ? MDB.createBranchWeights(ExitWeight, FallThruWeight)
+ : MDB.createBranchWeights(FallThruWeight, ExitWeight);
+ LatchBR->setMetadata(LLVMContext::MD_prof, WeightNode);
}
/// Initialize the weights.
@@ -430,22 +430,23 @@ static void initBranchWeights(BasicBlock *Header, BranchInst *LatchBR,
static void fixupBranchWeights(BasicBlock *Header, BranchInst *LatchBR,
uint64_t ExitWeight, uint64_t CurHeaderWeight) {
// Adjust the branch weights on the loop exit.
- if (ExitWeight) {
- // The backedge count is the difference of current header weight and
- // current loop exit weight. If the current header weight is smaller than
- // the current loop exit weight, we mark the loop backedge weight as 1.
- uint64_t BackEdgeWeight = 0;
- if (ExitWeight < CurHeaderWeight)
- BackEdgeWeight = CurHeaderWeight - ExitWeight;
- else
- BackEdgeWeight = 1;
- MDBuilder MDB(LatchBR->getContext());
- unsigned HeaderIdx = LatchBR->getSuccessor(0) == Header ? 0 : 1;
- MDNode *WeightNode =
- HeaderIdx ? MDB.createBranchWeights(ExitWeight, BackEdgeWeight)
- : MDB.createBranchWeights(BackEdgeWeight, ExitWeight);
- LatchBR->setMetadata(LLVMContext::MD_prof, WeightNode);
- }
+ if (!ExitWeight)
+ return;
+
+ // The backedge count is the difference of current header weight and
+ // current loop exit weight. If the current header weight is smaller than
+ // the current loop exit weight, we mark the loop backedge weight as 1.
+ uint64_t BackEdgeWeight = 0;
+ if (ExitWeight < CurHeaderWeight)
+ BackEdgeWeight = CurHeaderWeight - ExitWeight;
+ else
+ BackEdgeWeight = 1;
+ MDBuilder MDB(LatchBR->getContext());
+ unsigned HeaderIdx = LatchBR->getSuccessor(0) == Header ? 0 : 1;
+ MDNode *WeightNode =
+ HeaderIdx ? MDB.createBranchWeights(ExitWeight, BackEdgeWeight)
+ : MDB.createBranchWeights(BackEdgeWeight, ExitWeight);
+ LatchBR->setMetadata(LLVMContext::MD_prof, WeightNode);
}
/// Clones the body of the loop L, putting it between \p InsertTop and \p