1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[SimplifyCFG] Preserve metadata when unconditionalizing branches (same target).

When replacing a conditional branch by an unconditional one because the targets are identical, transfer the metadata to the new branch instruction.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D101226
This commit is contained in:
Michael Kruse 2021-04-26 17:04:00 -05:00
parent 4b2b6e81e1
commit 7bf3404c76
2 changed files with 25 additions and 1 deletions

View File

@ -148,7 +148,12 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
Dest1->removePredecessor(BI->getParent());
// Replace the conditional branch with an unconditional one.
Builder.CreateBr(Dest1);
BranchInst *NewBI = Builder.CreateBr(Dest1);
// Transfer the metadata to the new branch instruction.
NewBI->copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
LLVMContext::MD_annotation});
Value *Cond = BI->getCondition();
BI->eraseFromParent();
if (DeleteDeadConditions)

View File

@ -0,0 +1,19 @@
; RUN: opt < %s -simplifycfg -S | FileCheck %s
;
; Ensure that the loop metadata is preserved when converting the
; conditional branch to an unconditional.
define void @commondest_loopid(i1 %T) {
; CHECK-LABEL: @commondest_loopid(
; CHECK: !llvm.loop !0
; CHECK: !0 = distinct !{!0, !1}
; CHECK: !1 = !{!"loopprop"}
entry:
br label %loop
loop:
br i1 %T, label %loop, label %loop, !llvm.loop !0
}
!0 = distinct !{!0, !1}
!1 = !{!"loopprop"}