Skip to content

Commit d87a30b

Browse files
committed
[SimplifyCFG] Don't propagate weights to unconditional branches in turnSwitchRangeIntoICmp
1 parent c528f60 commit d87a30b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5956,7 +5956,7 @@ bool SimplifyCFGOpt::turnSwitchRangeIntoICmp(SwitchInst *SI,
59565956
}
59575957

59585958
// Update weight for the newly-created conditional branch.
5959-
if (hasBranchWeightMD(*SI)) {
5959+
if (hasBranchWeightMD(*SI) && NewBI->isConditional()) {
59605960
SmallVector<uint64_t, 8> Weights;
59615961
getBranchWeights(SI, Weights);
59625962
if (Weights.size() == 1 + SI->getNumCases()) {

llvm/test/Transforms/SimplifyCFG/pr165301.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
; Make sure there's no use after free when removing incoming values from PHI nodes
55

6-
define i32 @pr165301(i1 %cond) {
6+
define i32 @pr165301(i1 %cond) !prof !0 {
77
; CHECK-LABEL: define i32 @pr165301(
88
; CHECK-SAME: i1 [[COND:%.*]]) {
99
; CHECK-NEXT: [[ENTRY:.*:]]
@@ -18,9 +18,11 @@ switchbb:
1818
switch i1 %cond, label %default [
1919
i1 false, label %switchbb
2020
i1 true, label %switchbb
21-
]
21+
], !prof !1
2222

2323
default:
2424
%phi.lcssa = phi i32 [ 0, %switchbb ]
2525
ret i32 %phi.lcssa
2626
}
27+
!0 = !{!"function_entry_count", i32 10}
28+
!1 = !{!"branch_weights", i32 2, i32 3, i32 5}

0 commit comments

Comments
 (0)