Commit 0ffa833d authored by Serguei Katkov's avatar Serguei Katkov
Browse files

[LoopInfo] Use early return in branch weight update functions. NFC.

llvm-svn: 366411
parent dad1bebe
Loading
Loading
Loading
Loading
+30 −29
Original line number Diff line number Diff line
@@ -382,11 +382,12 @@ 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;
@@ -399,7 +400,6 @@ static void updateBranchWeights(BasicBlock *Header, BranchInst *LatchBR,
                : MDB.createBranchWeights(FallThruWeight, ExitWeight);
  LatchBR->setMetadata(LLVMContext::MD_prof, WeightNode);
}
}

/// Initialize the weights.
///
@@ -430,7 +430,9 @@ 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) {
  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.
@@ -446,7 +448,6 @@ static void fixupBranchWeights(BasicBlock *Header, BranchInst *LatchBR,
                : MDB.createBranchWeights(BackEdgeWeight, ExitWeight);
  LatchBR->setMetadata(LLVMContext::MD_prof, WeightNode);
}
}

/// Clones the body of the loop L, putting it between \p InsertTop and \p
/// InsertBot.