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
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5959,7 +5959,11 @@ bool SimplifyCFGOpt::turnSwitchRangeIntoICmp(SwitchInst *SI,
unsigned PreviousEdges = OtherCases->size();
if (OtherDest == SI->getDefaultDest())
++PreviousEdges;
for (unsigned I = 0, E = PreviousEdges - 1; I != E; ++I)
unsigned E = PreviousEdges - 1;
// Remove all incoming values from OtherDest if OtherDest is unreachable.
if (NewBI->isUnconditional())
++E;
for (unsigned I = 0; I != E; ++I)
cast<PHINode>(BBI)->removeIncomingValue(SI->getParent());
}

Expand Down
23 changes: 23 additions & 0 deletions llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,27 @@ b:
ret i32 %1
}

define i32 @else_will_be_unreachable(i1 %arg) {
; CHECK-LABEL: @else_will_be_unreachable(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[I:%.*]] = select i1 [[ARG:%.*]], i32 0, i32 1
; CHECK-NEXT: ret i32 [[I]]
;
entry:
switch i1 %arg, label %else [
i1 false, label %if
i1 true, label %if
]

if:
br i1 %arg, label %else, label %bb

bb:
br label %else

else:
%i = phi i32 [ 0, %entry ], [ 0, %if ], [ 1, %bb ]
ret i32 %i
}

declare void @bar(ptr nonnull dereferenceable(4))