[llvm-commits] [llvm] r147280 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/preserve-branchweights.ll
Nick Lewycky
nicholas at mxc.ca
Mon Dec 26 12:54:14 PST 2011
Author: nicholas
Date: Mon Dec 26 14:54:14 2011
New Revision: 147280
URL: http://llvm.org/viewvc/llvm-project?rev=147280&view=rev
Log:
Update the branch weight metadata when reversing the order of a branch.
Added:
llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=147280&r1=147279&r2=147280&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Mon Dec 26 14:54:14 2011
@@ -1603,10 +1603,7 @@
}
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.
Added: llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll?rev=147280&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll (added)
+++ llvm/trunk/test/Transforms/SimplifyCFG/preserve-branchweights.ll Mon Dec 26 14:54:14 2011
@@ -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}
More information about the llvm-commits
mailing list