<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 12, 2015 at 3:33 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">On Mon, Oct 12, 2015 at 9:44 PM, Cong Hou via llvm-commits<br>
<<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: conghou<br>
> Date: Mon Oct 12 14:44:08 2015<br>
> New Revision: 250089<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=250089&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=250089&view=rev</a><br>
> Log:<br>
> Update the branch weight metadata in JumpThreading pass.<br>
><br>
> In JumpThreading pass, the branch weight metadata is not updated after CFG modification. Consider the jump threading on PredBB, BB, and SuccBB. After jump threading, the weight on BB->SuccBB should be adjusted as some of it is contributed by the edge PredBB->BB, which doesn't exist anymore. This patch tries to update the edge weight in metadata on BB->SuccBB by scaling it by 1 - Freq(PredBB->BB) / Freq(BB->SuccBB).<br>
><br>
> Differential revision: <a href="http://reviews.llvm.org/D10979" rel="noreferrer" target="_blank">http://reviews.llvm.org/D10979</a><br>
><br>
><br>
> Added:<br>
> llvm/trunk/test/Transforms/JumpThreading/update-edge-weight.ll<br>
> Modified:<br>
> llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h<br>
> llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h<br>
> llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h<br>
> llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp<br>
> llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp<br>
> llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp<br>
><br>
> Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h?rev=250089&r1=250088&r2=250089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h?rev=250089&r1=250088&r2=250089&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h Mon Oct 12 14:44:08 2015<br>
> @@ -45,6 +45,9 @@ public:<br>
> /// floating points.<br>
> BlockFrequency getBlockFreq(const BasicBlock *BB) const;<br>
><br>
> + // Set the frequency of the given basic block.<br>
> + void setBlockFreq(const BasicBlock *BB, uint64_t Freq);<br>
> +<br>
> /// calculate - compute block frequency info for the given function.<br>
> void calculate(const Function &F, const BranchProbabilityInfo &BPI,<br>
> const LoopInfo &LI);<br>
><br>
> Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h?rev=250089&r1=250088&r2=250089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h?rev=250089&r1=250088&r2=250089&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h (original)<br>
> +++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h Mon Oct 12 14:44:08 2015<br>
> @@ -477,6 +477,8 @@ public:<br>
><br>
> BlockFrequency getBlockFreq(const BlockNode &Node) const;<br>
><br>
> + void setBlockFreq(const BlockNode &Node, uint64_t Freq);<br>
> +<br>
> raw_ostream &printBlockFreq(raw_ostream &OS, const BlockNode &Node) const;<br>
> raw_ostream &printBlockFreq(raw_ostream &OS,<br>
> const BlockFrequency &Freq) const;<br>
> @@ -913,6 +915,7 @@ public:<br>
> BlockFrequency getBlockFreq(const BlockT *BB) const {<br>
> return BlockFrequencyInfoImplBase::getBlockFreq(getNode(BB));<br>
> }<br>
> + void setBlockFreq(const BlockT *BB, uint64_t Freq);<br>
> Scaled64 getFloatingBlockFreq(const BlockT *BB) const {<br>
> return BlockFrequencyInfoImplBase::getFloatingBlockFreq(getNode(BB));<br>
> }<br>
> @@ -965,6 +968,21 @@ void BlockFrequencyInfoImpl<BT>::calcula<br>
> finalizeMetrics();<br>
> }<br>
><br>
> +template <class BT><br>
> +void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB, uint64_t Freq) {<br>
> + if (Nodes.count(BB))<br>
> + BlockFrequencyInfoImplBase::setBlockFreq(getNode(BB), Freq);<br>
> + else {<br>
> + // If BB is a newly added block after BFI is done, we need to create a new<br>
> + // BlockNode for it assigned with a new index. The index can be determined<br>
> + // by the size of Freqs.<br>
> + BlockNode NewNode(Freqs.size());<br>
> + Nodes[BB] = NewNode;<br>
> + Freqs.emplace_back();<br>
> + BlockFrequencyInfoImplBase::setBlockFreq(NewNode, Freq);<br>
> + }<br>
> +}<br>
> +<br>
> template <class BT> void BlockFrequencyInfoImpl<BT>::initializeRPOT() {<br>
> const BlockT *Entry = &F->front();<br>
> RPOT.reserve(F->size());<br>
><br>
> Modified: llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h?rev=250089&r1=250088&r2=250089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h?rev=250089&r1=250088&r2=250089&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h (original)<br>
> +++ llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h Mon Oct 12 14:44:08 2015<br>
> @@ -83,8 +83,35 @@ public:<br>
> raw_ostream &printEdgeProbability(raw_ostream &OS,<br>
> const MachineBasicBlock *Src,<br>
> const MachineBasicBlock *Dst) const;<br>
> +<br>
> + // Normalize a list of weights by scaling them down so that the sum of them<br>
> + // doesn't exceed UINT32_MAX. Return the scale.<br>
> + template <class WeightListIter><br>
> + static uint32_t normalizeEdgeWeights(WeightListIter Begin,<br>
> + WeightListIter End);<br>
> };<br>
><br>
> +template <class WeightListIter><br>
> +uint32_t<br>
> +MachineBranchProbabilityInfo::normalizeEdgeWeights(WeightListIter Begin,<br>
> + WeightListIter End) {<br>
> + // First we compute the sum with 64-bits of precision.<br>
> + uint64_t Sum = std::accumulate(Begin, End, uint64_t(0));<br>
> +<br>
> + // If the computed sum fits in 32-bits, we're done.<br>
> + if (Sum <= UINT32_MAX)<br>
> + return 1;<br>
> +<br>
> + // Otherwise, compute the scale necessary to cause the weights to fit, and<br>
> + // re-sum with that scale applied.<br>
> + assert((Sum / UINT32_MAX) < UINT32_MAX &&<br>
> + "The sum of weights exceeds UINT32_MAX^2!");<br>
> + uint32_t Scale = (Sum / UINT32_MAX) + 1;<br>
> + for (auto I = Begin; I != End; ++I)<br>
> + *I /= Scale;<br>
<br>
Can Sum be 0xfffffffe00000001 here, making Scale zero?<br></blockquote><div><br></div><div>If the assertion above doesn't fail, (Sum / UINT32_MAX) + 1 won't be zero. Actually, Sum should be way less from UINT64_MAX: weight is less than UINT32_MAX, and we won't normalize a list of weights whose size is close to UINT32_MAX.</div><div><br></div><div>Cong<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
- Ben<br>
<br>
> + return Scale;<br>
> +}<br>
> +<br>
> }<br>
><br>
><br>
><br>
> Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp?rev=250089&r1=250088&r2=250089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp?rev=250089&r1=250088&r2=250089&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp Mon Oct 12 14:44:08 2015<br>
> @@ -129,6 +129,12 @@ BlockFrequency BlockFrequencyInfo::getBl<br>
> return BFI ? BFI->getBlockFreq(BB) : 0;<br>
> }<br>
><br>
> +void BlockFrequencyInfo::setBlockFreq(const BasicBlock *BB,<br>
> + uint64_t Freq) {<br>
> + assert(BFI && "Expected analysis to be available");<br>
> + BFI->setBlockFreq(BB, Freq);<br>
> +}<br>
> +<br>
> /// Pop up a ghostview window with the current block frequency propagation<br>
> /// rendered using dot.<br>
> void BlockFrequencyInfo::view() const {<br>
><br>
> Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp?rev=250089&r1=250088&r2=250089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp?rev=250089&r1=250088&r2=250089&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp Mon Oct 12 14:44:08 2015<br>
> @@ -530,6 +530,13 @@ BlockFrequencyInfoImplBase::getFloatingB<br>
> return Freqs[Node.Index].Scaled;<br>
> }<br>
><br>
> +void BlockFrequencyInfoImplBase::setBlockFreq(const BlockNode &Node,<br>
> + uint64_t Freq) {<br>
> + assert(Node.isValid() && "Expected valid node");<br>
> + assert(Node.Index < Freqs.size() && "Expected legal index");<br>
> + Freqs[Node.Index].Integer = Freq;<br>
> +}<br>
> +<br>
> std::string<br>
> BlockFrequencyInfoImplBase::getBlockName(const BlockNode &Node) const {<br>
> return std::string();<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=250089&r1=250088&r2=250089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=250089&r1=250088&r2=250089&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Mon Oct 12 14:44:08 2015<br>
> @@ -20,14 +20,20 @@<br>
> #include "llvm/ADT/Statistic.h"<br>
> #include "llvm/Analysis/GlobalsModRef.h"<br>
> #include "llvm/Analysis/CFG.h"<br>
> +#include "llvm/Analysis/BlockFrequencyInfo.h"<br>
> +#include "llvm/Analysis/BlockFrequencyInfoImpl.h"<br>
> +#include "llvm/Analysis/BranchProbabilityInfo.h"<br>
> #include "llvm/Analysis/ConstantFolding.h"<br>
> #include "llvm/Analysis/InstructionSimplify.h"<br>
> #include "llvm/Analysis/LazyValueInfo.h"<br>
> #include "llvm/Analysis/Loads.h"<br>
> +#include "llvm/Analysis/LoopInfo.h"<br>
> #include "llvm/Analysis/TargetLibraryInfo.h"<br>
> +#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"<br>
> #include "llvm/IR/DataLayout.h"<br>
> #include "llvm/IR/IntrinsicInst.h"<br>
> #include "llvm/IR/LLVMContext.h"<br>
> +#include "llvm/IR/MDBuilder.h"<br>
> #include "llvm/IR/Metadata.h"<br>
> #include "llvm/IR/ValueHandle.h"<br>
> #include "llvm/Pass.h"<br>
> @@ -37,6 +43,8 @@<br>
> #include "llvm/Transforms/Utils/BasicBlockUtils.h"<br>
> #include "llvm/Transforms/Utils/Local.h"<br>
> #include "llvm/Transforms/Utils/SSAUpdater.h"<br>
> +#include <algorithm><br>
> +#include <memory><br>
> using namespace llvm;<br>
><br>
> #define DEBUG_TYPE "jump-threading"<br>
> @@ -81,6 +89,9 @@ namespace {<br>
> class JumpThreading : public FunctionPass {<br>
> TargetLibraryInfo *TLI;<br>
> LazyValueInfo *LVI;<br>
> + std::unique_ptr<BlockFrequencyInfo> BFI;<br>
> + std::unique_ptr<BranchProbabilityInfo> BPI;<br>
> + bool HasProfileData;<br>
> #ifdef NDEBUG<br>
> SmallPtrSet<BasicBlock*, 16> LoopHeaders;<br>
> #else<br>
> @@ -119,6 +130,11 @@ namespace {<br>
> AU.addRequired<TargetLibraryInfoWrapperPass>();<br>
> }<br>
><br>
> + void releaseMemory() override {<br>
> + BFI.reset();<br>
> + BPI.reset();<br>
> + }<br>
> +<br>
> void FindLoopHeaders(Function &F);<br>
> bool ProcessBlock(BasicBlock *BB);<br>
> bool ThreadEdge(BasicBlock *BB, const SmallVectorImpl<BasicBlock*> &PredBBs,<br>
> @@ -139,6 +155,12 @@ namespace {<br>
><br>
> bool SimplifyPartiallyRedundantLoad(LoadInst *LI);<br>
> bool TryToUnfoldSelect(CmpInst *CondCmp, BasicBlock *BB);<br>
> +<br>
> + private:<br>
> + BasicBlock *SplitBlockPreds(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,<br>
> + const char *Suffix);<br>
> + void UpdateBlockFreqAndEdgeWeight(BasicBlock *PredBB, BasicBlock *BB,<br>
> + BasicBlock *NewBB, BasicBlock *SuccBB);<br>
> };<br>
> }<br>
><br>
> @@ -162,6 +184,16 @@ bool JumpThreading::runOnFunction(Functi<br>
> DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n");<br>
> TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();<br>
> LVI = &getAnalysis<LazyValueInfo>();<br>
> + BFI.reset();<br>
> + BPI.reset();<br>
> + // When profile data is available, we need to update edge weights after<br>
> + // successful jump threading, which requires both BPI and BFI being available.<br>
> + HasProfileData = F.getEntryCount().hasValue();<br>
> + if (HasProfileData) {<br>
> + LoopInfo LI{DominatorTree(F)};<br>
> + BPI.reset(new BranchProbabilityInfo(F, LI));<br>
> + BFI.reset(new BlockFrequencyInfo(F, *BPI, LI));<br>
> + }<br>
><br>
> // Remove unreachable blocks from function as they may result in infinite<br>
> // loop. We do threading if we found something profitable. Jump threading a<br>
> @@ -977,8 +1009,7 @@ bool JumpThreading::SimplifyPartiallyRed<br>
> }<br>
><br>
> // Split them out to their own block.<br>
> - UnavailablePred =<br>
> - SplitBlockPredecessors(LoadBB, PredsToSplit, "thread-pre-split");<br>
> + UnavailablePred = SplitBlockPreds(LoadBB, PredsToSplit, "thread-pre-split");<br>
> }<br>
><br>
> // If the value isn't available in all predecessors, then there will be<br>
> @@ -1403,7 +1434,7 @@ bool JumpThreading::ThreadEdge(BasicBloc<br>
> else {<br>
> DEBUG(dbgs() << " Factoring out " << PredBBs.size()<br>
> << " common predecessors.\n");<br>
> - PredBB = SplitBlockPredecessors(BB, PredBBs, ".thr_comm");<br>
> + PredBB = SplitBlockPreds(BB, PredBBs, ".thr_comm");<br>
> }<br>
><br>
> // And finally, do it!<br>
> @@ -1424,6 +1455,13 @@ bool JumpThreading::ThreadEdge(BasicBloc<br>
> BB->getParent(), BB);<br>
> NewBB->moveAfter(PredBB);<br>
><br>
> + // Set the block frequency of NewBB.<br>
> + if (HasProfileData) {<br>
> + auto NewBBFreq =<br>
> + BFI->getBlockFreq(PredBB) * BPI->getEdgeProbability(PredBB, BB);<br>
> + BFI->setBlockFreq(NewBB, NewBBFreq.getFrequency());<br>
> + }<br>
> +<br>
> BasicBlock::iterator BI = BB->begin();<br>
> for (; PHINode *PN = dyn_cast<PHINode>(BI); ++BI)<br>
> ValueMapping[PN] = PN->getIncomingValueForBlock(PredBB);<br>
> @@ -1447,7 +1485,7 @@ bool JumpThreading::ThreadEdge(BasicBloc<br>
><br>
> // We didn't copy the terminator from BB over to NewBB, because there is now<br>
> // an unconditional jump to SuccBB. Insert the unconditional jump.<br>
> - BranchInst *NewBI =BranchInst::Create(SuccBB, NewBB);<br>
> + BranchInst *NewBI = BranchInst::Create(SuccBB, NewBB);<br>
> NewBI->setDebugLoc(BB->getTerminator()->getDebugLoc());<br>
><br>
> // Check to see if SuccBB has PHI nodes. If so, we need to add entries to the<br>
> @@ -1508,11 +1546,86 @@ bool JumpThreading::ThreadEdge(BasicBloc<br>
> // frequently happens because of phi translation.<br>
> SimplifyInstructionsInBlock(NewBB, TLI);<br>
><br>
> + // Update the edge weight from BB to SuccBB, which should be less than before.<br>
> + UpdateBlockFreqAndEdgeWeight(PredBB, BB, NewBB, SuccBB);<br>
> +<br>
> // Threaded an edge!<br>
> ++NumThreads;<br>
> return true;<br>
> }<br>
><br>
> +/// Create a new basic block that will be the predecessor of BB and successor of<br>
> +/// all blocks in Preds. When profile data is availble, update the frequency of<br>
> +/// this new block.<br>
> +BasicBlock *JumpThreading::SplitBlockPreds(BasicBlock *BB,<br>
> + ArrayRef<BasicBlock *> Preds,<br>
> + const char *Suffix) {<br>
> + // Collect the frequencies of all predecessors of BB, which will be used to<br>
> + // update the edge weight on BB->SuccBB.<br>
> + BlockFrequency PredBBFreq(0);<br>
> + if (HasProfileData)<br>
> + for (auto Pred : Preds)<br>
> + PredBBFreq += BFI->getBlockFreq(Pred) * BPI->getEdgeProbability(Pred, BB);<br>
> +<br>
> + BasicBlock *PredBB = SplitBlockPredecessors(BB, Preds, Suffix);<br>
> +<br>
> + // Set the block frequency of the newly created PredBB, which is the sum of<br>
> + // frequencies of Preds.<br>
> + if (HasProfileData)<br>
> + BFI->setBlockFreq(PredBB, PredBBFreq.getFrequency());<br>
> + return PredBB;<br>
> +}<br>
> +<br>
> +/// Update the block frequency of BB and branch weight and the metadata on the<br>
> +/// edge BB->SuccBB. This is done by scaling the weight of BB->SuccBB by 1 -<br>
> +/// Freq(PredBB->BB) / Freq(BB->SuccBB).<br>
> +void JumpThreading::UpdateBlockFreqAndEdgeWeight(BasicBlock *PredBB,<br>
> + BasicBlock *BB,<br>
> + BasicBlock *NewBB,<br>
> + BasicBlock *SuccBB) {<br>
> + if (!HasProfileData)<br>
> + return;<br>
> +<br>
> + assert(BFI && BPI && "BFI & BPI should have been created here");<br>
> +<br>
> + // As the edge from PredBB to BB is deleted, we have to update the block<br>
> + // frequency of BB.<br>
> + auto BBOrigFreq = BFI->getBlockFreq(BB);<br>
> + auto NewBBFreq = BFI->getBlockFreq(NewBB);<br>
> + auto BB2SuccBBFreq = BBOrigFreq * BPI->getEdgeProbability(BB, SuccBB);<br>
> + auto BBNewFreq = BBOrigFreq - NewBBFreq;<br>
> + BFI->setBlockFreq(BB, BBNewFreq.getFrequency());<br>
> +<br>
> + // Collect updated outgoing edges' frequencies from BB and use them to update<br>
> + // edge weights.<br>
> + SmallVector<uint64_t, 4> BBSuccFreq;<br>
> + for (auto I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {<br>
> + auto SuccFreq = (*I == SuccBB)<br>
> + ? BB2SuccBBFreq - NewBBFreq<br>
> + : BBOrigFreq * BPI->getEdgeProbability(BB, *I);<br>
> + BBSuccFreq.push_back(SuccFreq.getFrequency());<br>
> + }<br>
> +<br>
> + // Normalize edge weights in Weights64 so that the sum of them can fit in<br>
> + MachineBranchProbabilityInfo::normalizeEdgeWeights(BBSuccFreq.begin(),<br>
> + BBSuccFreq.end());<br>
> +<br>
> + SmallVector<uint32_t, 4> Weights;<br>
> + for (auto Freq : BBSuccFreq)<br>
> + Weights.push_back(static_cast<uint32_t>(Freq));<br>
> +<br>
> + // Update edge weights in BPI.<br>
> + for (int I = 0, E = Weights.size(); I < E; I++)<br>
> + BPI->setEdgeWeight(BB, I, Weights[I]);<br>
> +<br>
> + if (Weights.size() >= 2) {<br>
> + auto TI = BB->getTerminator();<br>
> + TI->setMetadata(<br>
> + LLVMContext::MD_prof,<br>
> + MDBuilder(TI->getParent()->getContext()).createBranchWeights(Weights));<br>
> + }<br>
> +}<br>
> +<br>
> /// DuplicateCondBranchOnPHIIntoPred - PredBB contains an unconditional branch<br>
> /// to BB which contains an i1 PHI node and a conditional branch on that PHI.<br>
> /// If we can duplicate the contents of BB up into PredBB do so now, this<br>
> @@ -1546,7 +1659,7 @@ bool JumpThreading::DuplicateCondBranchO<br>
> else {<br>
> DEBUG(dbgs() << " Factoring out " << PredBBs.size()<br>
> << " common predecessors.\n");<br>
> - PredBB = SplitBlockPredecessors(BB, PredBBs, ".thr_comm");<br>
> + PredBB = SplitBlockPreds(BB, PredBBs, ".thr_comm");<br>
> }<br>
><br>
> // Okay, we decided to do this! Clone all the instructions in BB onto the end<br>
><br>
> Added: llvm/trunk/test/Transforms/JumpThreading/update-edge-weight.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/update-edge-weight.ll?rev=250089&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/update-edge-weight.ll?rev=250089&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/Transforms/JumpThreading/update-edge-weight.ll (added)<br>
> +++ llvm/trunk/test/Transforms/JumpThreading/update-edge-weight.ll Mon Oct 12 14:44:08 2015<br>
> @@ -0,0 +1,43 @@<br>
> +; RUN: opt -S -jump-threading %s | FileCheck %s<br>
> +<br>
> +; Test if edge weights are properly updated after jump threading.<br>
> +<br>
> +; CHECK: !2 = !{!"branch_weights", i32 22, i32 7}<br>
> +<br>
> +define void @foo(i32 %n) !prof !0 {<br>
> +entry:<br>
> + %cmp = icmp sgt i32 %n, 10<br>
> + br i1 %cmp, label %if.then.1, label %if.else.1, !prof !1<br>
> +<br>
> +if.then.1:<br>
> + tail call void @a()<br>
> + br label %if.cond<br>
> +<br>
> +if.else.1:<br>
> + tail call void @b()<br>
> + br label %if.cond<br>
> +<br>
> +if.cond:<br>
> + %cmp1 = icmp sgt i32 %n, 5<br>
> + br i1 %cmp1, label %if.then.2, label %if.else.2, !prof !2<br>
> +<br>
> +if.then.2:<br>
> + tail call void @c()<br>
> + br label %if.end<br>
> +<br>
> +if.else.2:<br>
> + tail call void @d()<br>
> + br label %if.end<br>
> +<br>
> +if.end:<br>
> + ret void<br>
> +}<br>
> +<br>
> +declare void @a()<br>
> +declare void @b()<br>
> +declare void @c()<br>
> +declare void @d()<br>
> +<br>
> +!0 = !{!"function_entry_count", i64 1}<br>
> +!1 = !{!"branch_weights", i32 10, i32 5}<br>
> +!2 = !{!"branch_weights", i32 10, i32 1}<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>