aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorMichael Kruse <llvm-project@meinersbur.de>2021-04-26 10:52:06 -0500
committerMichael Kruse <llvm-project@meinersbur.de>2021-04-26 10:57:31 -0500
commit153144be40855ca1e35e1bfca082e10f553bb2e5 (patch)
treeb1131ce68f676b31f9bcdfc5d785d358f73838ca /llvm/lib/Transforms/Utils/Local.cpp
parent858d4885dcc2242910971607bf46428d5b563d95 (diff)
downloadllvm-153144be40855ca1e35e1bfca082e10f553bb2e5.zip
llvm-153144be40855ca1e35e1bfca082e10f553bb2e5.tar.gz
llvm-153144be40855ca1e35e1bfca082e10f553bb2e5.tar.bz2
[SimplifyCFG] Preserve metadata when unconditionalizing branches (constant condition).
When replacing a conditional branch by an unconditional one because the condition is a constant, transfer the metadata to the new branch instruction. Part of fix for llvm.org/PR50060 Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D101141
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 255bb8d..b61c369 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -167,7 +167,12 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
OldDest->removePredecessor(BB);
// Replace the conditional branch with an unconditional one.
- Builder.CreateBr(Destination);
+ BranchInst *NewBI = Builder.CreateBr(Destination);
+
+ // Transfer the metadata to the new branch instruction.
+ NewBI->copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
+ LLVMContext::MD_annotation});
+
BI->eraseFromParent();
if (DTU)
DTU->applyUpdates({{DominatorTree::Delete, BB, OldDest}});