Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5956,7 +5956,7 @@ bool SimplifyCFGOpt::turnSwitchRangeIntoICmp(SwitchInst *SI,
}

// Update weight for the newly-created conditional branch.
if (hasBranchWeightMD(*SI)) {
if (hasBranchWeightMD(*SI) && NewBI->isConditional()) {
SmallVector<uint64_t, 8> Weights;
getBranchWeights(SI, Weights);
if (Weights.size() == 1 + SI->getNumCases()) {
Expand Down
13 changes: 9 additions & 4 deletions llvm/test/Transforms/SimplifyCFG/pr165301.ll
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 6
; RUN: opt -S -passes="simplifycfg<switch-range-to-icmp>" < %s | FileCheck %s

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

define i32 @pr165301(i1 %cond) {
define i32 @pr165301(i1 %cond) !prof !0 {
; CHECK-LABEL: define i32 @pr165301(
; CHECK-SAME: i1 [[COND:%.*]]) {
; CHECK-SAME: i1 [[COND:%.*]]) !prof [[PROF0:![0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br label %[[SWITCHBB:.*]]
; CHECK: [[SWITCHBB]]:
Expand All @@ -18,9 +18,14 @@ switchbb:
switch i1 %cond, label %default [
i1 false, label %switchbb
i1 true, label %switchbb
]
], !prof !1

default:
%phi.lcssa = phi i32 [ 0, %switchbb ]
ret i32 %phi.lcssa
}
!0 = !{!"function_entry_count", i32 10}
!1 = !{!"branch_weights", i32 2, i32 3, i32 5}
;.
; CHECK: [[PROF0]] = !{!"function_entry_count", i32 10}
;.
Loading