From 3ca147ea3d8c2364542c2e4c2b7ba83fdf5e6dcd Mon Sep 17 00:00:00 2001 From: Michael Kuperstein Date: Fri, 16 Dec 2016 21:23:59 +0000 Subject: Preserve loop metadata when folding branches to a common destination. Differential Revision: https://reviews.llvm.org/D27830 llvm-svn: 289992 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp') diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index a47d0774fa7..668e22f46f4 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2792,6 +2792,11 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold) { PBI = New_PBI; } + // If BI was a loop latch, it may have had associated loop metadata. + // We need to copy it to the new latch, that is, PBI. + if (MDNode *LoopMD = BI->getMetadata(LLVMContext::MD_loop)) + PBI->setMetadata(LLVMContext::MD_loop, LoopMD); + // TODO: If BB is reachable from all paths through PredBlock, then we // could replace PBI's branch probabilities with BI's. -- cgit v1.2.3