[SimplifyCFG] propagate branch metadata when creating select

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267624 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjay Patel 2016-04-26 23:15:48 +00:00
parent 316e8d944d
commit b4a90e614d
2 changed files with 29 additions and 2 deletions

View File

@ -1220,7 +1220,7 @@ HoistTerminator:
if (!SI)
SI = cast<SelectInst>
(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)

View File

@ -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}