diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 4239764ebc7..01f7c81b7d3 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1220,7 +1220,7 @@ HoistTerminator: if (!SI) SI = cast (Builder.CreateSelect(BI->getCondition(), BB1V, BB2V, - BB1V->getName() + "." + BB2V->getName())); + BB1V->getName() + "." + BB2V->getName(), BI)); // Make the PHI node use the select for all incoming values for BB1/BB2 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) diff --git a/test/Transforms/SimplifyCFG/preserve-branchweights.ll b/test/Transforms/SimplifyCFG/preserve-branchweights.ll index 118c4c116b5..21738961b06 100644 --- a/test/Transforms/SimplifyCFG/preserve-branchweights.ll +++ b/test/Transforms/SimplifyCFG/preserve-branchweights.ll @@ -387,6 +387,31 @@ for.exit: ret void } +; Don't drop the metadata. + +define i32 @HoistThenElseCodeToIf(i32 %n) { +; CHECK-LABEL: @HoistThenElseCodeToIf( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 %n, 0 +; CHECK-NEXT: [[DOT:%.*]] = select i1 [[TOBOOL]], i32 1, i32 234, !prof !11 +; CHECK-NEXT: ret i32 [[DOT]] +; +entry: + %tobool = icmp eq i32 %n, 0 + br i1 %tobool, label %if, label %else, !prof !0 + +if: + br label %return + +else: + br label %return + +return: + %retval.0 = phi i32 [ 1, %if ], [ 234, %else ] + ret i32 %retval.0 +} + + !0 = !{!"branch_weights", i32 3, i32 5} !1 = !{!"branch_weights", i32 1, i32 1} !2 = !{!"branch_weights", i32 1, i32 2} @@ -406,7 +431,7 @@ for.exit: ; CHECK: !2 = !{!"branch_weights", i32 7, i32 1, i32 2} ; CHECK: !3 = !{!"branch_weights", i32 49, i32 12, i32 24, i32 35} ; CHECK: !4 = !{!"branch_weights", i32 11, i32 5} -; CHECK: !5 = !{!"branch_weights", i32 17, i32 15} +; CHECK: !5 = !{!"branch_weights", i32 17, i32 15} ; CHECK: !6 = !{!"branch_weights", i32 9, i32 7} ; CHECK: !7 = !{!"branch_weights", i32 17, i32 9, i32 8, i32 7, i32 17} ; CHECK: !8 = !{!"branch_weights", i32 24, i32 33} @@ -414,3 +439,5 @@ for.exit: ;; The false weight prints out as a negative integer here, but inside llvm, we ;; treat the weight as an unsigned integer. ; CHECK: !10 = !{!"branch_weights", i32 112017436, i32 -735157296} +; CHECK: !11 = !{!"branch_weights", i32 3, i32 5} +