aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-12-26 20:54:14 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-12-26 20:54:14 +0000
commitc9a1aed7fefe627820bb92154361ede0568229fc (patch)
tree253b387a45f33afd6b1dbc6ca57dcb3bce09cf97
parent9d5231022283ff20b0291eb5711a449de262d3fe (diff)
downloadexternal_llvm-c9a1aed7fefe627820bb92154361ede0568229fc.zip
external_llvm-c9a1aed7fefe627820bb92154361ede0568229fc.tar.gz
external_llvm-c9a1aed7fefe627820bb92154361ede0568229fc.tar.bz2
Update the branch weight metadata when reversing the order of a branch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147280 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp5
-rw-r--r--test/Transforms/SimplifyCFG/preserve-branchweights.ll26
2 files changed, 27 insertions, 4 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 7835349..9604f5e 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1603,10 +1603,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
}
PBI->setCondition(NewCond);
- BasicBlock *OldTrue = PBI->getSuccessor(0);
- BasicBlock *OldFalse = PBI->getSuccessor(1);
- PBI->setSuccessor(0, OldFalse);
- PBI->setSuccessor(1, OldTrue);
+ PBI->swapSuccessors();
}
// If we have a bonus inst, clone it into the predecessor block.
diff --git a/test/Transforms/SimplifyCFG/preserve-branchweights.ll b/test/Transforms/SimplifyCFG/preserve-branchweights.ll
new file mode 100644
index 0000000..dab0d7c
--- /dev/null
+++ b/test/Transforms/SimplifyCFG/preserve-branchweights.ll
@@ -0,0 +1,26 @@
+; RUN: opt -simplifycfg -S -o - < %s | FileCheck %s
+
+declare void @helper(i32)
+
+define void @test1(i1 %a, i1 %b) {
+; CHECK @test1
+entry:
+ br i1 %a, label %Y, label %X, !prof !0
+; CHECK: br i1 %or.cond, label %Z, label %Y, !prof !0
+
+X:
+ %c = or i1 %b, false
+ br i1 %c, label %Z, label %Y
+
+Y:
+ call void @helper(i32 0)
+ ret void
+
+Z:
+ call void @helper(i32 1)
+ ret void
+}
+
+!0 = metadata !{metadata !"branch_weights", i32 1, i32 2}
+
+; CHECK: !0 = metadata !{metadata !"branch_weights", i32 2, i32 1}